File: attrunset.t

package info (click to toggle)
libnet-radius-perl 2.103%2Bdfsg-1.1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid, trixie
  • size: 1,276 kB
  • sloc: perl: 4,561; tcl: 33; makefile: 2
file content (55 lines) | stat: -rw-r--r-- 1,621 bytes parent folder | download | duplicates (2)
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
#!/usr/bin/perl

# Test attribute unsetting attributes with ASCII and non-ASCII (8-bit) values

# $Id: attrunset.t 81 2007-04-26 20:25:21Z lem $


use IO::File;
use Test::More qw/no_plan/;
use Net::Radius::Packet;
use Net::Radius::Dictionary;

# Init the dictionary for our test run...
BEGIN {
    my $fh = new IO::File "dict.$$", ">";
    print $fh <<EOF;
ATTRIBUTE	User-Name		1	string
ATTRIBUTE	NAS-IP-Address		4	ipaddr
ATTRIBUTE	NAS-Port		5	integer
ATTRIBUTE	Reply-Message		18	string
EOF

    close $fh;
};

END { unlink 'dict.' . $$; }

my $d = new Net::Radius::Dictionary "dict.$$";
isa_ok($d, 'Net::Radius::Dictionary');

# Build a request and test it is ok
my $p = new Net::Radius::Packet $d;
isa_ok($p, 'Net::Radius::Packet');
$p->set_identifier(42);
$p->set_authenticator("\x66" x 16);
$p->set_code("Access-Accept");
$p->set_attr('Reply-Message' => 'Hello World 1');

is($p->attr('Reply-Message'), 'Hello World 1', 'ASCII Reply-Message loaded');

$p->unset_attr('Reply-Message', $p->attr('Reply-Message'));
is($p->attr('Reply-Message'), undef, 'ASCII Reply-Message deleted');

$p->set_attr('Reply-Message' => '¡Hola Mundo!');
is($p->attr('Reply-Message'), '¡Hola Mundo!', 'UTF-8 Reply-Message loaded');

$p->unset_attr('Reply-Message', $p->attr('Reply-Message'));
is($p->attr('Reply-Message'), undef, 'UTF-8 Reply-Message loaded');

$p->set_attr('Reply-Message' => "\xde\xad\x00\xbe\xef");
is($p->attr('Reply-Message'), "\xde\xad\x00\xbe\xef", 
   '8-bit Reply-Message present');

$p->unset_attr('Reply-Message', $p->attr('Reply-Message'));
is($p->attr('Reply-Message'), undef, '8-bit Reply-Message deleted');