2014-09-09 07:58:27 +02:00
|
|
|
#!/usr/bin/perl
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
|
|
|
|
use Data::Dumper;
|
|
|
|
use Test::More;
|
|
|
|
|
|
|
|
use lib 'lib'; # test lib/Qpsmtpd (vs site_perl)
|
|
|
|
BEGIN { use_ok('Qpsmtpd'); }
|
|
|
|
BEGIN { use_ok('Qpsmtpd::Constants'); }
|
|
|
|
|
2014-09-15 20:53:28 +02:00
|
|
|
my $qp = bless {}, 'Qpsmtpd';
|
2014-09-09 07:58:27 +02:00
|
|
|
|
|
|
|
ok( $qp->version(), "version, " . $qp->version());
|
|
|
|
is_deeply( Qpsmtpd::hooks(), {}, 'hooks, empty');
|
|
|
|
|
2014-09-15 20:53:28 +02:00
|
|
|
__authenticated();
|
2014-09-09 07:58:27 +02:00
|
|
|
__config_dir();
|
2014-09-15 20:53:28 +02:00
|
|
|
__get_qmail_config();
|
|
|
|
__config();
|
2014-09-09 07:58:27 +02:00
|
|
|
__log();
|
|
|
|
__load_logging();
|
|
|
|
|
|
|
|
done_testing();
|
|
|
|
|
2014-09-15 20:53:28 +02:00
|
|
|
sub __config {
|
|
|
|
my @r = $qp->config('badhelo');
|
|
|
|
ok( $r[0], "config, badhelo, @r");
|
|
|
|
};
|
|
|
|
|
|
|
|
sub __get_qmail_config {
|
|
|
|
ok( !$qp->get_qmail_config('me'), "get_qmail_config, me");
|
|
|
|
|
|
|
|
# TODO: add positive tests.
|
|
|
|
};
|
|
|
|
|
|
|
|
sub __config_from_file {
|
|
|
|
# $configfile, $config, $visited
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2014-09-09 07:58:27 +02:00
|
|
|
sub __log {
|
2014-09-12 08:23:09 +02:00
|
|
|
my $warned = '';
|
|
|
|
local $SIG{__WARN__} = sub {
|
|
|
|
if ( $_[0] eq "$$ test log message\n" ) {
|
|
|
|
$warned = join ' ', @_;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
warn @_;
|
|
|
|
}
|
|
|
|
};
|
2014-09-09 07:58:27 +02:00
|
|
|
ok( $qp->log(LOGWARN, "test log message"), 'log');
|
2014-09-12 08:23:09 +02:00
|
|
|
is( $warned, "$$ test log message\n", 'LOGWARN emitted correct warning' );
|
2014-09-09 07:58:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
sub __config_dir {
|
|
|
|
my $dir = $qp->config_dir('logging');
|
|
|
|
ok( $dir, "config_dir, $dir");
|
|
|
|
|
|
|
|
#warn Data::Dumper::Dumper($Qpsmtpd::config_dir_memo{logging});
|
|
|
|
$dir = $Qpsmtpd::config_dir_memo{logging};
|
|
|
|
ok( $dir, "config_dir, $dir (memo)");
|
|
|
|
};
|
|
|
|
|
|
|
|
sub __load_logging {
|
|
|
|
$Qpsmtpd::LOGGING_LOADED = 1;
|
|
|
|
ok( !$qp->load_logging(), "load_logging, loaded");
|
|
|
|
|
|
|
|
$Qpsmtpd::LOGGING_LOADED = 0;
|
|
|
|
$Qpsmtpd::hooks->{logging} = 1;
|
|
|
|
ok( !$qp->load_logging(), "load_logging, logging hook");
|
|
|
|
|
|
|
|
$Qpsmtpd::hooks->{logging} = undef; # restore
|
|
|
|
}
|
2014-09-15 20:53:28 +02:00
|
|
|
|
|
|
|
sub __authenticated {
|
|
|
|
|
|
|
|
ok( ! $qp->authenticated(), "authenticated, undef");
|
|
|
|
|
|
|
|
$qp->{_auth} = 1;
|
|
|
|
ok( $qp->authenticated(), "authenticated, true");
|
|
|
|
|
|
|
|
$qp->{_auth} = 0;
|
|
|
|
ok( !$qp->authenticated(), "authenticated, false");
|
|
|
|
};
|