From 9c1e62371b809e1c6e9e43167a8f8c50b94d6527 Mon Sep 17 00:00:00 2001 From: Matt Simerson Date: Sat, 2 Jun 2012 22:56:05 -0400 Subject: [PATCH] added new t/config directory, with developer tests run when $ENV{QPSMTPD_DEVELOPER} is set plugins file is same as in config.sample, but with more stuff enabled --- config.sample/flat_auth_pw | 1 + t/Test/Qpsmtpd.pm | 1 + t/config.t | 15 ++++-- t/config/badhelo | 4 ++ t/config/badrcptto | 9 ++++ t/config/dnsbl_zones | 1 + t/config/flat_auth_pw | 2 + t/config/plugins | 94 ++++++++++++++++++++++++++++++++++++++ t/config/rcpthosts | 1 + t/config/relayclients | 5 ++ t/plugin_tests.t | 8 ++++ 11 files changed, 137 insertions(+), 4 deletions(-) create mode 100644 t/config/badhelo create mode 100644 t/config/badrcptto create mode 100644 t/config/dnsbl_zones create mode 100644 t/config/flat_auth_pw create mode 100644 t/config/plugins create mode 100644 t/config/rcpthosts create mode 100644 t/config/relayclients diff --git a/config.sample/flat_auth_pw b/config.sample/flat_auth_pw index 292d9f5..cdae7f7 100644 --- a/config.sample/flat_auth_pw +++ b/config.sample/flat_auth_pw @@ -1,2 +1,3 @@ +# example entries good@example.com:good_pass bad@example.com:bad_pass diff --git a/t/Test/Qpsmtpd.pm b/t/Test/Qpsmtpd.pm index 83805df..48041ee 100644 --- a/t/Test/Qpsmtpd.pm +++ b/t/Test/Qpsmtpd.pm @@ -69,6 +69,7 @@ sub input { } sub config_dir { + return './t/config' if $ENV{QPSMTPD_DEVELOPER}; './config.sample'; } diff --git a/t/config.t b/t/config.t index f134e7a..8b6b11e 100644 --- a/t/config.t +++ b/t/config.t @@ -5,12 +5,17 @@ use strict; use lib 't'; use_ok('Test::Qpsmtpd'); +my @mes; + BEGIN { # need this to happen before anything else my $cwd = `pwd`; chomp($cwd); - open my $me_config, '>', "./config.sample/me"; - print $me_config "some.host.example.org"; - close $me_config; + @mes = qw{ ./config.sample/me ./t/config/me }; + foreach my $f ( @mes ) { + open my $me_config, '>', $f; + print $me_config "some.host.example.org"; + close $me_config; + }; } ok(my ($smtpd, $conn) = Test::Qpsmtpd->new_conn(), "get new connection"); @@ -22,6 +27,8 @@ is($smtpd->config('me'), 'some.host.example.org', 'config("me")'); my $relayclients = join ",", sort $smtpd->config('relayclients'); is($relayclients, '127.0.0.1,192.0.', 'config("relayclients") are trimmed'); -unlink "./config.sample/me"; +foreach my $f ( @mes ) { + unlink $f if -f $f; +}; diff --git a/t/config/badhelo b/t/config/badhelo new file mode 100644 index 0000000..a13ebfa --- /dev/null +++ b/t/config/badhelo @@ -0,0 +1,4 @@ +# these domains never uses their domain when greeting us, so reject transactions +aol.com +yahoo.com + diff --git a/t/config/badrcptto b/t/config/badrcptto new file mode 100644 index 0000000..a7f88ca --- /dev/null +++ b/t/config/badrcptto @@ -0,0 +1,9 @@ +######## entries used for testing ### +bad@example.com +@bad.example.com +######## Example patterns ####### +# Format is pattern\s+Response +# Don't forget to anchor the pattern if required +! Sorry, bang paths not accepted here +@.*@ Sorry, multiple at signs not accepted here +% Sorry, percent hack not accepted here diff --git a/t/config/dnsbl_zones b/t/config/dnsbl_zones new file mode 100644 index 0000000..1053328 --- /dev/null +++ b/t/config/dnsbl_zones @@ -0,0 +1 @@ +zen.spamhaus.org diff --git a/t/config/flat_auth_pw b/t/config/flat_auth_pw new file mode 100644 index 0000000..292d9f5 --- /dev/null +++ b/t/config/flat_auth_pw @@ -0,0 +1,2 @@ +good@example.com:good_pass +bad@example.com:bad_pass diff --git a/t/config/plugins b/t/config/plugins new file mode 100644 index 0000000..4a18615 --- /dev/null +++ b/t/config/plugins @@ -0,0 +1,94 @@ +# +# Example configuration file for plugins +# + +# enable this to get configuration via http; see perldoc +# plugins/http_config for details. +# http_config http://localhost/~smtpd/config/ http://www.example.com/smtp.pl?config= + +# hosts_allow does not work with the tcpserver deployment model! +# perldoc plugins/hosts_allow for an alternative. +# +# The hosts_allow module must be loaded if you want the -m / --max-from-ip / +# my $MAXCONNIP = 5; # max simultaneous connections from one IP +# settings... without this it will NOT refuse more than $MAXCONNIP connections +# from one IP! +hosts_allow + +# information plugins +ident/geoip +#ident/p0f /tmp/.p0f_socket version 3 +connection_time + +# enable to accept MAIL FROM:/RCPT TO: addresses without surrounding <> +dont_require_anglebrackets + +# enable to reject MAIL FROM:/RCPT TO: parameters if client helo was HELO +# (strict RFC 821)... this is not used in EHLO ... +parse_addr_withhelo + +quit_fortune +# tls should load before count_unrecognized_commands +#tls +check_earlytalker +count_unrecognized_commands 4 +check_relay + +require_resolvable_fromhost + +rhsbl +dnsbl +check_badmailfrom +check_badrcptto +check_spamhelo + +sender_permitted_from +greylisting p0f genre,windows + +auth/auth_checkpassword checkpw /usr/local/vpopmail/bin/vchkpw true /usr/bin/true +auth/auth_vpopmail +auth/auth_vpopmaild +auth/auth_vpopmail_sql +auth/auth_flat_file +auth/authdeny + +# this plugin needs to run after all other "rcpt" plugins +rcpt_ok + +check_basicheaders days 5 reject_type temp +domainkeys + +# content filters +virus/klez_filter + + +# You can run the spamassassin plugin with options. See perldoc +# plugins/spamassassin for details. +# +spamassassin + +# rejects mails with a SA score higher than 20 and munges the subject +# of the score is higher than 10. +# +# spamassassin reject_threshold 20 munge_subject_threshold 10 + +# dspam must run after spamassassin for the learn_from_sa feature to work +dspam learn_from_sa 7 reject 1 + +# run the clamav virus checking plugin +virus/clamav + +# You must enable a queue plugin - see the options in plugins/queue/ - for example: + +# queue to a maildir +# queue/maildir /home/spamtrap/mail + +# queue the mail with qmail-queue +queue/qmail-queue + + +# If you need to run the same plugin multiple times, you can do +# something like the following +# check_relay +# check_relay:0 somearg +# check_relay:1 someotherarg diff --git a/t/config/rcpthosts b/t/config/rcpthosts new file mode 100644 index 0000000..2fbb50c --- /dev/null +++ b/t/config/rcpthosts @@ -0,0 +1 @@ +localhost diff --git a/t/config/relayclients b/t/config/relayclients new file mode 100644 index 0000000..5bbb91d --- /dev/null +++ b/t/config/relayclients @@ -0,0 +1,5 @@ +# Format is IP, or IP part with trailing dot +# e.g. "127.0.0.1", or "192.168." +127.0.0.1 +# leading/trailing whitespace is ignored + 192.168. diff --git a/t/plugin_tests.t b/t/plugin_tests.t index e1f3050..69344c1 100644 --- a/t/plugin_tests.t +++ b/t/plugin_tests.t @@ -7,3 +7,11 @@ my $qp = Test::Qpsmtpd->new(); $qp->run_plugin_tests(); +foreach my $file ( + "./t/config/greylist.dbm", + "./t/config/greylist.dbm.lock" + ) { + next if ! -f $file; + unlink $file; +}; +