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