commit
bf2cfcf4e3
3
MANIFEST
3
MANIFEST
@ -207,6 +207,9 @@ t/plugin_tests/sender_permitted_from
|
|||||||
t/plugin_tests/spamassassin
|
t/plugin_tests/spamassassin
|
||||||
t/plugin_tests/virus/clamdscan
|
t/plugin_tests/virus/clamdscan
|
||||||
t/qpsmtpd-address.t
|
t/qpsmtpd-address.t
|
||||||
|
t/qpsmtpd-smtp.t
|
||||||
|
t/qpsmtpd-utils.t
|
||||||
|
t/qpsmtpd.t
|
||||||
t/rset.t
|
t/rset.t
|
||||||
t/tempstuff.t
|
t/tempstuff.t
|
||||||
t/Test/Qpsmtpd.pm
|
t/Test/Qpsmtpd.pm
|
||||||
|
@ -7,7 +7,6 @@ WriteMakefile(
|
|||||||
NAME => 'qpsmtpd',
|
NAME => 'qpsmtpd',
|
||||||
VERSION_FROM => 'lib/Qpsmtpd.pm',
|
VERSION_FROM => 'lib/Qpsmtpd.pm',
|
||||||
PREREQ_PM => {
|
PREREQ_PM => {
|
||||||
'Test::Output' => 0,
|
|
||||||
'Data::Dumper' => 0,
|
'Data::Dumper' => 0,
|
||||||
'Date::Parse' => 0,
|
'Date::Parse' => 0,
|
||||||
'File::Temp' => 0,
|
'File::Temp' => 0,
|
||||||
@ -17,6 +16,9 @@ WriteMakefile(
|
|||||||
'Net::IP' => 0,
|
'Net::IP' => 0,
|
||||||
'Time::HiRes' => 0,
|
'Time::HiRes' => 0,
|
||||||
'IO::Socket::SSL' => 0,
|
'IO::Socket::SSL' => 0,
|
||||||
|
# Dev/Test modules
|
||||||
|
'Test::More' => 0,
|
||||||
|
'Test::Output' => 0,
|
||||||
# modules for specific features
|
# modules for specific features
|
||||||
'Mail::DKIM' => 0,
|
'Mail::DKIM' => 0,
|
||||||
'File::Tail' => 0, # log/summarize, log/watch
|
'File::Tail' => 0, # log/summarize, log/watch
|
||||||
|
@ -1,12 +1,15 @@
|
|||||||
package Qpsmtpd::SMTP;
|
|
||||||
use Qpsmtpd;
|
|
||||||
@ISA = qw(Qpsmtpd);
|
|
||||||
my %auth_mechanisms = ();
|
|
||||||
|
|
||||||
package Qpsmtpd::SMTP;
|
package Qpsmtpd::SMTP;
|
||||||
use strict;
|
use strict;
|
||||||
use Carp;
|
|
||||||
|
|
||||||
|
use base 'Qpsmtpd';
|
||||||
|
|
||||||
|
use Carp;
|
||||||
|
#use Data::Dumper;
|
||||||
|
use POSIX qw(strftime);
|
||||||
|
use Mail::Header;
|
||||||
|
use Net::DNS;
|
||||||
|
|
||||||
|
use Qpsmtpd;
|
||||||
use Qpsmtpd::Connection;
|
use Qpsmtpd::Connection;
|
||||||
use Qpsmtpd::Transaction;
|
use Qpsmtpd::Transaction;
|
||||||
use Qpsmtpd::Plugin;
|
use Qpsmtpd::Plugin;
|
||||||
@ -15,11 +18,7 @@ use Qpsmtpd::Auth;
|
|||||||
use Qpsmtpd::Address ();
|
use Qpsmtpd::Address ();
|
||||||
use Qpsmtpd::Command;
|
use Qpsmtpd::Command;
|
||||||
|
|
||||||
use Mail::Header ();
|
my %auth_mechanisms = ();
|
||||||
|
|
||||||
#use Data::Dumper;
|
|
||||||
use POSIX qw(strftime);
|
|
||||||
use Net::DNS;
|
|
||||||
|
|
||||||
# this is only good for forkserver
|
# this is only good for forkserver
|
||||||
# can't set these here, cause forkserver resets them
|
# can't set these here, cause forkserver resets them
|
||||||
@ -27,19 +26,16 @@ use Net::DNS;
|
|||||||
#$SIG{ALRM} = sub { warn "Connection Timed Out\n"; exit; };
|
#$SIG{ALRM} = sub { warn "Connection Timed Out\n"; exit; };
|
||||||
|
|
||||||
sub new {
|
sub new {
|
||||||
my $proto = shift;
|
my ($proto, %args) = @_;
|
||||||
my $class = ref($proto) || $proto;
|
my $class = ref($proto) || $proto;
|
||||||
|
|
||||||
my %args = @_;
|
|
||||||
|
|
||||||
my $self = bless({args => \%args}, $class);
|
my $self = bless({args => \%args}, $class);
|
||||||
|
|
||||||
my (@commands) = qw(ehlo helo rset mail rcpt data help vrfy noop quit);
|
|
||||||
my (%commands);
|
|
||||||
@commands{@commands} = ('') x @commands;
|
|
||||||
|
|
||||||
# this list of valid commands should probably be a method or a set of methods
|
# this list of valid commands should probably be a method or a set of methods
|
||||||
$self->{_commands} = \%commands;
|
$self->{_commands} = {
|
||||||
|
map { $_ => '' } qw(ehlo helo rset mail rcpt data help vrfy noop quit)
|
||||||
|
};
|
||||||
|
|
||||||
$self->SUPER::_restart(%args) if $args{restart}; # calls Qpsmtpd::_restart()
|
$self->SUPER::_restart(%args) if $args{restart}; # calls Qpsmtpd::_restart()
|
||||||
$self;
|
$self;
|
||||||
}
|
}
|
||||||
|
19
t/misc.t
19
t/misc.t
@ -1,4 +1,4 @@
|
|||||||
use Test::More tests => 14;
|
use Test::More tests => 10;
|
||||||
use Test::Output;
|
use Test::Output;
|
||||||
use strict;
|
use strict;
|
||||||
use lib 't';
|
use lib 't';
|
||||||
@ -6,23 +6,6 @@ use_ok('Test::Qpsmtpd');
|
|||||||
|
|
||||||
ok(my ($smtpd, $conn) = Test::Qpsmtpd->new_conn(), "get new connection");
|
ok(my ($smtpd, $conn) = Test::Qpsmtpd->new_conn(), "get new connection");
|
||||||
|
|
||||||
# fault method
|
|
||||||
{
|
|
||||||
my $fault;
|
|
||||||
stderr_like { $fault = $smtpd->fault }
|
|
||||||
qr/program fault - command not performed.*Last system error:/ms,
|
|
||||||
'fault outputs proper warning to STDOUT';
|
|
||||||
is($fault->[0], 451, 'fault returns 451');
|
|
||||||
};
|
|
||||||
{
|
|
||||||
my $fault;
|
|
||||||
stderr_like { $fault = $smtpd->fault('test message') }
|
|
||||||
qr/test message.*Last system error/ms,
|
|
||||||
'fault outputs proper custom warning to STDOUT';
|
|
||||||
is($fault->[1], 'Internal error - try again later - test message',
|
|
||||||
'returns the input message');
|
|
||||||
};
|
|
||||||
|
|
||||||
# vrfy command
|
# vrfy command
|
||||||
is(($smtpd->command('VRFY <foo@bar>'))[0], 252, 'VRFY command');
|
is(($smtpd->command('VRFY <foo@bar>'))[0], 252, 'VRFY command');
|
||||||
|
|
||||||
|
@ -65,11 +65,11 @@ sub test_invalid_localhost {
|
|||||||
foreach my $ip ( undef, '', '192.0.99.5' ) {
|
foreach my $ip ( undef, '', '192.0.99.5' ) {
|
||||||
$self->qp->connection->remote_ip(undef);
|
$self->qp->connection->remote_ip(undef);
|
||||||
($err, $why) = $self->invalid_localhost('localhost' );
|
($err, $why) = $self->invalid_localhost('localhost' );
|
||||||
ok(!$err, "host: localhost, remote ip: $ip");
|
ok(!$err, "host: localhost, invalid remote ip");
|
||||||
|
|
||||||
$self->qp->connection->remote_ip(undef);
|
$self->qp->connection->remote_ip(undef);
|
||||||
($err, $why) = $self->invalid_localhost('not-localhost');
|
($err, $why) = $self->invalid_localhost('not-localhost');
|
||||||
ok($err, "host: not-localhost, remote ip: $ip");
|
ok($err, "host: not-localhost, invalid remote ip");
|
||||||
};
|
};
|
||||||
|
|
||||||
foreach my $ip (qw/ ::1 127.0.0.1 / ) {
|
foreach my $ip (qw/ ::1 127.0.0.1 / ) {
|
||||||
|
45
t/qpsmtpd-smtp.t
Normal file
45
t/qpsmtpd-smtp.t
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
#!/usr/bin/perl
|
||||||
|
use strict;
|
||||||
|
use warnings;
|
||||||
|
|
||||||
|
use Data::Dumper;
|
||||||
|
use Test::More;
|
||||||
|
use Test::Output;
|
||||||
|
|
||||||
|
use lib 't';
|
||||||
|
use lib 'lib'; # test lib/Qpsmtpd/SMTP (vs site_perl)
|
||||||
|
|
||||||
|
use_ok('Test::Qpsmtpd');
|
||||||
|
use_ok('Qpsmtpd::SMTP');
|
||||||
|
|
||||||
|
ok(my $smtp = Qpsmtpd::SMTP->new(), "new smtp");
|
||||||
|
ok(my ($smtpd, $conn) = Test::Qpsmtpd->new_conn(), "get new connection");
|
||||||
|
|
||||||
|
__new();
|
||||||
|
__fault();
|
||||||
|
|
||||||
|
done_testing();
|
||||||
|
|
||||||
|
sub __new {
|
||||||
|
isa_ok( $smtp, 'Qpsmtpd::SMTP' );
|
||||||
|
|
||||||
|
ok( $smtp->{_commands}, "valid commands populated");
|
||||||
|
$smtp = Qpsmtpd::SMTP->new( key => 'val' );
|
||||||
|
cmp_ok( $smtp->{args}{key}, 'eq', 'val', "new with args");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
sub __fault {
|
||||||
|
|
||||||
|
my $fault;
|
||||||
|
stderr_like { $fault = $smtpd->fault }
|
||||||
|
qr/program fault - command not performed.*Last system error:/ms,
|
||||||
|
'fault outputs proper warning to STDOUT';
|
||||||
|
is($fault->[0], 451, 'fault returns 451');
|
||||||
|
|
||||||
|
stderr_like { $fault = $smtpd->fault('test message') }
|
||||||
|
qr/test message.*Last system error/ms,
|
||||||
|
'fault outputs proper custom warning to STDOUT';
|
||||||
|
is($fault->[1], 'Internal error - try again later - test message',
|
||||||
|
'returns the input message');
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user