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

1.1       andrew      1: #!perl -T
1.2     ! andrew      2: # $RedRiver: 51-network-add_su.t,v 1.1 2007/02/06 00:42:33 andrew Exp $
1.1       andrew      3:
1.2     ! 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:
                     11: diag("Testing Net::Telnet::Trango $Net::Telnet::Trango::VERSION, Perl $], $^X");
                     12: diag("  Generic tests");
                     13:
                     14: my $cfg_file = File::Spec->catfile('t', 'tests.cfg');
                     15: my ($cir, $mir) = (128, 256);
                     16:
                     17: SKIP: {
1.2     ! andrew     18:     my $skipped = 16;
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:     $t->input_log('input.log'); # XXX Debugging
                     62:
                     63:     ok($t->open($host), "Opening connection to $host");
                     64:
                     65:     ok($t->is_connected, "connected");
                     66:
                     67:     ok($t->login($pass), "Logging in");
                     68:
                     69:     ok($t->logged_in, "logged in");
                     70:
                     71:
                     72:     my $sudb;
1.2     ! andrew     73:     if ((!ok($sudb = $t->sudb_view, "Getting sudb"))
        !            74:       && $t->last_error ) {
        !            75:         diag('ERR: ' . $t->last_error);
        !            76:     }
        !            77:
        !            78:     my $in_sudb = 0;
        !            79:     foreach my $su (@{ $sudb }) {
        !            80:         if ($su_id == $su->{suid}) {
        !            81:             if (lc($su_mac) eq lc($su->{mac})) {
        !            82:                 $in_sudb = 1;
        !            83:             } else {
        !            84:                 $in_sudb = -1;
        !            85:                 diag("Incorrect mac for SUID $su_id");
        !            86:                 diag("  Should be $su_mac");
        !            87:                 diag("  Really is $su->{mac}");
        !            88:             }
        !            89:             last;
        !            90:         }
        !            91:     }
        !            92:
        !            93:     if ($in_sudb) {
        !            94:         diag("Removing suid $su_id from AP");
        !            95:         if ( (! $t->sudb_delete($su_id))
        !            96:           && $t->last_error ) {
        !            97:             diag('ERR: ' . $t->last_error);
        !            98:         }
        !            99:     }
1.1       andrew    100:
                    101:
                    102:     my $result;
1.2     ! andrew    103:     if ( (! ok($result = $t->sudb_add($su_id, 'reg', $cir, $mir, $su_mac),
        !           104:       "Adding su"))
        !           105:       && $t->last_error ) {
1.1       andrew    106:         diag('ERR: ' . $t->last_error);
                    107:     }
                    108:
                    109:     ok($result = $t->save_sudb, "Saving sudb");
                    110:     if ( (! $result ) && $t->last_error ) {
                    111:         diag('ERR: ' . $t->last_error);
                    112:     }
                    113:
1.2     ! andrew    114:     $sudb = [];
        !           115:     if ((!ok($sudb = $t->sudb_view, "Getting sudb"))
        !           116:       && $t->last_error ) {
1.1       andrew    117:         diag('ERR: ' . $t->last_error);
                    118:     }
                    119:
1.2     ! andrew    120:     $in_sudb = 0;
        !           121:     foreach my $su (@{ $sudb }) {
        !           122:         if ($su_id == $su->{suid}) {
        !           123:             if (lc($su_mac) eq lc($su->{mac})) {
        !           124:                 $in_sudb = 1;
        !           125:             } else {
        !           126:                 $in_sudb = -1;
        !           127:                 diag("Incorrect mac for SUID $su_id");
        !           128:                 diag("  Should be $su_mac");
        !           129:                 diag("  Really is $su->{mac}");
        !           130:             }
        !           131:             last;
        !           132:         }
        !           133:     }
        !           134:
        !           135:     is($in_sudb, 1, "Correct SU is in SUDB");
        !           136:
1.1       andrew    137:     my $opmode;
                    138:     ok($opmode = $t->opmode, "getting current opmode");
                    139:
1.2     ! andrew    140:     if ($opmode->{Opmode} eq 'ap') {
        !           141:         ok(1, "Already opmode ap");
        !           142:     } else {
        !           143:         if ((! ok($result = $t->opmode('ap y'), "Setting opmode ap y"))
        !           144:           && $t->last_error ) {
        !           145:             diag('ERR: ' . $t->last_error);
        !           146:         }
        !           147:     }
        !           148:
        !           149:     $opmode = {};
        !           150:     ok($opmode = $t->opmode, "getting current opmode");
1.1       andrew    151:     if (ref $opmode eq 'HASH' && $opmode->{ERR}) {
                    152:         diag("Error: $opmode->{ERR}");
                    153:     }
                    154:
                    155:     is($opmode->{Opmode}, 'ap', "Checking opmode is ap");
1.2     ! andrew    156:
        !           157:     if (! ok($result = $t->save_ss, "Saving systemsetting")
        !           158:       && $t->last_error ) {
        !           159:         diag('ERR: ' . $t->last_error);
        !           160:     }
1.1       andrew    161:
                    162:     ok($t->bye, "Goodbye");
                    163: }

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