qpsmtpd/t/qpsmtpd-base.t

49 lines
1.2 KiB
Perl
Raw Normal View History

#!/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-16 01:58:21 +02:00
BEGIN { use_ok('Qpsmtpd::Base'); }
2014-09-16 02:19:43 +02:00
my $base = bless {}, 'Qpsmtpd::Base';
__tildeexp();
__is_localhost();
__is_valid_ip();
done_testing();
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");
}
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");
}
};
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");
}
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");
}
};
sub __tildeexp {
2014-09-16 02:19:43 +02:00
my $path = $base->tildeexp('~root/foo.txt');
ok( $path, "tildeexp, $path");
2014-09-16 02:19:43 +02:00
$path = $base->tildeexp('no/tilde/in/path');
cmp_ok( $path, 'eq', 'no/tilde/in/path', 'tildeexp, no expansion');
};