comparison smtp-xclient.t @ 68:5f56040c39df

Tests: smtp xclient tests.
author Maxim Dounin <mdounin@mdounin.ru>
date Tue, 03 Feb 2009 09:27:08 +0300
parents
children ecff5407867c
comparison
equal deleted inserted replaced
67:5d16f380cd75 68:5f56040c39df
1 #!/usr/bin/perl
2
3 # (C) Maxim Dounin
4
5 ###############################################################################
6
7 use warnings;
8 use strict;
9
10 use Test::More;
11
12 use MIME::Base64;
13 use Socket qw/ CRLF /;
14
15 BEGIN { use FindBin; chdir($FindBin::Bin); }
16
17 use lib 'lib';
18 use Test::Nginx;
19 use Test::Nginx::SMTP;
20
21 ###############################################################################
22
23 select STDERR; $| = 1;
24 select STDOUT; $| = 1;
25
26 my $t = Test::Nginx->new()->has('mail')->plan(6)
27 ->run_daemon(\&Test::Nginx::SMTP::smtp_test_daemon)
28 ->write_file_expand('nginx.conf', <<'EOF')->run();
29
30 master_process off;
31 daemon off;
32
33 events {
34 }
35
36 mail {
37 proxy_pass_error_message on;
38 auth_http http://127.0.0.1:8080/mail/auth;
39 xclient on;
40
41 server {
42 listen 127.0.0.1:8025;
43 protocol smtp;
44 smtp_auth login plain none;
45 }
46 }
47
48 http {
49 access_log off;
50
51 client_body_temp_path %%TESTDIR%%/client_body_temp;
52 fastcgi_temp_path %%TESTDIR%%/fastcgi_temp;
53 proxy_temp_path %%TESTDIR%%/proxy_temp;
54
55 server {
56 listen 127.0.0.1:8080;
57 server_name localhost;
58
59 location = /mail/auth {
60 add_header Auth-Status OK;
61 add_header Auth-Server 127.0.0.1;
62 add_header Auth-Port 8026;
63 add_header Auth-Wait 1;
64 return 204;
65 }
66 }
67 }
68
69 EOF
70
71 ###############################################################################
72
73 # When XCLIENT's HELO= argument isn't used, the following combinations may be
74 # send to backend with xclient on:
75 #
76 # xclient
77 # xclient, helo
78 # xclient, ehlo
79 # xclient, from, rcpt
80 # xclient, helo, from, rcpt
81 # xclient, ehlo, from, rcpt
82 #
83 # Test them in order.
84
85 # xclient
86
87 my $s = Test::Nginx::SMTP->new();
88 $s->read();
89 $s->send('AUTH PLAIN ' . encode_base64("\0test\@example.com\0secret", ''));
90 $s->authok('xclient');
91
92 # xclient, helo
93
94 $s = Test::Nginx::SMTP->new();
95 $s->read();
96 $s->send('HELO example.com');
97 $s->read();
98 $s->send('AUTH PLAIN ' . encode_base64("\0test\@example.com\0secret", ''));
99 $s->authok('xclient, helo');
100
101 # xclient, ehlo
102
103 $s = Test::Nginx::SMTP->new();
104 $s->read();
105 $s->send('EHLO example.com');
106 $s->read();
107 $s->send('AUTH PLAIN ' . encode_base64("\0test\@example.com\0secret", ''));
108 $s->authok('xclient, ehlo');
109
110 # xclient, from, rcpt
111
112 $s = Test::Nginx::SMTP->new();
113 $s->read();
114 $s->send('MAIL FROM:<test@example.com>');
115 $s->read();
116 $s->send('RCPT TO:<test@example.com>');
117 $s->ok('xclient, from');
118
119 # xclient, helo, from, rcpt
120
121 $s = Test::Nginx::SMTP->new();
122 $s->read();
123 $s->send('HELO example.com');
124 $s->read();
125 $s->send('MAIL FROM:<test@example.com>');
126 $s->read();
127 $s->send('RCPT TO:<test@example.com>');
128 $s->ok('xclient, helo, from');
129
130 # xclient, ehlo, from, rcpt
131
132 $s = Test::Nginx::SMTP->new();
133 $s->read();
134 $s->send('EHLO example.com');
135 $s->read();
136 $s->send('MAIL FROM:<test@example.com>');
137 $s->read();
138 $s->send('RCPT TO:<test@example.com>');
139 $s->ok('xclient, ehlo, from');
140
141 ###############################################################################