version 1.1, 2007/02/06 00:42:33 |
version 1.9, 2009/07/09 22:50:36 |
|
|
#!perl -T |
#!perl -T |
# $RedRiver: 50-network.t,v 1.4 2007/02/05 23:11:21 andrew Exp $ |
# $RedRiver: 51-network-add_su-ap.t,v 1.8 2007/02/06 20:59:10 andrew Exp $ |
|
|
use Test::More tests => 7; |
use Test::More tests => 20; |
use File::Spec; |
use File::Spec; |
|
|
BEGIN { |
BEGIN { |
use_ok( 'Net::Telnet::Trango' ); |
use_ok('Net::Telnet::Trango'); |
} |
} |
|
|
diag("Testing Net::Telnet::Trango $Net::Telnet::Trango::VERSION, Perl $], $^X"); |
diag("51: AP tests when adding an SU to an AP"); |
diag(" Generic tests"); |
|
|
|
my $cfg_file = File::Spec->catfile('t', 'tests.cfg'); |
my $cfg_file = File::Spec->catfile( 't', 'tests.cfg' ); |
my ($cir, $mir) = (128, 256); |
my ( $pri, $new_pri, $su2su, $new_su2su ) = ( 'reg', 'pri', '0', 'F' ); |
|
my ( $cir, $mir, $new_mir ) = ( 128, 256, 1024 ); |
|
|
SKIP: { |
SKIP: { |
my $skipped = 6; |
my $skipped = 19; |
my %cfg; |
my %cfg; |
if (-e $cfg_file) { |
if ( -e $cfg_file ) { |
if (open my $fh, $cfg_file) { |
if ( open my $fh, $cfg_file ) { |
while (<$fh>) { |
while (<$fh>) { |
chomp; |
chomp; |
my ($key, $value) = split /\t/, $_, 2; |
my ( $key, $value ) = split /\t/, $_, 2; |
$cfg{$key} = $value; |
$cfg{$key} = $value; |
} |
} |
close $fh; |
close $fh; |
|
|
} |
} |
|
|
my $type = 'AP'; |
my $type = 'AP'; |
my ($host, $pass, $su_id, $su_mac); |
my ( $host, $pass, $su_id, $su_mac ); |
|
|
if ($cfg{$type} && $cfg{$type} =~ /^(\d+\.\d+\.\d+.\d+)$/) { |
if ( $cfg{$type} && $cfg{$type} =~ /^(\d+\.\d+\.\d+.\d+)$/ ) { |
$host = $1; |
$host = $1; |
} |
} |
|
|
skip 'No valid ' . $type . ' in config file', $skipped unless $host; |
skip 'No valid ' . $type . ' in config file', $skipped unless $host; |
|
|
if ($cfg{$type . '_PASSWD'} && $cfg{$type . '_PASSWD'} =~ /^(.*)$/) { |
if ( $cfg{ $type . '_PASSWD' } && $cfg{ $type . '_PASSWD' } =~ /^(.*)$/ ) |
|
{ |
$pass = $1; |
$pass = $1; |
} |
} |
|
|
skip 'No valid ' . $type . '_PASSWD in config file', $skipped unless $pass; |
skip 'No valid ' . $type . '_PASSWD in config file', $skipped |
|
unless $pass; |
|
|
if ($cfg{SU_ID} && $cfg{SU_ID} =~ /^(\d+)$/) { |
if ( $cfg{SU_ID} && $cfg{SU_ID} =~ /^(\d+)$/ ) { |
$su_id= $1; |
$su_id = $1; |
} |
} |
|
|
skip 'No valid SU_ID in config file', $skipped unless $su_id; |
skip 'No valid SU_ID in config file', $skipped unless $su_id; |
|
|
if ($cfg{SU_MAC} && length $cfg{SU_MAC} >= 12 && $cfg{SU_MAC} =~ /^(.*)$/) { |
if ( $cfg{SU_MAC} |
|
&& length $cfg{SU_MAC} >= 12 |
|
&& $cfg{SU_MAC} =~ /^(.*)$/ ) |
|
{ |
$su_mac = $1; |
$su_mac = $1; |
} |
} |
|
|
skip 'No valid SU_MAC in config file', $skipped unless $su_mac; |
skip 'No valid SU_MAC in config file', $skipped unless $su_mac; |
|
|
my $t; |
my $t; |
ok($t = Net::Telnet::Trango->new(), "Instantiating object"); |
ok( $t = Net::Telnet::Trango->new(), "Instantiating object" ); |
|
|
$t->input_log('input.log'); # XXX Debugging |
ok( $t->open($host), "Opening connection to $host" ); |
|
|
ok($t->open($host), "Opening connection to $host"); |
ok( $t->is_connected, "connected" ); |
|
|
ok($t->is_connected, "connected"); |
ok( $t->login($pass), "Logging in" ); |
|
|
ok($t->login($pass), "Logging in"); |
ok( $t->logged_in, "logged in" ); |
|
|
ok($t->logged_in, "logged in"); |
my $sudb; |
|
if ( ( !ok( $sudb = $t->sudb_view, "Getting sudb" ) ) |
|
&& $t->last_error ) |
|
{ |
|
diag( 'ERR: ' . $t->last_error ); |
|
} |
|
|
|
my $in_sudb = 0; |
|
foreach my $su ( @{$sudb} ) { |
|
if ( $su_id == $su->{suid} ) { |
|
if ( lc($su_mac) eq lc( $su->{mac} ) ) { |
|
$in_sudb = $su; |
|
} |
|
else { |
|
$in_sudb = -1; |
|
diag("Incorrect mac for SUID $su_id"); |
|
diag(" Should be $su_mac"); |
|
diag(" Really is $su->{mac}"); |
|
} |
|
last; |
|
} |
|
} |
|
|
my $sudb; |
if ($in_sudb) { |
ok($sudb = $t->sudb_view, "Getting sudb"); |
|
|
|
use YAML; |
diag("Removing suid $su_id from AP"); |
print Dump $sudb; |
if ( ( !$t->sudb_delete($su_id) ) |
|
&& $t->last_error ) |
|
{ |
|
diag( 'ERR: ' . $t->last_error ); |
|
} |
|
} |
|
|
my $result; |
if (( !ok($t->sudb_add( $su_id, $pri, $cir, $mir, $su_mac ), |
ok($result = $t->sudb_add($su_id, 'reg', $cir, $mir, $su_mac), "Adding su"); |
"Adding su" |
|
) |
|
) |
|
&& $t->last_error |
|
) |
|
{ |
|
diag( 'ERR: ' . $t->last_error ); |
|
} |
|
|
if ( (! $result ) && $t->last_error ) { |
$sudb = []; |
diag('ERR: ' . $t->last_error); |
if ( ( !ok( $sudb = $t->sudb_view, "Getting sudb" ) ) |
|
&& $t->last_error ) |
|
{ |
|
diag( 'ERR: ' . $t->last_error ); |
} |
} |
|
|
ok($result = $t->save_sudb, "Saving sudb"); |
$in_sudb = 0; |
|
my $su_mir = 0; |
|
my $su_su2su = ''; |
|
my $su_type = ''; |
|
foreach my $su ( @{$sudb} ) { |
|
if ( $su_id == $su->{suid} ) { |
|
if ( lc($su_mac) eq lc( $su->{mac} ) ) { |
|
$in_sudb = 1; |
|
$su_mir = $su->{mir}; |
|
$su_su2su = $su->{su2su}; |
|
$su_type = $su->{type}; |
|
} |
|
else { |
|
$in_sudb = -1; |
|
diag("Incorrect mac for SUID $su_id"); |
|
diag(" Should be $su_mac"); |
|
diag(" Really is $su->{mac}"); |
|
} |
|
last; |
|
} |
|
} |
|
|
if ( (! $result ) && $t->last_error ) { |
is( $in_sudb, 1, "Correct SU is in SUDB" ); |
diag('ERR: ' . $t->last_error); |
|
|
if ( ( !ok( $t->save_sudb, "Saving sudb" ) ) |
|
&& $t->last_error ) |
|
{ |
|
diag( 'ERR: ' . $t->last_error ); |
} |
} |
|
|
$result = $t->opmode('ap y'); |
is( $mir, $su_mir, "SU has correct mir" ); |
if ( (! $result ) && $t->last_error ) { |
is( $su2su, $su_su2su, "SU is in correct group" ); |
diag('ERR: ' . $t->last_error); |
is( $pri, $su_type, 'SU has correct type' ); |
|
|
|
if (( !ok($t->sudb_modify( $su_id, 'mir', $new_mir ), |
|
"modifying su mir" |
|
) |
|
) |
|
&& $t->last_error |
|
) |
|
{ |
|
diag( 'ERR: ' . $t->last_error ); |
} |
} |
|
|
my $opmode; |
$sudb = []; |
ok($opmode = $t->opmode, "getting current opmode"); |
if ( ( !ok( $sudb = $t->sudb_view, "Getting sudb" ) ) |
|
&& $t->last_error ) |
|
{ |
|
diag( 'ERR: ' . $t->last_error ); |
|
} |
|
|
if (ref $opmode eq 'HASH' && $opmode->{ERR}) { |
$su_mir = 0; |
diag("Error: $opmode->{ERR}"); |
foreach my $su ( @{$sudb} ) { |
|
if ( $su_id == $su->{suid} ) { |
|
$su_mir = $su->{mir}; |
|
last; |
|
} |
} |
} |
|
|
is($opmode->{Opmode}, 'ap', "Checking opmode is ap"); |
is( $new_mir, $su_mir, "SU has new mir" ); |
|
|
ok($t->bye, "Goodbye"); |
if (( !ok($t->sudb_modify( $su_id, 'su2su', $new_su2su ), |
|
"modifying su su2su" |
|
) |
|
) |
|
&& $t->last_error |
|
) |
|
{ |
|
diag( 'ERR: ' . $t->last_error ); |
|
} |
|
|
|
$sudb = []; |
|
if ( ( !ok( $sudb = $t->sudb_view, "Getting sudb" ) ) |
|
&& $t->last_error ) |
|
{ |
|
diag( 'ERR: ' . $t->last_error ); |
|
} |
|
|
|
$su_su2su = 0; |
|
foreach my $su ( @{$sudb} ) { |
|
if ( $su_id == $su->{suid} ) { |
|
$su_su2su = $su->{su2su}; |
|
last; |
|
} |
|
} |
|
|
|
is( $new_su2su, $su_su2su, "SU has new su2su" ); |
|
|
|
if ( ( !ok( $t->save_sudb, "Saving sudb" ) ) |
|
&& $t->last_error ) |
|
{ |
|
diag( 'ERR: ' . $t->last_error ); |
|
} |
|
|
|
ok( $t->bye, "Goodbye" ); |
} |
} |