1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
|
#!/usr/bin/perl
# Test the parsing of individual attributes
# $Id: packdict.t 37 2006-11-14 01:42:55Z lem $
use IO::File;
use Test::More tests => 30;
use Data::Dumper;
use Net::Radius::Dictionary;
my $dictfile = "dict$$.tmp";
END
{
unlink $dictfile;
};
{
my $dict;
eval { $dict = Net::Radius::Dictionary->new() };
isa_ok($dict, 'Net::Radius::Dictionary');
ok(!$@, 'No errors during parse');
diag $@ if $@;
# Test presence of some stuff
my %number_for = $dict->packet_numbers();
is(scalar(keys %number_for), 35, 'Default packet numbers number');
is($number_for{'Disconnect-NAK'}, 42, 'Simple mapping presence in hash');
my %name_for = $dict->packet_names();
is(scalar(keys %name_for), 34, 'Default packet names number');
is($name_for{40}, 'Disconnect-Request', 'Simple mapping presence in hash');
is($name_for{6}, 'Interim-Accounting',
'Back-resolution of 6 to Interim Accounting as default');
# Direct resolution
ok($dict->packet_hasname('Access-Reject'),
'packet_hasname() to default');
is($dict->packet_num('Access-Reject'), 3, 'packet_num() to default');
ok($dict->packet_hasnum(2), 'packet_hasnum() to default');
is($dict->packet_name(2), 'Access-Accept', 'packet_name() to default');
ok(! $dict->packet_hasname('@@Inexistent@@'),
'packet_hasname() on inexistent');
is($dict->packet_num('@@Inexistent@@'), undef,
'packet_num() on inexistent');
ok(! $dict->packet_hasnum(-1), 'packet_hasnum() on inexistent');
is($dict->packet_name(-1), undef, 'packet_name() on inexistent');
}
{
my $dict_content = do { local $/; <DATA>; };
_write($dict_content);
my $dict;
eval { $dict = Net::Radius::Dictionary->new($dictfile) };
isa_ok($dict, 'Net::Radius::Dictionary');
ok(!$@, 'No errors during parse');
diag $@ if $@;
# Test presence of some stuff
my %number_for = $dict->packet_numbers();
is(scalar(keys %number_for), 10, 'Packet numbers number');
is($number_for{'My-Experiment'}, 250, 'Simple mapping presence in hash');
my %name_for = $dict->packet_names();
is(scalar(keys %name_for), 10, 'Packet names number');
is($name_for{1}, 'Access-Request', 'Simple mapping presence in hash');
is($name_for{250}, 'My-Experiment', 'Experimental value');
# Direct resolution
ok($dict->packet_hasname('Access-Reject'),
'packet_hasname() to default');
is($dict->packet_num('Access-Reject'), 3, 'packet_num() to default');
ok($dict->packet_hasnum(2), 'packet_hasnum() to default');
is($dict->packet_name(2), 'Access-Accept', 'packet_name() to default');
ok(! $dict->packet_hasname('Disconnect-Request'),
'packet_hasname() on inexistent');
is($dict->packet_num('Disconnect-NAK'), undef,
'packet_num() on inexistent');
ok(! $dict->packet_hasnum(41), 'packet_hasnum() on inexistent');
is($dict->packet_name(41), undef, 'packet_name() on inexistent');
}
sub _write
{
my $dict = shift;
my $fh = new IO::File;
$fh->open($dictfile, "w") or diag "Failed to write dict $dictfile: $!";
print $fh $dict;
$fh->close;
}
__END__
# Sample dictionary
PACKET Access-Request 1
PACKET Access-Accept 2
PACKET Access-Reject 3
PACKET Accounting-Request 4
PACKET Accounting-Response 5
PACKET Accounting-Status 6
PACKET Access-Challenge 11
PACKET Status-Server 12
PACKET Status-Client 13
PACKET My-Experiment 250
|