Tests: smtp tests with proxy protocol to backend.
diff --git a/lib/Test/Nginx/SMTP.pm b/lib/Test/Nginx/SMTP.pm
index 8df56b5..f1098c4 100644
--- a/lib/Test/Nginx/SMTP.pm
+++ b/lib/Test/Nginx/SMTP.pm
@@ -100,6 +100,7 @@
sub smtp_test_daemon {
my ($port) = @_;
+ my $proxy_protocol;
my $server = IO::Socket::INET->new(
Proto => 'tcp',
@@ -113,6 +114,8 @@
$client->autoflush(1);
print $client "220 fake esmtp server ready" . CRLF;
+ $proxy_protocol = '';
+
while (<$client>) {
Test::Nginx::log_core('||', $_);
@@ -134,6 +137,10 @@
print $client '250 rcpt to ok' . CRLF;
} elsif (/^xclient/i) {
print $client '220 xclient ok' . CRLF;
+ } elsif (/^proxy/i) {
+ $proxy_protocol = $_;
+ } elsif (/^xproxy/i) {
+ print $client '211 ' . $proxy_protocol . CRLF;
} else {
print $client "500 unknown command" . CRLF;
}
diff --git a/mail_proxy_protocol.t b/mail_proxy_protocol.t
index 721fc29..73cd720 100644
--- a/mail_proxy_protocol.t
+++ b/mail_proxy_protocol.t
@@ -40,6 +40,7 @@
mail {
proxy_pass_error_message on;
proxy_smtp_auth on;
+ proxy_protocol on;
auth_http http://127.0.0.1:8080/mail/auth;
smtp_auth login plain;
@@ -90,7 +91,7 @@
EOF
$t->run_daemon(\&Test::Nginx::SMTP::smtp_test_daemon);
-$t->try_run('no proxy_protocol')->plan(6);
+$t->try_run('no proxy_protocol')->plan(8);
$t->waitforsocket('127.0.0.1:' . port(8026));
@@ -108,6 +109,10 @@
$s->send('AUTH PLAIN ' . encode_base64("\0test\@example.com\0secret", ''));
$s->authok('auth with proxy_protocol');
+$s->send('XPROXY');
+$s->check(qr/^211 PROXY TCP4 127.0.0.1 127.0.0.1 \d+ \d+/,
+ 'proxy protocol to backend');
+
# connection with PROXY protocol and set_realip_from
$s = Test::Nginx::SMTP->new(PeerAddr => '127.0.0.1:' . port(8027));
@@ -121,4 +126,8 @@
$s->send('AUTH PLAIN ' . encode_base64("\0test\@example.com\0secret", ''));
$s->authok('auth with proxy_protocol and realip');
+$s->send('XPROXY');
+$s->check(qr/^211 PROXY TCP4 192.0.2.1 127.0.0.1 \d+ \d+/,
+ 'proxy_protocol to backend and realip');
+
###############################################################################