[BACK]Return to 51-network-add_su-ap.t CVS log [TXT][DIR] Up to [local] / trango / Net-Telnet-Trango / t

Annotation of trango/Net-Telnet-Trango/t/51-network-add_su-ap.t, Revision 1.4

1.1       andrew      1: #!perl -T
1.4     ! andrew      2: # $RedRiver: 51-network-add_su.t,v 1.3 2007/02/06 16:29:58 andrew Exp $
1.1       andrew      3:
1.4     ! andrew      4: use Test::More tests => 12;
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.4     ! andrew     12: diag("  add SU on AP tests");
1.1       andrew     13:
                     14: my $cfg_file = File::Spec->catfile('t', 'tests.cfg');
                     15: my ($cir, $mir) = (128, 256);
                     16:
                     17: SKIP: {
1.4     ! andrew     18:     my $skipped = 11;
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:
                     70:     my $sudb;
1.2       andrew     71:     if ((!ok($sudb = $t->sudb_view, "Getting sudb"))
                     72:       && $t->last_error ) {
                     73:         diag('ERR: ' . $t->last_error);
                     74:     }
                     75:
                     76:     my $in_sudb = 0;
                     77:     foreach my $su (@{ $sudb }) {
                     78:         if ($su_id == $su->{suid}) {
                     79:             if (lc($su_mac) eq lc($su->{mac})) {
                     80:                 $in_sudb = 1;
                     81:             } else {
                     82:                 $in_sudb = -1;
                     83:                 diag("Incorrect mac for SUID $su_id");
                     84:                 diag("  Should be $su_mac");
                     85:                 diag("  Really is $su->{mac}");
                     86:             }
                     87:             last;
                     88:         }
                     89:     }
                     90:
                     91:     if ($in_sudb) {
                     92:         diag("Removing suid $su_id from AP");
                     93:         if ( (! $t->sudb_delete($su_id))
                     94:           && $t->last_error ) {
                     95:             diag('ERR: ' . $t->last_error);
                     96:         }
                     97:     }
1.1       andrew     98:
                     99:
                    100:     my $result;
1.2       andrew    101:     if ( (! ok($result = $t->sudb_add($su_id, 'reg', $cir, $mir, $su_mac),
                    102:       "Adding su"))
                    103:       && $t->last_error ) {
1.1       andrew    104:         diag('ERR: ' . $t->last_error);
                    105:     }
                    106:
                    107:     ok($result = $t->save_sudb, "Saving sudb");
                    108:     if ( (! $result ) && $t->last_error ) {
                    109:         diag('ERR: ' . $t->last_error);
                    110:     }
                    111:
1.2       andrew    112:     $sudb = [];
                    113:     if ((!ok($sudb = $t->sudb_view, "Getting sudb"))
                    114:       && $t->last_error ) {
1.1       andrew    115:         diag('ERR: ' . $t->last_error);
                    116:     }
                    117:
1.2       andrew    118:     $in_sudb = 0;
                    119:     foreach my $su (@{ $sudb }) {
                    120:         if ($su_id == $su->{suid}) {
                    121:             if (lc($su_mac) eq lc($su->{mac})) {
                    122:                 $in_sudb = 1;
                    123:             } else {
                    124:                 $in_sudb = -1;
                    125:                 diag("Incorrect mac for SUID $su_id");
                    126:                 diag("  Should be $su_mac");
                    127:                 diag("  Really is $su->{mac}");
                    128:             }
                    129:             last;
                    130:         }
                    131:     }
                    132:
                    133:     is($in_sudb, 1, "Correct SU is in SUDB");
1.1       andrew    134:
                    135:     ok($t->bye, "Goodbye");
                    136: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>