Tests: auth cram-md5 mail tests, pop3 user/pass and apop tests.
diff --git a/mail_imap.t b/mail_imap.t
index 87c9c82..48fa07e 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(9)
+my $t = Test::Nginx->new()->has(qw/mail imap http rewrite/)->plan(11)
->write_file_expand('nginx.conf', <<'EOF');
%%TEST_GLOBALS%%
@@ -43,6 +43,7 @@
server {
listen 127.0.0.1:8143;
protocol imap;
+ imap_auth plain cram-md5;
}
}
@@ -55,6 +56,7 @@
location = /mail/auth {
set $reply ERROR;
+ set $passw "";
if ($http_auth_smtp_to ~ example.com) {
set $reply OK;
@@ -65,9 +67,16 @@
set $reply OK;
}
+ set $userpass "$http_auth_user:$http_auth_salt:$http_auth_pass";
+ if ($userpass ~ '^test@example.com:<.*@.*>:0{32}$') {
+ 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%%;
+ add_header Auth-Pass $passw;
add_header Auth-Wait 1;
return 204;
}
@@ -122,4 +131,15 @@
$s->send(encode_base64('secret', ''));
$s->ok('auth login with username');
+# auth cram-md5
+
+$s = Test::Nginx::IMAP->new();
+$s->read();
+
+$s->send('1 AUTHENTICATE CRAM-MD5');
+$s->check(qr/\+ /, 'auth cram-md5 challenge');
+
+$s->send(encode_base64('test@example.com ' . ('0' x 32), ''));
+$s->ok('auth cram-md5');
+
###############################################################################
diff --git a/mail_pop3.t b/mail_pop3.t
index 3b21173..aeecfa4 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(8)
+my $t = Test::Nginx->new()->has(qw/mail pop3 http rewrite/)->plan(15)
->write_file_expand('nginx.conf', <<'EOF');
%%TEST_GLOBALS%%
@@ -43,6 +43,7 @@
server {
listen 127.0.0.1:8110;
protocol pop3;
+ pop3_auth plain apop cram-md5;
}
}
@@ -55,6 +56,7 @@
location = /mail/auth {
set $reply ERROR;
+ set $passw "";
if ($http_auth_smtp_to ~ example.com) {
set $reply OK;
@@ -65,9 +67,16 @@
set $reply OK;
}
+ set $userpass "$http_auth_user:$http_auth_salt:$http_auth_pass";
+ if ($userpass ~ '^test@example.com:<.*@.*>:0{32}$') {
+ 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%%;
+ add_header Auth-Pass $passw;
add_header Auth-Wait 1;
return 204;
}
@@ -84,8 +93,30 @@
my $s = Test::Nginx::POP3->new();
$s->ok('greeting');
+# user / pass
+
+$s->send('USER test@example.com');
+$s->ok('user');
+
+$s->send('PASS secret');
+$s->ok('pass');
+
+# apop
+
+$s = Test::Nginx::POP3->new();
+$s->check(qr/<.*\@.*>/, 'apop salt');
+
+$s->send('APOP test@example.com ' . ('1' x 32));
+$s->check(qr/^-ERR/, 'apop error');
+
+$s->send('APOP test@example.com ' . ('0' x 32));
+$s->ok('apop');
+
# auth plain
+$s = Test::Nginx::POP3->new();
+$s->read();
+
$s->send('AUTH PLAIN ' . encode_base64("\0test\@example.com\0bad", ''));
$s->check(qr/^-ERR/, 'auth plain with bad password');
@@ -117,4 +148,15 @@
$s->send(encode_base64('secret', ''));
$s->ok('auth login with username');
+# auth cram-md5
+
+$s = Test::Nginx::POP3->new();
+$s->read();
+
+$s->send('AUTH CRAM-MD5');
+$s->check(qr/\+ /, 'auth cram-md5 challenge');
+
+$s->send(encode_base64('test@example.com ' . ('0' x 32), ''));
+$s->ok('auth cram-md5');
+
###############################################################################
diff --git a/mail_smtp.t b/mail_smtp.t
index 6851d0b..81ea0b7 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(25)
+my $t = Test::Nginx->new()->has(qw/mail smtp http rewrite/)->plan(27)
->write_file_expand('nginx.conf', <<'EOF');
%%TEST_GLOBALS%%
@@ -45,7 +45,7 @@
server {
listen 127.0.0.1:8025;
protocol smtp;
- smtp_auth login plain none;
+ smtp_auth login plain none cram-md5;
}
}
@@ -68,6 +68,11 @@
set $reply OK;
}
+ set $userpass "$http_auth_user:$http_auth_salt:$http_auth_pass";
+ if ($userpass ~ '^test@example.com:<.*@.*>:0{32}$') {
+ set $reply OK;
+ }
+
add_header Auth-Status $reply;
add_header Auth-Server 127.0.0.1;
add_header Auth-Port %%PORT_8026%%;
@@ -139,6 +144,18 @@
$s->send(encode_base64('secret', ''));
$s->authok('auth login with username');
+# Try auth cram-md5
+
+$s = Test::Nginx::SMTP->new();
+$s->read();
+$s->send('EHLO example.com');
+$s->read();
+
+$s->send('AUTH CRAM-MD5');
+$s->check(qr/^334 /, 'auth cram-md5 challenge');
+$s->send(encode_base64('test@example.com ' . ('0' x 32), ''));
+$s->authok('auth cram-md5');
+
# Try auth plain with pipelining
$s = Test::Nginx::SMTP->new();