my
$tests
= 119;
my
$db
=
"test-$$.db"
;
my
$class
=
'db'
;
plan
tests
=> 1 +
$tests
;
END {
unlink
$db
; }
SKIP:
{
skip
"Failed to use DBS::BL"
,
$tests
unless
use_ok(
'DNS::BL'
);
my
$bl
;
isa_ok(
$bl
= new DNS::BL,
"DNS::BL"
,
'new DNS::BL'
);
my
@r
;
my
$com
=
"connect $class file $db"
;
eval
{
@r
=
$bl
->parse(
$com
); };
diag
"->parse($com) failed miserably: $@"
unless
ok(!$@,
"Parsing of $com"
);
diag
"$com returned $r[0] / $r[1]"
unless
is(
$r
[0],
&DNS::BL::DNSBL_OK
,
"result $com"
);
$com
=
"print within any as internal"
;
eval
{
@r
=
$bl
->parse(
$com
); };
diag
"->parse($com) failed miserably: $@"
unless
ok(!$@,
"Parsing of $com"
);
diag
"$com returned $r[0] / $r[1] but should be empty"
unless
is(
$r
[0],
&DNS::BL::DNSBL_ENOTFOUND
,
"result $com"
);
ok(-f
$db
,
"Database was created on disk"
);
die
"Failed to use NetAddr::IP"
unless
use_ok(
'NetAddr::IP'
);
for
my
$ip
(
map
{ NetAddr::IP->new(
$_
) }
qw(10.0.0.0/24 10.0.1.0/24)
)
{
$com
=
qq{add ip $ip text "$ip $$ test entry"}
;
eval
{
@r
=
$bl
->parse(
$com
); };
diag
"->parse($com) failed miserably: $@"
unless
ok(!$@,
"Parsing of $com"
);
diag
"$com returned $r[0] / $r[1] to addition"
unless
is(
$r
[0],
&DNS::BL::DNSBL_OK
,
"result $com"
);
}
for
my
$mask
(0 .. 24)
{
$com
=
qq{add ip 10.0.0.0/$mask text "10.0.0.0/$mask $$ collission"}
;
eval
{
@r
=
$bl
->parse(
$com
); };
diag
"->parse($com) failed miserably: $@"
unless
ok(!$@,
"Parsing of $com"
);
diag
"$com returned $r[0] / $r[1] to addition with collission"
unless
is(
$r
[0],
&DNS::BL::DNSBL_ECOLLISSION
,
"result $com"
);
}
$com
=
qq{print within any as internal}
;
eval
{
@r
=
$bl
->parse(
$com
); };
diag
"->parse($com) failed miserably: $@"
unless
ok(!$@,
"Parsing of $com"
);
diag
"$com returned $r[0] / $r[1] to print any"
unless
is(
$r
[0],
&DNS::BL::DNSBL_OK
,
"result $com"
);
is(
scalar
@r
, 4,
"Correct number of elements returned"
);
splice
@r
, 0, 2;
for
my
$r
(
@r
)
{
ok((
grep
{
$r
->addr eq
$_
}
qw(10.0.0.0/24 10.0.1.0/24)
),
"Proper entry "
.
$r
->addr);
is(
$r
->desc,
$r
->addr .
" $$ test entry"
,
"Correct test entry "
.
$r
->addr);
}
for
my
$ip
(
map
{ NetAddr::IP->new(
$_
) }
qw(10.0.0.0/24 10.0.1.0/24)
)
{
$com
=
qq{add ip $ip text "$ip $$ 2nd test entry" without checking}
;
eval
{
@r
=
$bl
->parse(
$com
); };
diag
"->parse($com) failed miserably: $@"
unless
ok(!$@,
"Parsing of $com"
);
diag
"$com returned $r[0] / $r[1] to addition"
unless
is(
$r
[0],
&DNS::BL::DNSBL_OK
,
"result $com"
);
}
$com
=
qq{print within any as internal}
;
eval
{
@r
=
$bl
->parse(
$com
); };
diag
"->parse($com) failed miserably: $@"
unless
ok(!$@,
"Parsing of $com"
);
diag
"$com returned $r[0] / $r[1]"
unless
is(
$r
[0],
&DNS::BL::DNSBL_OK
,
"result $com"
);
is(
scalar
@r
, 4,
"Correct number of elements returned"
);
splice
@r
, 0, 2;
for
my
$r
(
@r
)
{
ok((
grep
{
$r
->addr eq
$_
}
qw(10.0.0.0/24 10.0.1.0/24)
),
"Proper entry "
.
$r
->addr);
is(
$r
->desc,
$r
->addr .
" $$ 2nd test entry"
,
"Correct test entry "
.
$r
->addr);
}
$com
=
qq{print within 10/8 as internal}
;
eval
{
@r
=
$bl
->parse(
$com
); };
diag
"->parse($com) failed miserably: $@"
unless
ok(!$@,
"Parsing of $com"
);
diag
"$com returned $r[0] / $r[1]"
unless
is(
$r
[0],
&DNS::BL::DNSBL_OK
,
"result $com"
);
is(
scalar
@r
, 4,
"Correct number of elements returned"
);
splice
@r
, 0, 2;
for
my
$r
(
@r
)
{
ok((
grep
{
$r
->addr eq
$_
}
qw(10.0.0.0/24 10.0.1.0/24)
),
"Proper entry "
.
$r
->addr);
is(
$r
->desc,
$r
->addr .
" $$ 2nd test entry"
,
"Correct test entry "
.
$r
->addr);
}
$com
=
qq{print within 10.0.1.0/25 as internal}
;
eval
{
@r
=
$bl
->parse(
$com
); };
diag
"->parse($com) failed miserably: $@"
unless
ok(!$@,
"Parsing of $com"
);
diag
"$com returned $r[0] / $r[1]"
unless
is(
$r
[0],
&DNS::BL::DNSBL_ENOTFOUND
,
"result $com"
);
is(
scalar
@r
, 2,
"Correct number of elements returned"
);
$com
=
qq{print matching 10/8 as internal}
;
eval
{
@r
=
$bl
->parse(
$com
); };
diag
"->parse($com) failed miserably: $@"
unless
ok(!$@,
"Parsing of $com"
);
diag
"$com returned $r[0] / $r[1]"
unless
is(
$r
[0],
&DNS::BL::DNSBL_ENOTFOUND
,
"result $com"
);
is(
scalar
@r
, 2,
"Correct number of elements returned"
);
$com
=
qq{print matching 10.0.1.0/25 as internal}
;
eval
{
@r
=
$bl
->parse(
$com
); };
diag
"->parse($com) failed miserably: $@"
unless
ok(!$@,
"Parsing of $com"
);
diag
"$com returned $r[0] / $r[1]"
unless
is(
$r
[0],
&DNS::BL::DNSBL_OK
,
"result $com"
);
is(
scalar
@r
, 3,
"Correct number of elements returned"
);
is(
$r
[2]->addr,
'10.0.1.0/24'
,
"Correct entry "
.
$r
[2]->addr);
is(
$r
[2]->desc,
"10.0.1.0/24 $$ 2nd test entry"
,
"Correct test entry 10.0.1.0/24"
);
$com
=
qq{delete within 10.0.1.0/25}
;
eval
{
@r
=
$bl
->parse(
$com
); };
diag
"->parse($com) failed miserably: $@"
unless
ok(!$@,
"Parsing of $com"
);
diag
"$com returned $r[0] / $r[1]"
unless
is(
$r
[0],
&DNS::BL::DNSBL_ENOTFOUND
,
"result of $com"
);
is(
scalar
@r
, 2,
"Correct number of elements returned"
);
$com
=
qq{delete within 10.0.1.0/23}
;
eval
{
@r
=
$bl
->parse(
$com
); };
diag
"->parse($com) failed miserably: $@"
unless
ok(!$@,
"Parsing of $com"
);
diag
"$com returned $r[0] / $r[1]"
unless
is(
$r
[0],
&DNS::BL::DNSBL_OK
,
"result of $com"
);
is(
scalar
@r
, 2,
"Correct number of elements returned"
);
for
my
$ip
(
map
{ NetAddr::IP->new(
$_
) }
qw(10.0.0.0/24 10.0.1.0/24)
)
{
$com
=
qq{add ip $ip text "$ip $$ test entry"}
;
eval
{
@r
=
$bl
->parse(
$com
); };
diag
"->parse($com) failed miserably: $@"
unless
ok(!$@,
"Parsing of $com"
);
diag
"$com returned $r[0] / $r[1]"
unless
is(
$r
[0],
&DNS::BL::DNSBL_OK
,
"result $com"
);
}
$com
=
qq{punch hole 10.0.0.0/25}
;
eval
{
@r
=
$bl
->parse(
$com
); };
diag
"->parse($com) failed miserably: $@"
unless
ok(!$@,
"Parsing of $com"
);
diag
"$com returned $r[0] / $r[1]"
unless
is(
$r
[0],
&DNS::BL::DNSBL_OK
,
"result $com"
);
$com
=
qq{print within 10.0.0.0/24 as internal}
;
eval
{
@r
=
$bl
->parse(
$com
); };
diag
"->parse($com) failed miserably: $@"
unless
ok(!$@,
"Parsing of $com"
);
diag
"$com returned $r[0] / $r[1]"
unless
is(
$r
[0],
&DNS::BL::DNSBL_OK
,
"result $com"
);
is(
scalar
@r
, 3,
"Correct number of elements returned"
);
is(
$r
[2]->addr,
'10.0.0.128/25'
,
"Correct entry "
.
$r
[2]->addr);
is(
$r
[2]->desc,
"10.0.0.0/24 $$ test entry"
,
"Correct test entry 10.0.1.0/25"
);
$com
=
qq{punch hole 10.0.0.0/8}
;
eval
{
@r
=
$bl
->parse(
$com
); };
diag
"->parse($com) failed miserably: $@"
unless
ok(!$@,
"Parsing of $com"
);
diag
"$com returned $r[0] / $r[1]"
unless
is(
$r
[0],
&DNS::BL::DNSBL_OK
,
"result $com"
);
$com
=
qq{print within any as internal}
;
eval
{
@r
=
$bl
->parse(
$com
); };
diag
"->parse($com) failed miserably: $@"
unless
ok(!$@,
"Parsing of $com"
);
diag
"$com returned $r[0] / $r[1]"
unless
is(
$r
[0],
&DNS::BL::DNSBL_ENOTFOUND
,
"result $com"
);
is(
scalar
@r
, 2,
"Correct number of elements returned"
);
};