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

Annotation of trango/Net-Telnet-Trango/t/59-network-cleanup.t, Revision 1.2

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

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