Mercurial > hg > nginx-tests
comparison mail_proxy_protocol.t @ 1659:d1c4059e1e72
Tests: smtp tests with proxy protocol and realip.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Thu, 04 Mar 2021 14:45:40 +0300 |
parents | |
children | 068c30e9d2c6 |
comparison
equal
deleted
inserted
replaced
1658:3b8a9f02d141 | 1659:d1c4059e1e72 |
---|---|
1 #!/usr/bin/perl | |
2 | |
3 # (C) Sergey Kandaurov | |
4 # (C) Nginx, Inc. | |
5 | |
6 # Tests for mail proxy module, PROXY protocol with realip. | |
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; | |
45 | |
46 server { | |
47 listen 127.0.0.1:8025 proxy_protocol; | |
48 protocol smtp; | |
49 | |
50 auth_http_header X-Type proxy; | |
51 } | |
52 | |
53 server { | |
54 listen 127.0.0.1:8027 proxy_protocol; | |
55 protocol smtp; | |
56 | |
57 set_real_ip_from 127.0.0.1/32; | |
58 auth_http_header X-Type realip; | |
59 } | |
60 } | |
61 | |
62 http { | |
63 %%TEST_GLOBALS_HTTP%% | |
64 | |
65 server { | |
66 listen 127.0.0.1:8080; | |
67 server_name localhost; | |
68 | |
69 location = /mail/auth { | |
70 set $reply ERROR; | |
71 set $test $http_x_type:$http_client_ip:$http_proxy_protocol_addr; | |
72 | |
73 if ($test = proxy:127.0.0.1:192.0.2.1) { | |
74 set $reply OK; | |
75 } | |
76 | |
77 if ($test = realip:192.0.2.1:192.0.2.1) { | |
78 set $reply OK; | |
79 } | |
80 | |
81 add_header Auth-Status $reply; | |
82 add_header Auth-Server 127.0.0.1; | |
83 add_header Auth-Port %%PORT_8026%%; | |
84 add_header Auth-Wait 1; | |
85 return 204; | |
86 } | |
87 } | |
88 } | |
89 | |
90 EOF | |
91 | |
92 $t->run_daemon(\&Test::Nginx::SMTP::smtp_test_daemon); | |
93 $t->try_run('no proxy_protocol')->plan(6); | |
94 | |
95 $t->waitforsocket('127.0.0.1:' . port(8026)); | |
96 | |
97 ############################################################################### | |
98 | |
99 # connection with PROXY protocol | |
100 | |
101 my $s = Test::Nginx::SMTP->new(PeerAddr => '127.0.0.1:' . port(8025)); | |
102 $s->send('PROXY TCP4 192.0.2.1 192.0.2.2 123 5678'); | |
103 $s->check(qr/^220 /, "greeting with proxy_protocol"); | |
104 | |
105 $s->send('EHLO example.com'); | |
106 $s->check(qr/^250 /, "ehlo with proxy_protocol"); | |
107 | |
108 $s->send('AUTH PLAIN ' . encode_base64("\0test\@example.com\0secret", '')); | |
109 $s->authok('auth with proxy_protocol'); | |
110 | |
111 # connection with PROXY protocol and set_realip_from | |
112 | |
113 $s = Test::Nginx::SMTP->new(PeerAddr => '127.0.0.1:' . port(8027)); | |
114 | |
115 $s->send('PROXY TCP4 192.0.2.1 192.0.2.2 123 5678'); | |
116 $s->check(qr/^220 /, "greeting with proxy_protocol and realip"); | |
117 | |
118 $s->send('EHLO example.com'); | |
119 $s->check(qr/^250 /, "ehlo with proxy_protocol and realip"); | |
120 | |
121 $s->send('AUTH PLAIN ' . encode_base64("\0test\@example.com\0secret", '')); | |
122 $s->authok('auth with proxy_protocol and realip'); | |
123 | |
124 ############################################################################### |