qpsmtpd/t/plugin_tests/user_config

56 lines
1.7 KiB
Plaintext
Raw Permalink Normal View History

2014-09-15 17:40:06 +02:00
#!perl -w
use strict;
use warnings;
use File::Path;
use Qpsmtpd::Constants;
BEGIN { # need this to happen before anything else
my $cwd = `pwd`;
chomp($cwd);
open my $spooldir, '>', "./config.sample/spool_dir";
print $spooldir "$cwd/t/tmp";
close $spooldir;
}
sub register_tests {
my ($self) = @_;
$self->register_test('test_hook_user_config');
2014-09-15 17:40:06 +02:00
}
sub test_hook_user_config {
my ($self) = @_;
2014-09-15 17:40:06 +02:00
my $dirname = $self->qp->temp_dir;
$self->{pattern} = $dirname . '/%u_%h_%a';
$dirname .= '/testuser_testhost_testaddress';
-d $dirname
or mkdir($dirname, 0700)
or die "Could not create $dirname: $!";
2014-09-15 17:40:06 +02:00
open my $fh, '>', "$dirname/testfield";
print $fh "testdata";
close $fh;
my $a = FakeAddress->new(
user => 'testuser',
host => 'testhost',
address => 'testaddress'
);
my ($r, $value) =
$self->hook_user_config($self->qp->transaction, $a, 'testfield');
is($r, OK, 'hook_user_config returned OK when config file present');
is($value, 'testdata', 'hook_user_config returned the correct value');
($r, $value) =
$self->hook_user_config($self->qp->transaction, $a, 'noconfig');
is($r, DECLINED,
'hook_user_config returned DECLINED when no config file present');
is($value, undef,
'hook_user_config returned no value when no config file present');
2014-09-15 17:40:06 +02:00
rmtree($dirname);
}
package FakeAddress;
sub new { return bless {@_}, shift; }
2014-09-15 17:40:06 +02:00
sub address { return shift->{address} }
sub user { return shift->{user} }
sub host { return shift->{host} }