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

1.1       andrew      1: #!perl -T
1.9     ! andrew      2: # $RedRiver: 51-network-add_su-ap.t,v 1.8 2007/02/06 20:59:10 andrew Exp $
1.1       andrew      3:
1.9     ! andrew      4: use Test::More tests => 20;
1.1       andrew      5: use File::Spec;
                      6:
                      7: BEGIN {
1.9     ! andrew      8:     use_ok('Net::Telnet::Trango');
1.1       andrew      9: }
                     10:
1.8       andrew     11: diag("51: AP tests when adding an SU to an AP");
1.1       andrew     12:
1.9     ! andrew     13: my $cfg_file = File::Spec->catfile( 't', 'tests.cfg' );
        !            14: my ( $pri, $new_pri, $su2su, $new_su2su ) = ( 'reg', 'pri', '0', 'F' );
        !            15: my ( $cir, $mir, $new_mir ) = ( 128, 256, 1024 );
1.1       andrew     16:
                     17: SKIP: {
1.9     ! andrew     18:     my $skipped = 19;
1.1       andrew     19:     my %cfg;
1.9     ! andrew     20:     if ( -e $cfg_file ) {
        !            21:         if ( open my $fh, $cfg_file ) {
1.1       andrew     22:             while (<$fh>) {
                     23:                 chomp;
1.9     ! andrew     24:                 my ( $key, $value ) = split /\t/, $_, 2;
1.1       andrew     25:                 $cfg{$key} = $value;
                     26:             }
                     27:             close $fh;
                     28:         }
                     29:     }
                     30:
                     31:     my $type = 'AP';
1.9     ! andrew     32:     my ( $host, $pass, $su_id, $su_mac );
1.1       andrew     33:
1.9     ! andrew     34:     if ( $cfg{$type} && $cfg{$type} =~ /^(\d+\.\d+\.\d+.\d+)$/ ) {
1.1       andrew     35:         $host = $1;
                     36:     }
                     37:
1.9     ! andrew     38:     skip 'No valid ' . $type . ' in config file', $skipped unless $host;
1.1       andrew     39:
1.9     ! andrew     40:     if ( $cfg{ $type . '_PASSWD' } && $cfg{ $type . '_PASSWD' } =~ /^(.*)$/ )
        !            41:     {
1.1       andrew     42:         $pass = $1;
                     43:     }
                     44:
1.9     ! andrew     45:     skip 'No valid ' . $type . '_PASSWD in config file', $skipped
        !            46:         unless $pass;
1.1       andrew     47:
1.9     ! andrew     48:     if ( $cfg{SU_ID} && $cfg{SU_ID} =~ /^(\d+)$/ ) {
        !            49:         $su_id = $1;
1.1       andrew     50:     }
                     51:
                     52:     skip 'No valid SU_ID in config file', $skipped unless $su_id;
                     53:
1.9     ! andrew     54:     if (   $cfg{SU_MAC}
        !            55:         && length $cfg{SU_MAC} >= 12
        !            56:         && $cfg{SU_MAC} =~ /^(.*)$/ )
        !            57:     {
1.1       andrew     58:         $su_mac = $1;
                     59:     }
                     60:
                     61:     skip 'No valid SU_MAC in config file', $skipped unless $su_mac;
                     62:
                     63:     my $t;
1.9     ! andrew     64:     ok( $t = Net::Telnet::Trango->new(), "Instantiating object" );
1.1       andrew     65:
1.9     ! andrew     66:     ok( $t->open($host), "Opening connection to $host" );
1.1       andrew     67:
1.9     ! andrew     68:     ok( $t->is_connected, "connected" );
1.1       andrew     69:
1.9     ! andrew     70:     ok( $t->login($pass), "Logging in" );
1.1       andrew     71:
1.9     ! andrew     72:     ok( $t->logged_in, "logged in" );
1.1       andrew     73:
                     74:     my $sudb;
1.9     ! andrew     75:     if ( ( !ok( $sudb = $t->sudb_view, "Getting sudb" ) )
        !            76:         && $t->last_error )
        !            77:     {
        !            78:         diag( 'ERR: ' . $t->last_error );
1.2       andrew     79:     }
                     80:
                     81:     my $in_sudb = 0;
1.9     ! andrew     82:     foreach my $su ( @{$sudb} ) {
        !            83:         if ( $su_id == $su->{suid} ) {
        !            84:             if ( lc($su_mac) eq lc( $su->{mac} ) ) {
        !            85:                 $in_sudb = $su;
        !            86:             }
        !            87:             else {
1.2       andrew     88:                 $in_sudb = -1;
                     89:                 diag("Incorrect mac for SUID $su_id");
                     90:                 diag("  Should be $su_mac");
                     91:                 diag("  Really is $su->{mac}");
                     92:             }
                     93:             last;
                     94:         }
                     95:     }
                     96:
                     97:     if ($in_sudb) {
1.9     ! andrew     98:
1.2       andrew     99:         diag("Removing suid $su_id from AP");
1.9     ! andrew    100:         if ( ( !$t->sudb_delete($su_id) )
        !           101:             && $t->last_error )
        !           102:         {
        !           103:             diag( 'ERR: ' . $t->last_error );
1.2       andrew    104:         }
                    105:     }
1.1       andrew    106:
1.9     ! andrew    107:     if ((   !ok($t->sudb_add( $su_id, $pri, $cir, $mir, $su_mac ),
        !           108:                 "Adding su"
        !           109:             )
        !           110:         )
        !           111:         && $t->last_error
        !           112:         )
        !           113:     {
        !           114:         diag( 'ERR: ' . $t->last_error );
1.1       andrew    115:     }
                    116:
1.2       andrew    117:     $sudb = [];
1.9     ! andrew    118:     if ( ( !ok( $sudb = $t->sudb_view, "Getting sudb" ) )
        !           119:         && $t->last_error )
        !           120:     {
        !           121:         diag( 'ERR: ' . $t->last_error );
1.1       andrew    122:     }
                    123:
1.2       andrew    124:     $in_sudb = 0;
1.9     ! andrew    125:     my $su_mir   = 0;
        !           126:     my $su_su2su = '';
        !           127:     my $su_type  = '';
        !           128:     foreach my $su ( @{$sudb} ) {
        !           129:         if ( $su_id == $su->{suid} ) {
        !           130:             if ( lc($su_mac) eq lc( $su->{mac} ) ) {
1.2       andrew    131:                 $in_sudb = 1;
1.9     ! andrew    132:                 $su_mir   = $su->{mir};
        !           133:                 $su_su2su = $su->{su2su};
        !           134:                 $su_type  = $su->{type};
        !           135:             }
        !           136:             else {
1.2       andrew    137:                 $in_sudb = -1;
                    138:                 diag("Incorrect mac for SUID $su_id");
                    139:                 diag("  Should be $su_mac");
                    140:                 diag("  Really is $su->{mac}");
                    141:             }
                    142:             last;
                    143:         }
                    144:     }
                    145:
1.9     ! andrew    146:     is( $in_sudb, 1, "Correct SU is in SUDB" );
        !           147:
        !           148:     if ( ( !ok( $t->save_sudb, "Saving sudb" ) )
        !           149:         && $t->last_error )
        !           150:     {
        !           151:         diag( 'ERR: ' . $t->last_error );
        !           152:     }
        !           153:
        !           154:     is( $mir,   $su_mir,   "SU has correct mir" );
        !           155:     is( $su2su, $su_su2su, "SU is in correct group" );
        !           156:     is( $pri,   $su_type,  'SU has correct type' );
        !           157:
        !           158:     if ((   !ok($t->sudb_modify( $su_id, 'mir', $new_mir ),
        !           159:                 "modifying su mir"
        !           160:             )
        !           161:         )
        !           162:         && $t->last_error
        !           163:         )
        !           164:     {
        !           165:         diag( 'ERR: ' . $t->last_error );
        !           166:     }
        !           167:
        !           168:     $sudb = [];
        !           169:     if ( ( !ok( $sudb = $t->sudb_view, "Getting sudb" ) )
        !           170:         && $t->last_error )
        !           171:     {
        !           172:         diag( 'ERR: ' . $t->last_error );
        !           173:     }
1.6       andrew    174:
1.9     ! andrew    175:     $su_mir = 0;
        !           176:     foreach my $su ( @{$sudb} ) {
        !           177:         if ( $su_id == $su->{suid} ) {
        !           178:             $su_mir = $su->{mir};
        !           179:             last;
        !           180:         }
1.6       andrew    181:     }
                    182:
1.9     ! andrew    183:     is( $new_mir, $su_mir, "SU has new mir" );
1.6       andrew    184:
1.9     ! andrew    185:     if ((   !ok($t->sudb_modify( $su_id, 'su2su', $new_su2su ),
        !           186:                 "modifying su su2su"
        !           187:             )
        !           188:         )
        !           189:         && $t->last_error
        !           190:         )
        !           191:     {
        !           192:         diag( 'ERR: ' . $t->last_error );
1.6       andrew    193:     }
                    194:
                    195:     $sudb = [];
1.9     ! andrew    196:     if ( ( !ok( $sudb = $t->sudb_view, "Getting sudb" ) )
        !           197:         && $t->last_error )
        !           198:     {
        !           199:         diag( 'ERR: ' . $t->last_error );
1.6       andrew    200:     }
                    201:
1.9     ! andrew    202:     $su_su2su = 0;
        !           203:     foreach my $su ( @{$sudb} ) {
        !           204:         if ( $su_id == $su->{suid} ) {
        !           205:             $su_su2su = $su->{su2su};
1.6       andrew    206:             last;
                    207:         }
                    208:     }
                    209:
1.9     ! andrew    210:     is( $new_su2su, $su_su2su, "SU has new su2su" );
1.6       andrew    211:
1.9     ! andrew    212:     if ( ( !ok( $t->save_sudb, "Saving sudb" ) )
        !           213:         && $t->last_error )
        !           214:     {
        !           215:         diag( 'ERR: ' . $t->last_error );
1.6       andrew    216:     }
1.1       andrew    217:
1.9     ! andrew    218:     ok( $t->bye, "Goodbye" );
1.1       andrew    219: }

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