Mercurial > hg > nginx-tests
changeset 26:0880e0fafde4
Tests: implement smtp test backend and use it.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Thu, 02 Oct 2008 16:18:11 +0400 |
parents | fbda19df2fc4 |
children | fb94a224fef2 |
files | README lib/Test/Nginx/SMTP.pm smtp-greeting-delay.t smtp.t |
diffstat | 4 files changed, 51 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/README Tue Sep 30 22:58:25 2008 +0400 +++ b/README Thu Oct 02 16:18:11 2008 +0400 @@ -3,10 +3,14 @@ Use prove to run tests as one usually do for perl tests. Individual tests may be run as well. +Tests assume that nginx sources are in directory nginx at the same level +as directory with tests, and nginx was already configured and built (i.e. +nginx binary available as ../nginx/objs/nginx from test directory). + Note: some tests may fail since they are for bugs not fixed in public code. Note: tests run nginx listening on localhost, and currently this includes -following ports: 8080, 10025. +following ports: 8025, 8026, 8080, 8081. Currently each test creates it's own temporary directory and uses it for logs etc. One may instruct tests not to remove the temp directory (e.g.
--- a/lib/Test/Nginx/SMTP.pm Tue Sep 30 22:58:25 2008 +0400 +++ b/lib/Test/Nginx/SMTP.pm Thu Oct 02 16:18:11 2008 +0400 @@ -23,7 +23,7 @@ my $self = return $class->SUPER::new( Proto => "tcp", PeerAddr => "localhost", - PeerPort => 10025, + PeerPort => 8025, @_ ) or die "Can't connect to nginx: $!\n"; @@ -70,6 +70,45 @@ ############################################################################### +sub smtp_test_daemon { + my $server = IO::Socket::INET->new( + Proto => 'tcp', + LocalPort => 8026, + Listen => 5, + Reuse => 1 + ) + or die "Can't create listening socket: $!\n"; + + while (my $client = $server->accept()) { + $client->autoflush(1); + print $client "220 fake esmtp server ready" . CRLF; + + while (<$client>) { + if (/^quit/i) { + print $client '221 quit ok' . CRLF; + } elsif (/^(ehlo|helo)/i) { + print $client '250 hello ok' . CRLF; + } elsif (/^rset/i) { + print $client '250 rset ok' . CRLF; + } elsif (/^mail from:[^@]+$/i) { + print $client '500 mail from error' . CRLF; + } elsif (/^mail from:/i) { + print $client '250 mail from ok' . CRLF; + } elsif (/^rcpt to:[^@]+$/i) { + print $client '500 rcpt to error' . CRLF; + } elsif (/^rcpt to:/i) { + print $client '250 rcpt to ok' . CRLF; + } else { + print $client "500 unknown command" . CRLF; + } + } + + close $client; + } +} + +############################################################################### + 1; ###############################################################################
--- a/smtp-greeting-delay.t Tue Sep 30 22:58:25 2008 +0400 +++ b/smtp-greeting-delay.t Thu Oct 02 16:18:11 2008 +0400 @@ -38,7 +38,7 @@ xclient off; server { - listen localhost:10025; + listen localhost:8025; protocol smtp; smtp_greeting_delay 100ms; }
--- a/smtp.t Tue Sep 30 22:58:25 2008 +0400 +++ b/smtp.t Thu Oct 02 16:18:11 2008 +0400 @@ -25,7 +25,9 @@ select STDERR; $| = 1; select STDOUT; $| = 1; -my $t = Test::Nginx->new()->write_file_expand('nginx.conf', <<'EOF')->run(); +my $t = Test::Nginx->new() + ->run_daemon(\&Test::Nginx::SMTP::smtp_test_daemon) + ->write_file_expand('nginx.conf', <<'EOF')->run(); master_process off; daemon off; @@ -40,7 +42,7 @@ xclient off; server { - listen localhost:10025; + listen localhost:8025; protocol smtp; smtp_auth login plain none; } @@ -65,7 +67,7 @@ add_header Auth-Status $reply; add_header Auth-Server 127.0.0.1; - add_header Auth-Port 25; + add_header Auth-Port 8026; add_header Auth-Wait 1; return 204; }