Tests: auth external mail tests.
diff --git a/mail_imap.t b/mail_imap.t
index 48fa07e..cb0e9b6 100644
--- a/mail_imap.t
+++ b/mail_imap.t
@@ -26,7 +26,7 @@
 
 local $SIG{PIPE} = 'IGNORE';
 
-my $t = Test::Nginx->new()->has(qw/mail imap http rewrite/)->plan(11)
+my $t = Test::Nginx->new()->has(qw/mail imap http rewrite/)->plan(14)
 	->write_file_expand('nginx.conf', <<'EOF');
 
 %%TEST_GLOBALS%%
@@ -73,6 +73,12 @@
                 set $passw secret;
             }
 
+            set $userpass "$http_auth_method:$http_auth_user:$http_auth_pass";
+            if ($userpass ~ '^external:test@example.com:$') {
+                set $reply OK;
+                set $passw secret;
+            }
+
             add_header Auth-Status $reply;
             add_header Auth-Server 127.0.0.1;
             add_header Auth-Port %%PORT_8144%%;
@@ -142,4 +148,28 @@
 $s->send(encode_base64('test@example.com ' . ('0' x 32), ''));
 $s->ok('auth cram-md5');
 
+TODO: {
+local $TODO = 'not yet' unless $t->has_version('1.11.6');
+
+# auth external
+
+$s = Test::Nginx::IMAP->new();
+$s->read();
+
+$s->send('1 AUTHENTICATE EXTERNAL');
+$s->check(qr/\+ VXNlcm5hbWU6/, 'auth external challenge');
+
+$s->send(encode_base64('test@example.com', ''));
+$s->ok('auth external');
+
+# auth external with username
+
+$s = Test::Nginx::IMAP->new();
+$s->read();
+
+$s->send('1 AUTHENTICATE EXTERNAL ' . encode_base64('test@example.com', ''));
+$s->ok('auth external with username');
+
+}
+
 ###############################################################################
diff --git a/mail_pop3.t b/mail_pop3.t
index aeecfa4..f9924b8 100644
--- a/mail_pop3.t
+++ b/mail_pop3.t
@@ -26,7 +26,7 @@
 
 local $SIG{PIPE} = 'IGNORE';
 
-my $t = Test::Nginx->new()->has(qw/mail pop3 http rewrite/)->plan(15)
+my $t = Test::Nginx->new()->has(qw/mail pop3 http rewrite/)->plan(18)
 	->write_file_expand('nginx.conf', <<'EOF');
 
 %%TEST_GLOBALS%%
@@ -73,6 +73,12 @@
                 set $passw secret;
             }
 
+            set $userpass "$http_auth_method:$http_auth_user:$http_auth_pass";
+            if ($userpass ~ '^external:test@example.com:$') {
+                set $reply OK;
+                set $passw secret;
+            }
+
             add_header Auth-Status $reply;
             add_header Auth-Server 127.0.0.1;
             add_header Auth-Port %%PORT_8111%%;
@@ -159,4 +165,28 @@
 $s->send(encode_base64('test@example.com ' . ('0' x 32), ''));
 $s->ok('auth cram-md5');
 
+TODO: {
+local $TODO = 'not yet' unless $t->has_version('1.11.6');
+
+# auth external
+
+$s = Test::Nginx::POP3->new();
+$s->read();
+
+$s->send('AUTH EXTERNAL');
+$s->check(qr/\+ VXNlcm5hbWU6/, 'auth external challenge');
+
+$s->send(encode_base64('test@example.com', ''));
+$s->ok('auth external');
+
+# auth external with username
+
+$s = Test::Nginx::POP3->new();
+$s->read();
+
+$s->send('AUTH EXTERNAL ' . encode_base64('test@example.com', ''));
+$s->ok('auth external with username');
+
+}
+
 ###############################################################################
diff --git a/mail_smtp.t b/mail_smtp.t
index 81ea0b7..b552d5f 100644
--- a/mail_smtp.t
+++ b/mail_smtp.t
@@ -27,7 +27,7 @@
 
 local $SIG{PIPE} = 'IGNORE';
 
-my $t = Test::Nginx->new()->has(qw/mail smtp http rewrite/)->plan(27)
+my $t = Test::Nginx->new()->has(qw/mail smtp http rewrite/)->plan(30)
 	->write_file_expand('nginx.conf', <<'EOF');
 
 %%TEST_GLOBALS%%
@@ -73,6 +73,11 @@
                 set $reply OK;
             }
 
+            set $userpass "$http_auth_method:$http_auth_user:$http_auth_pass";
+            if ($userpass ~ '^external:test@example.com:$') {
+                set $reply OK;
+            }
+
             add_header Auth-Status $reply;
             add_header Auth-Server 127.0.0.1;
             add_header Auth-Port %%PORT_8026%%;
@@ -156,6 +161,33 @@
 $s->send(encode_base64('test@example.com ' . ('0' x 32), ''));
 $s->authok('auth cram-md5');
 
+TODO: {
+local $TODO = 'not yet' unless $t->has_version('1.11.6');
+
+# Try auth external
+
+$s = Test::Nginx::SMTP->new();
+$s->read();
+$s->send('EHLO example.com');
+$s->read();
+
+$s->send('AUTH EXTERNAL');
+$s->check(qr/^334 VXNlcm5hbWU6/, 'auth external challenge');
+$s->send(encode_base64('test@example.com', ''));
+$s->ok('auth external');
+
+# Try auth external with username
+
+$s = Test::Nginx::SMTP->new();
+$s->read();
+$s->send('EHLO example.com');
+$s->read();
+
+$s->send('AUTH EXTERNAL ' . encode_base64('test@example.com', ''));
+$s->ok('auth external with username');
+
+}
+
 # Try auth plain with pipelining
 
 $s = Test::Nginx::SMTP->new();