/
test.pl
69 lines (49 loc) · 1.65 KB
/
test.pl
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
# Before `make install' is performed this script should be runnable with
# `make test'. After `make install' it should work as `perl test.pl'
use strict;
use warnings;
use Getopt::Long;
use Test::More tests => 6;
BEGIN {
use_ok('Authen::Radius');
}
require_ok('Authen::Radius');
my $interactive = 0;
my $verbose = 0;
GetOptions( "interactive!" => \$interactive, "verbose+" => \$verbose );
SKIP: {
skip( "Non-interactive mode", 3 ) unless ($interactive);
print "Make sure this machine is in your Radius clients file!\n";
print "Enter hostname[:port] of your Radius server: ";
chomp( my $host = <STDIN> );
print "Enter shared-secret of your Radius server: ";
chomp( my $secret = <STDIN> );
print "Enter a username to be validated: ";
chomp( my $user = <STDIN> );
print "Enter this user's password: ";
chomp( my $pwd = <STDIN> );
my $r = new_ok(
'Authen::Radius' => [
Host => $host,
Secret => $secret,
Debug => $verbose,
],
);
# Authen::Radius->load_dictionary();
my $result = $r->check_pwd( $user, $pwd );
ok($result);
my @attributes = $r->get_attributes();
cmp_ok( $#attributes, '!=', -1 );
}
# Convert each two-digit hex number back to an ASCII character.
sub hex_to_ascii {
my $str = shift;
return $str unless ( defined $str );
$str =~ s/([a-fA-F0-9]{2})/chr(hex $1)/eg;
return $str;
}
my $key = "Jefe";
my $data = "what do ya want for nothing?";
my $etalon_digest = hex_to_ascii("750c783e6ab0b503eaa86e310a5db738");
my $digest = Authen::Radius::hmac_md5( undef, $data, $key );
cmp_ok( $digest, 'eq', $etalon_digest );