2014-09-10 22:43:46 +02:00
|
|
|
#!/usr/bin/perl
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
|
|
|
|
use Test::More;
|
|
|
|
|
2014-09-16 01:58:21 +02:00
|
|
|
use lib 'lib'; # test lib/Qpsmtpd/Base (vs site_perl)
|
2014-09-10 22:43:46 +02:00
|
|
|
|
2014-09-16 08:41:31 +02:00
|
|
|
BEGIN {
|
|
|
|
use_ok('Qpsmtpd::Base');
|
|
|
|
use_ok('Qpsmtpd::Constants');
|
|
|
|
}
|
2014-09-10 22:43:46 +02:00
|
|
|
|
2014-09-16 08:41:31 +02:00
|
|
|
my $base = Qpsmtpd::Base->new();
|
2014-09-10 22:43:46 +02:00
|
|
|
|
|
|
|
__tildeexp();
|
|
|
|
__is_localhost();
|
2014-09-11 22:34:32 +02:00
|
|
|
__is_valid_ip();
|
2014-11-06 03:02:58 +01:00
|
|
|
__get_resolver();
|
|
|
|
__get_async_resolver();
|
|
|
|
__resolve_a();
|
|
|
|
__resolve_aaaa();
|
|
|
|
__resolve_mx();
|
|
|
|
__resolve_ns();
|
|
|
|
__resolve_ptr();
|
2014-09-10 22:43:46 +02:00
|
|
|
|
|
|
|
done_testing();
|
|
|
|
|
2014-09-11 22:34:32 +02:00
|
|
|
sub __is_valid_ip {
|
|
|
|
my @good = qw/ 1.2.3.4 1.0.0.0 254.254.254.254 2001:db8:ffff:ffff:ffff:ffff:ffff:ffff /;
|
|
|
|
foreach my $ip ( @good ) {
|
2014-09-16 02:19:43 +02:00
|
|
|
ok( $base->is_valid_ip($ip), "is_valid_ip: $ip");
|
2014-09-11 22:34:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
my @bad = qw/ 1.2.3.256 256.1.1.1 2001:db8:ffff:ffff:ffff:ffff:ffff:fffj /;
|
|
|
|
foreach my $ip ( @bad ) {
|
2014-09-16 02:19:43 +02:00
|
|
|
ok( !$base->is_valid_ip($ip), "is_valid_ip, neg: $ip");
|
2014-09-11 22:34:32 +02:00
|
|
|
}
|
2014-11-11 23:59:40 +01:00
|
|
|
}
|
2014-09-11 22:34:32 +02:00
|
|
|
|
2014-09-10 22:43:46 +02:00
|
|
|
sub __is_localhost {
|
|
|
|
|
|
|
|
for my $local_ip (qw/ 127.0.0.1 ::1 2607:f060:b008:feed::127.0.0.1 127.0.0.2 /) {
|
2014-09-16 02:19:43 +02:00
|
|
|
ok( $base->is_localhost($local_ip), "is_localhost, $local_ip");
|
2014-09-10 22:43:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
for my $rem_ip (qw/ 128.0.0.1 ::2 2607:f060:b008:feed::128.0.0.1 /) {
|
2014-09-16 02:19:43 +02:00
|
|
|
ok( !$base->is_localhost($rem_ip), "!is_localhost, $rem_ip");
|
2014-09-10 22:43:46 +02:00
|
|
|
}
|
2014-11-11 23:59:40 +01:00
|
|
|
}
|
2014-09-10 22:43:46 +02:00
|
|
|
|
|
|
|
sub __tildeexp {
|
2014-09-16 02:19:43 +02:00
|
|
|
my $path = $base->tildeexp('~root/foo.txt');
|
2014-09-10 22:43:46 +02:00
|
|
|
ok( $path, "tildeexp, $path");
|
|
|
|
|
2014-09-16 02:19:43 +02:00
|
|
|
$path = $base->tildeexp('no/tilde/in/path');
|
2014-09-10 22:43:46 +02:00
|
|
|
cmp_ok( $path, 'eq', 'no/tilde/in/path', 'tildeexp, no expansion');
|
2014-11-11 23:59:40 +01:00
|
|
|
}
|
2014-11-06 03:02:58 +01:00
|
|
|
|
|
|
|
sub __get_resolver {
|
|
|
|
my $res = $base->get_resolver();
|
|
|
|
isa_ok( $res, 'Net::DNS::Resolver', "get_resolver returns a Net::DNS::Resolver");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
sub __get_async_resolver {
|
2014-11-06 20:12:01 +01:00
|
|
|
eval 'use Net::DNS::Async';
|
|
|
|
return if ($@);
|
2014-11-06 03:02:58 +01:00
|
|
|
my $res = $base->get_async_resolver() or return;
|
|
|
|
isa_ok( $res, 'Net::DNS::Async', "resolver object, $res");
|
|
|
|
isa_ok( $res->{Resolver}, 'Net::DNS::Resolver', "resolver object, $res");
|
|
|
|
}
|
|
|
|
|
|
|
|
sub __resolve_a {
|
|
|
|
my @r = $base->resolve_a('simerson.net');
|
|
|
|
ok(@r, "resolve_a: " . join(',', @r));
|
|
|
|
}
|
|
|
|
|
|
|
|
sub __resolve_aaaa {
|
|
|
|
my @r = $base->resolve_aaaa('ns2.cadillac.net');
|
|
|
|
ok(@r, "resolve_aaaa: " . join(',', @r));
|
|
|
|
}
|
|
|
|
|
|
|
|
sub __resolve_mx {
|
|
|
|
my @r = $base->resolve_mx('simerson.net');
|
|
|
|
ok(@r, "resolve_mx: " . join(',', @r));
|
|
|
|
}
|
|
|
|
|
|
|
|
sub __resolve_ns {
|
|
|
|
my @r = $base->resolve_ns('simerson.net');
|
|
|
|
ok(@r, "resolve_ns: " . join(', ', @r));
|
|
|
|
}
|
|
|
|
|
|
|
|
sub __resolve_ptr {
|
|
|
|
my @r = $base->resolve_ptr('163.51.128.66.in-addr.arpa.');
|
|
|
|
ok(@r, "resolve_ptr: FQDN: " . join(', ', @r));
|
|
|
|
|
|
|
|
@r = $base->resolve_ptr('66.128.51.163');
|
|
|
|
ok(@r, "resolve_ptr, IP: " . join(', ', @r));
|
|
|
|
}
|