[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.5

1.1       andrew      1: #!perl -T
1.5     ! andrew      2: # $RedRiver: 51-network-add_su-ap.t,v 1.4 2007/02/06 16:52:21 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.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');
                     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:     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.5     ! andrew    104:     if ( (! ok($t->save_sudb, "Saving sudb"))
        !           105:       && $t->last_error ) {
1.1       andrew    106:         diag('ERR: ' . $t->last_error);
                    107:     }
                    108:
1.2       andrew    109:     $sudb = [];
                    110:     if ((!ok($sudb = $t->sudb_view, "Getting sudb"))
                    111:       && $t->last_error ) {
1.1       andrew    112:         diag('ERR: ' . $t->last_error);
                    113:     }
                    114:
1.2       andrew    115:     $in_sudb = 0;
                    116:     foreach my $su (@{ $sudb }) {
                    117:         if ($su_id == $su->{suid}) {
                    118:             if (lc($su_mac) eq lc($su->{mac})) {
                    119:                 $in_sudb = 1;
                    120:             } else {
                    121:                 $in_sudb = -1;
                    122:                 diag("Incorrect mac for SUID $su_id");
                    123:                 diag("  Should be $su_mac");
                    124:                 diag("  Really is $su->{mac}");
                    125:             }
                    126:             last;
                    127:         }
                    128:     }
                    129:
                    130:     is($in_sudb, 1, "Correct SU is in SUDB");
1.1       andrew    131:
                    132:     ok($t->bye, "Goodbye");
                    133: }

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