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