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