Annotation of trango/Net-Telnet-Trango/t/51-network-add_su-ap.t, Revision 1.6
1.1 andrew 1: #!perl -T
1.6 ! andrew 2: # $RedRiver: 51-network-add_su-ap.t,v 1.5 2007/02/06 17:40:02 andrew Exp $
1.1 andrew 3:
1.6 ! andrew 4: use Test::More tests => 16;
1.1 andrew 5: use File::Spec;
6:
7: BEGIN {
8: use_ok( 'Net::Telnet::Trango' );
9: }
10:
11: diag("Testing Net::Telnet::Trango $Net::Telnet::Trango::VERSION, Perl $], $^X");
1.5 andrew 12: diag(" AP tests when adding an SU to an AP");
1.1 andrew 13:
14: my $cfg_file = File::Spec->catfile('t', 'tests.cfg');
1.6 ! andrew 15: my ($cir, $mir, $new_mir) = (128, 256, 1024);
1.1 andrew 16:
17: SKIP: {
1.6 ! andrew 18: my $skipped = 15;
1.1 andrew 19: my %cfg;
20: if (-e $cfg_file) {
21: if (open my $fh, $cfg_file) {
22: while (<$fh>) {
23: chomp;
24: my ($key, $value) = split /\t/, $_, 2;
25: $cfg{$key} = $value;
26: }
27: close $fh;
28: }
29: }
30:
31: my $type = 'AP';
32: my ($host, $pass, $su_id, $su_mac);
33:
34: if ($cfg{$type} && $cfg{$type} =~ /^(\d+\.\d+\.\d+.\d+)$/) {
35: $host = $1;
36: }
37:
38: skip 'No valid ' . $type . ' in config file', $skipped unless $host;
39:
40: if ($cfg{$type . '_PASSWD'} && $cfg{$type . '_PASSWD'} =~ /^(.*)$/) {
41: $pass = $1;
42: }
43:
44: skip 'No valid ' . $type . '_PASSWD in config file', $skipped unless $pass;
45:
46: if ($cfg{SU_ID} && $cfg{SU_ID} =~ /^(\d+)$/) {
47: $su_id= $1;
48: }
49:
50: skip 'No valid SU_ID in config file', $skipped unless $su_id;
51:
52: if ($cfg{SU_MAC} && length $cfg{SU_MAC} >= 12 && $cfg{SU_MAC} =~ /^(.*)$/) {
53: $su_mac = $1;
54: }
55:
56: skip 'No valid SU_MAC in config file', $skipped unless $su_mac;
57:
58: my $t;
59: ok($t = Net::Telnet::Trango->new(), "Instantiating object");
60:
61: ok($t->open($host), "Opening connection to $host");
62:
63: ok($t->is_connected, "connected");
64:
65: ok($t->login($pass), "Logging in");
66:
67: ok($t->logged_in, "logged in");
68:
69: my $sudb;
1.2 andrew 70: if ((!ok($sudb = $t->sudb_view, "Getting sudb"))
71: && $t->last_error ) {
72: diag('ERR: ' . $t->last_error);
73: }
74:
75: my $in_sudb = 0;
76: foreach my $su (@{ $sudb }) {
77: if ($su_id == $su->{suid}) {
78: if (lc($su_mac) eq lc($su->{mac})) {
79: $in_sudb = 1;
80: } else {
81: $in_sudb = -1;
82: diag("Incorrect mac for SUID $su_id");
83: diag(" Should be $su_mac");
84: diag(" Really is $su->{mac}");
85: }
86: last;
87: }
88: }
89:
90: if ($in_sudb) {
91: diag("Removing suid $su_id from AP");
92: if ( (! $t->sudb_delete($su_id))
93: && $t->last_error ) {
94: diag('ERR: ' . $t->last_error);
95: }
96: }
1.1 andrew 97:
98:
1.5 andrew 99: if ( (! ok($t->sudb_add($su_id, 'reg', $cir, $mir, $su_mac), "Adding su"))
1.2 andrew 100: && $t->last_error ) {
1.1 andrew 101: diag('ERR: ' . $t->last_error);
102: }
103:
1.2 andrew 104: $sudb = [];
105: if ((!ok($sudb = $t->sudb_view, "Getting sudb"))
106: && $t->last_error ) {
1.1 andrew 107: diag('ERR: ' . $t->last_error);
108: }
109:
1.2 andrew 110: $in_sudb = 0;
111: foreach my $su (@{ $sudb }) {
112: if ($su_id == $su->{suid}) {
113: if (lc($su_mac) eq lc($su->{mac})) {
114: $in_sudb = 1;
115: } else {
116: $in_sudb = -1;
117: diag("Incorrect mac for SUID $su_id");
118: diag(" Should be $su_mac");
119: diag(" Really is $su->{mac}");
120: }
121: last;
122: }
123: }
124:
125: is($in_sudb, 1, "Correct SU is in SUDB");
1.6 ! andrew 126:
! 127: if ( (! ok($t->save_sudb, "Saving sudb"))
! 128: && $t->last_error ) {
! 129: diag('ERR: ' . $t->last_error);
! 130: }
! 131:
! 132:
! 133: if ( (! ok($t->sudb_modify($su_id, 'mir', $new_mir), "modifying su mir"))
! 134: && $t->last_error ) {
! 135: diag('ERR: ' . $t->last_error);
! 136: }
! 137:
! 138: $sudb = [];
! 139: if ((!ok($sudb = $t->sudb_view, "Getting sudb"))
! 140: && $t->last_error ) {
! 141: diag('ERR: ' . $t->last_error);
! 142: }
! 143:
! 144: $su_mir = 0;
! 145: foreach my $su (@{ $sudb }) {
! 146: if ($su_id == $su->{suid}) {
! 147: $su_mir = $su->{mir};
! 148: last;
! 149: }
! 150: }
! 151:
! 152: is($new_mir, $su_mir, "SU has new mir");
! 153:
! 154: if ( (! ok($t->save_sudb, "Saving sudb"))
! 155: && $t->last_error ) {
! 156: diag('ERR: ' . $t->last_error);
! 157: }
1.1 andrew 158:
159: ok($t->bye, "Goodbye");
160: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>