Mercurial > hg > nginx-tests
comparison lib/Test/Nginx/SMTP.pm @ 1660:068c30e9d2c6
Tests: smtp tests with proxy protocol to backend.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Fri, 05 Mar 2021 19:18:52 +0300 |
parents | 4e0644119341 |
children | d0025a0dead7 |
comparison
equal
deleted
inserted
replaced
1659:d1c4059e1e72 | 1660:068c30e9d2c6 |
---|---|
98 | 98 |
99 ############################################################################### | 99 ############################################################################### |
100 | 100 |
101 sub smtp_test_daemon { | 101 sub smtp_test_daemon { |
102 my ($port) = @_; | 102 my ($port) = @_; |
103 my $proxy_protocol; | |
103 | 104 |
104 my $server = IO::Socket::INET->new( | 105 my $server = IO::Socket::INET->new( |
105 Proto => 'tcp', | 106 Proto => 'tcp', |
106 LocalAddr => '127.0.0.1:' . ($port || port(8026)), | 107 LocalAddr => '127.0.0.1:' . ($port || port(8026)), |
107 Listen => 5, | 108 Listen => 5, |
110 or die "Can't create listening socket: $!\n"; | 111 or die "Can't create listening socket: $!\n"; |
111 | 112 |
112 while (my $client = $server->accept()) { | 113 while (my $client = $server->accept()) { |
113 $client->autoflush(1); | 114 $client->autoflush(1); |
114 print $client "220 fake esmtp server ready" . CRLF; | 115 print $client "220 fake esmtp server ready" . CRLF; |
116 | |
117 $proxy_protocol = ''; | |
115 | 118 |
116 while (<$client>) { | 119 while (<$client>) { |
117 Test::Nginx::log_core('||', $_); | 120 Test::Nginx::log_core('||', $_); |
118 | 121 |
119 if (/^quit/i) { | 122 if (/^quit/i) { |
132 print $client '500 rcpt to error' . CRLF; | 135 print $client '500 rcpt to error' . CRLF; |
133 } elsif (/^rcpt to:/i) { | 136 } elsif (/^rcpt to:/i) { |
134 print $client '250 rcpt to ok' . CRLF; | 137 print $client '250 rcpt to ok' . CRLF; |
135 } elsif (/^xclient/i) { | 138 } elsif (/^xclient/i) { |
136 print $client '220 xclient ok' . CRLF; | 139 print $client '220 xclient ok' . CRLF; |
140 } elsif (/^proxy/i) { | |
141 $proxy_protocol = $_; | |
142 } elsif (/^xproxy/i) { | |
143 print $client '211 ' . $proxy_protocol . CRLF; | |
137 } else { | 144 } else { |
138 print $client "500 unknown command" . CRLF; | 145 print $client "500 unknown command" . CRLF; |
139 } | 146 } |
140 } | 147 } |
141 | 148 |