# HG changeset patch # User Maxim Dounin # Date 1220469989 -14400 # Node ID 6c41dbb2954f2fd30c221270ab445af9f17735eb # Parent ce002b2323d3475ae24e925252f42d81be32380c Tests: run nginx with appropriate config from test itself. diff --git a/smtp.conf b/smtp.conf new file mode 100644 --- /dev/null +++ b/smtp.conf @@ -0,0 +1,54 @@ +# Config for smtp.t tests. + +worker_processes 1; + +master_process off; +daemon off; + +events { + worker_connections 1024; +} + +mail { + proxy_pass_error_message on; + auth_http http://localhost:8080/mail/auth; + xclient off; + + server { + listen 10025; + protocol smtp; + smtp_auth login plain none; + } + + server { + listen 10026; + protocol smtp; + smtp_greeting_delay 100ms; + } +} + +http { + access_log off; + + server { + listen 8080; + server_name localhost; + + location = /mail/auth { + set $reply ERROR; + + if ($http_auth_smtp_to ~ example.com) { + set $reply OK; + } + if ($http_auth_pass ~ secret) { + set $reply OK; + } + + add_header Auth-Status $reply; + add_header Auth-Server 127.0.0.1; + add_header Auth-Port 25; + add_header Auth-Wait 1; + return 204; + } + } +} diff --git a/smtp.t b/smtp.t --- a/smtp.t +++ b/smtp.t @@ -9,8 +9,9 @@ use warnings; use strict; -use Test::More tests => 26; +use Test::More tests => 28; +use File::Temp qw/ tempdir /; use IO::Socket; use MIME::Base64; @@ -19,6 +20,35 @@ use constant CRLF => "\x0D\x0A"; select STDERR; $| = 1; select STDOUT; $| = 1; +############################################################################### + +# Create temp directory and run nginx instance. + +my $tempdir = tempdir('nginx-test-XXXXXXXXXX', TMPDIR => 1, CLEANUP => 1) + or die "Can't create temp directory: $!\n"; + +my $pid = fork(); +die "Unable to fork(): $!\n" unless defined $pid; + +if ($pid == 0) { + exec('../nginx/objs/nginx', '-c', 'smtp.conf', '-g', + "pid $tempdir/nginx.pid; error_log $tempdir/nginx-error.log info;") + or die "Unable to exec(): $!\n"; + print "# child after exec - not reached\n"; +} + +END { + # terminate nginx by SIGTERM + kill 15, $pid; + wait; +} + +# Give nginx some time to start. + +sleep 1; + +############################################################################### + my $s = smtp_connect(); smtp_check(qr/^220 /, "greeting");