comparison smtp.t @ 17:7e28c64edf55

Tests: reorganize smtp tests (no real changes). Move smtp_greeting_delay tests into separate test file. Embed config into tests.
author Maxim Dounin <mdounin@mdounin.ru>
date Sat, 13 Sep 2008 03:37:45 +0400
parents d4b74207a627
children 0880e0fafde4
comparison
equal deleted inserted replaced
16:dc0f15a3a140 17:7e28c64edf55
7 ############################################################################### 7 ###############################################################################
8 8
9 use warnings; 9 use warnings;
10 use strict; 10 use strict;
11 11
12 use Test::More tests => 28; 12 use Test::More tests => 26;
13 13
14 use MIME::Base64; 14 use MIME::Base64;
15 use Socket qw/ CRLF /; 15 use Socket qw/ CRLF /;
16 16
17 BEGIN { use FindBin; chdir($FindBin::Bin); } 17 BEGIN { use FindBin; chdir($FindBin::Bin); }
23 ############################################################################### 23 ###############################################################################
24 24
25 select STDERR; $| = 1; 25 select STDERR; $| = 1;
26 select STDOUT; $| = 1; 26 select STDOUT; $| = 1;
27 27
28 my $t = Test::Nginx->new()->run('smtp.conf'); 28 my $t = Test::Nginx->new()->write_file_expand('nginx.conf', <<'EOF')->run();
29
30 master_process off;
31 daemon off;
32
33 events {
34 worker_connections 1024;
35 }
36
37 mail {
38 proxy_pass_error_message on;
39 auth_http http://localhost:8080/mail/auth;
40 xclient off;
41
42 server {
43 listen localhost:10025;
44 protocol smtp;
45 smtp_auth login plain none;
46 }
47 }
48
49 http {
50 access_log off;
51
52 server {
53 listen localhost:8080;
54 server_name localhost;
55
56 location = /mail/auth {
57 set $reply ERROR;
58
59 if ($http_auth_smtp_to ~ example.com) {
60 set $reply OK;
61 }
62 if ($http_auth_pass ~ secret) {
63 set $reply OK;
64 }
65
66 add_header Auth-Status $reply;
67 add_header Auth-Server 127.0.0.1;
68 add_header Auth-Port 25;
69 add_header Auth-Wait 1;
70 return 204;
71 }
72 }
73 }
74
75 EOF
29 76
30 ############################################################################### 77 ###############################################################################
31 78
32 my $s = Test::Nginx::SMTP->new(); 79 my $s = Test::Nginx::SMTP->new();
33 $s->check(qr/^220 /, "greeting"); 80 $s->check(qr/^220 /, "greeting");
139 log_out('HEL'); 186 log_out('HEL');
140 $s->print('HEL'); 187 $s->print('HEL');
141 $s->send('O example.com'); 188 $s->send('O example.com');
142 $s->ok('splitted command'); 189 $s->ok('splitted command');
143 190
144 # With smtp_greeting_delay session expected to be closed after first error
145 # message if client sent something before greeting. Use 10026 port
146 # configured with smtp_greeting_delay 0.1s to check this.
147
148 $s = Test::Nginx::SMTP->new(PeerPort => 10026);
149 $s->send('HELO example.com');
150 $s->check(qr/^5.. /, "command before greeting - session must be rejected");
151 ok($s->eof(), "session have to be closed");
152
153 ############################################################################### 191 ###############################################################################