summaryrefslogtreecommitdiff
path: root/lib/Net/t/config.t
blob: 95a77aad441bd7a1a87780160605812356dd3b90 (plain)
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
#!./perl -w

BEGIN {
    if ($ENV{PERL_CORE}) {
	chdir 't' if -d 't';
	@INC = '../lib';
    }
}

(my $libnet_t = __FILE__) =~ s/config.t/libnet_t.pl/;
require $libnet_t;

print "1..10\n";

use Net::Config;
ok( exists $INC{'Net/Config.pm'}, 'Net::Config should have been used' );
ok( keys %NetConfig, '%NetConfig should be imported' );

undef $NetConfig{'ftp_firewall'};
is( Net::Config->requires_firewall(), 0, 
	'requires_firewall() should return 0 without ftp_firewall defined' );

$NetConfig{'ftp_firewall'} = 1;
is( Net::Config->requires_firewall(''), -1,
	'... should return -1 without a valid hostname' );

delete $NetConfig{'local_netmask'};
is( Net::Config->requires_firewall('127.0.0.1'), 0,
	'... should return 0 without local_netmask defined' );

$NetConfig{'local_netmask'} = '127.0.0.1/24';
is( Net::Config->requires_firewall('127.0.0.1'), 0,
	'... should return false if host is within netmask' );
is( Net::Config->requires_firewall('192.168.10.0'), 1,
	'... should return true if host is outside netmask' );

# now try more netmasks
$NetConfig{'local_netmask'} = [ '127.0.0.1/24', '10.0.0.0/8' ];
is( Net::Config->requires_firewall('10.10.255.254'), 0,
	'... should find success with mutiple local netmasks' );
is( Net::Config->requires_firewall('192.168.10.0'), 1,
	'... should handle failure with multiple local netmasks' );

is( \&Net::Config::is_external, \&Net::Config::requires_firewall,
	'is_external() should be an alias for requires_firewall()' );