-
Notifications
You must be signed in to change notification settings - Fork 70
/
cidrs.t
executable file
·66 lines (53 loc) · 1.68 KB
/
cidrs.t
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
#!/usr/bin/perl
BEGIN {
if (-e 't/test_dir') { # if we are running "t/rule_tests.t", kluge around ...
chdir 't';
}
if (-e 'test_dir') { # running from test directory, not ..
unshift(@INC, '../blib/lib');
}
}
my $prefix = '.';
if (-e 'test_dir') { # running from test directory, not ..
$prefix = '..';
}
use strict;
use Test;
use Mail::SpamAssassin;
use Mail::SpamAssassin::NetSet;
my $sa = Mail::SpamAssassin->new({
rules_filename => "$prefix/rules",
});
plan tests => 22;
sub tryone {
my ($testip, @nets) = @_;
my $nets = Mail::SpamAssassin::NetSet->new();
foreach my $net (@nets) { $nets->add_cidr ($net); }
if ($nets->contains_ip ($testip)) {
print "\n$testip was in @nets\n"; return 1;
} else {
print "\n$testip was not in @nets\n"; return 0;
}
}
ok (tryone ("127.0.0.1", "127.0.0.1"));
ok (!tryone ("127.0.0.2", "127.0.0.1"));
ok (tryone ("127.0.0.1", "127."));
ok (tryone ("127.0.0.254", "127."));
ok (tryone ("127.0.0.1", "127/8"));
ok (tryone ("127.0.0.1", "127.0/16"));
ok (tryone ("127.0.0.1", "127.0.0/24"));
ok (tryone ("127.0.0.1", "127.0.0.1/32"));
ok (tryone ("127.0.0.1", "127.0.0.1/31"));
ok (tryone ("127.0.0.1", "10.", "11.", "127.0.0.1"));
ok (tryone ("127.0.0.1", "127.0."));
ok (tryone ("127.0.0.1", "127.0.0."));
ok (tryone ("127.0.0.1", "127."));
ok (!tryone ("128.0.0.254", "127."));
ok (!tryone ("128.0.0.1", "127/8"));
ok (!tryone ("128.0.0.1", "127.0/16"));
ok (!tryone ("128.0.0.1", "127.0.0/24"));
ok (!tryone ("128.0.0.1", "127.0.0.1/32"));
ok (!tryone ("128.0.0.1", "127.0.0.1/31"));
ok (!tryone ("128.0.0.1", "127.0."));
ok (!tryone ("128.0.0.1", "127.0.0."));
ok (!tryone ("12.9.0.1", "10.", "11.", "127.0.0.1"));