comparison mail_proxy_smtp_auth.t @ 1599:4e0644119341

Tests: proxy_smtp_auth directive tests.
author Sergey Kandaurov <pluknet@nginx.com>
date Tue, 06 Oct 2020 20:52:06 +0100
parents
children 74986ebee2fd
comparison
equal deleted inserted replaced
1598:f069dd7ba5a7 1599:4e0644119341
1 #!/usr/bin/perl
2
3 # (C) Sergey Kandaurov
4 # (C) Nginx, Inc.
5
6 # Tests for nginx mail proxy module, the proxy_smtp_auth directive.
7
8 ###############################################################################
9
10 use warnings;
11 use strict;
12
13 use Test::More;
14
15 use MIME::Base64;
16
17 BEGIN { use FindBin; chdir($FindBin::Bin); }
18
19 use lib 'lib';
20 use Test::Nginx;
21 use Test::Nginx::SMTP;
22
23 ###############################################################################
24
25 select STDERR; $| = 1;
26 select STDOUT; $| = 1;
27
28 local $SIG{PIPE} = 'IGNORE';
29
30 my $t = Test::Nginx->new()->has(qw/mail smtp http rewrite/)
31 ->write_file_expand('nginx.conf', <<'EOF');
32
33 %%TEST_GLOBALS%%
34
35 daemon off;
36
37 events {
38 }
39
40 mail {
41 proxy_pass_error_message on;
42 proxy_smtp_auth on;
43 auth_http http://127.0.0.1:8080/mail/auth;
44 smtp_auth login plain external;
45
46 server {
47 listen 127.0.0.1:8025;
48 protocol smtp;
49 }
50
51 server {
52 listen 127.0.0.1:8027;
53 protocol smtp;
54 xclient off;
55 }
56 }
57
58 http {
59 %%TEST_GLOBALS_HTTP%%
60
61 server {
62 listen 127.0.0.1:8080;
63 server_name localhost;
64
65 location = /mail/auth {
66 add_header Auth-Status OK;
67 add_header Auth-Server 127.0.0.1;
68 add_header Auth-Port %%PORT_8026%%;
69 add_header Auth-Wait 1;
70 return 204;
71 }
72 }
73 }
74
75 EOF
76
77 $t->run_daemon(\&Test::Nginx::SMTP::smtp_test_daemon);
78 $t->try_run('no proxy_smtp_auth')->plan(7);
79
80 $t->waitforsocket('127.0.0.1:' . port(8026));
81
82 ###############################################################################
83
84 # The following combinations may be sent to backend with proxy_smtp_auth on:
85 #
86 # ehlo, xclient, auth
87 # ehlo, xclient, helo, auth
88 # ehlo, xclient, ehlo, auth
89 # helo, auth
90 # ehlo, auth
91 #
92 # Test them in order.
93
94 # ehlo, xclient, auth
95
96 my $s = Test::Nginx::SMTP->new();
97 $s->read();
98 $s->send('AUTH PLAIN ' . encode_base64("\0test\@example.com\0secret", ''));
99 $s->authok('ehlo, xclient, auth');
100
101 # ehlo, xclient, helo, auth
102
103 $s = Test::Nginx::SMTP->new();
104 $s->read();
105 $s->send('HELO example.com');
106 $s->read();
107 $s->send('AUTH PLAIN ' . encode_base64("\0test\@example.com\0secret", ''));
108 $s->authok('ehlo, xclient, helo, auth');
109
110 # ehlo, xclient, ehlo, auth
111
112 $s = Test::Nginx::SMTP->new();
113 $s->read();
114 $s->send('EHLO example.com');
115 $s->read();
116 $s->send('AUTH PLAIN ' . encode_base64("\0test\@example.com\0secret", ''));
117 $s->authok('ehlo, xclient, ehlo, auth');
118
119 # helo, auth
120
121 $s = Test::Nginx::SMTP->new(PeerAddr => '127.0.0.1:' . port(8027));
122 $s->read();
123 $s->send('AUTH PLAIN ' . encode_base64("\0test\@example.com\0secret", ''));
124 $s->authok('helo, auth');
125
126 # ehlo, auth
127
128 $s = Test::Nginx::SMTP->new(PeerAddr => '127.0.0.1:' . port(8027));
129 $s->read();
130 $s->send('EHLO example.com');
131 $s->read();
132 $s->send('AUTH PLAIN ' . encode_base64("\0test\@example.com\0secret", ''));
133 $s->authok('ehlo, auth');
134
135 # Try auth external
136
137 $s = Test::Nginx::SMTP->new();
138 $s->read();
139 $s->send('EHLO example.com');
140 $s->read();
141
142 $s->send('AUTH EXTERNAL');
143 $s->check(qr/^334 VXNlcm5hbWU6/, 'auth external challenge');
144 $s->send(encode_base64('test@example.com', ''));
145 $s->check(qr/^4.. /, 'auth external no password');
146
147 ###############################################################################