Mercurial > hg > nginx-tests
annotate mail_proxy_timeout.t @ 1990:85d88cd5091c
Tests: SSI include stub tests.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Thu, 04 Jul 2024 17:42:55 +0300 |
parents | 79753dd514e6 |
children |
rev | line source |
---|---|
1978
79753dd514e6
Tests: added test for mail proxy timeout.
Rob Mueller <robm@fastmailteam.com>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
79753dd514e6
Tests: added test for mail proxy timeout.
Rob Mueller <robm@fastmailteam.com>
parents:
diff
changeset
|
2 |
79753dd514e6
Tests: added test for mail proxy timeout.
Rob Mueller <robm@fastmailteam.com>
parents:
diff
changeset
|
3 # (C) Maxim Dounin |
79753dd514e6
Tests: added test for mail proxy timeout.
Rob Mueller <robm@fastmailteam.com>
parents:
diff
changeset
|
4 |
79753dd514e6
Tests: added test for mail proxy timeout.
Rob Mueller <robm@fastmailteam.com>
parents:
diff
changeset
|
5 # Tests for nginx mail module, timeout and proxy_timeout directives. |
79753dd514e6
Tests: added test for mail proxy timeout.
Rob Mueller <robm@fastmailteam.com>
parents:
diff
changeset
|
6 |
79753dd514e6
Tests: added test for mail proxy timeout.
Rob Mueller <robm@fastmailteam.com>
parents:
diff
changeset
|
7 ############################################################################### |
79753dd514e6
Tests: added test for mail proxy timeout.
Rob Mueller <robm@fastmailteam.com>
parents:
diff
changeset
|
8 |
79753dd514e6
Tests: added test for mail proxy timeout.
Rob Mueller <robm@fastmailteam.com>
parents:
diff
changeset
|
9 use warnings; |
79753dd514e6
Tests: added test for mail proxy timeout.
Rob Mueller <robm@fastmailteam.com>
parents:
diff
changeset
|
10 use strict; |
79753dd514e6
Tests: added test for mail proxy timeout.
Rob Mueller <robm@fastmailteam.com>
parents:
diff
changeset
|
11 |
79753dd514e6
Tests: added test for mail proxy timeout.
Rob Mueller <robm@fastmailteam.com>
parents:
diff
changeset
|
12 use Test::More; |
79753dd514e6
Tests: added test for mail proxy timeout.
Rob Mueller <robm@fastmailteam.com>
parents:
diff
changeset
|
13 |
79753dd514e6
Tests: added test for mail proxy timeout.
Rob Mueller <robm@fastmailteam.com>
parents:
diff
changeset
|
14 BEGIN { use FindBin; chdir($FindBin::Bin); } |
79753dd514e6
Tests: added test for mail proxy timeout.
Rob Mueller <robm@fastmailteam.com>
parents:
diff
changeset
|
15 |
79753dd514e6
Tests: added test for mail proxy timeout.
Rob Mueller <robm@fastmailteam.com>
parents:
diff
changeset
|
16 use lib 'lib'; |
79753dd514e6
Tests: added test for mail proxy timeout.
Rob Mueller <robm@fastmailteam.com>
parents:
diff
changeset
|
17 use Test::Nginx; |
79753dd514e6
Tests: added test for mail proxy timeout.
Rob Mueller <robm@fastmailteam.com>
parents:
diff
changeset
|
18 use Test::Nginx::IMAP; |
79753dd514e6
Tests: added test for mail proxy timeout.
Rob Mueller <robm@fastmailteam.com>
parents:
diff
changeset
|
19 |
79753dd514e6
Tests: added test for mail proxy timeout.
Rob Mueller <robm@fastmailteam.com>
parents:
diff
changeset
|
20 ############################################################################### |
79753dd514e6
Tests: added test for mail proxy timeout.
Rob Mueller <robm@fastmailteam.com>
parents:
diff
changeset
|
21 |
79753dd514e6
Tests: added test for mail proxy timeout.
Rob Mueller <robm@fastmailteam.com>
parents:
diff
changeset
|
22 select STDERR; $| = 1; |
79753dd514e6
Tests: added test for mail proxy timeout.
Rob Mueller <robm@fastmailteam.com>
parents:
diff
changeset
|
23 select STDOUT; $| = 1; |
79753dd514e6
Tests: added test for mail proxy timeout.
Rob Mueller <robm@fastmailteam.com>
parents:
diff
changeset
|
24 |
79753dd514e6
Tests: added test for mail proxy timeout.
Rob Mueller <robm@fastmailteam.com>
parents:
diff
changeset
|
25 local $SIG{PIPE} = 'IGNORE'; |
79753dd514e6
Tests: added test for mail proxy timeout.
Rob Mueller <robm@fastmailteam.com>
parents:
diff
changeset
|
26 |
79753dd514e6
Tests: added test for mail proxy timeout.
Rob Mueller <robm@fastmailteam.com>
parents:
diff
changeset
|
27 my $t = Test::Nginx->new()->has(qw/mail imap http map rewrite/) |
79753dd514e6
Tests: added test for mail proxy timeout.
Rob Mueller <robm@fastmailteam.com>
parents:
diff
changeset
|
28 ->write_file_expand('nginx.conf', <<'EOF'); |
79753dd514e6
Tests: added test for mail proxy timeout.
Rob Mueller <robm@fastmailteam.com>
parents:
diff
changeset
|
29 |
79753dd514e6
Tests: added test for mail proxy timeout.
Rob Mueller <robm@fastmailteam.com>
parents:
diff
changeset
|
30 %%TEST_GLOBALS%% |
79753dd514e6
Tests: added test for mail proxy timeout.
Rob Mueller <robm@fastmailteam.com>
parents:
diff
changeset
|
31 |
79753dd514e6
Tests: added test for mail proxy timeout.
Rob Mueller <robm@fastmailteam.com>
parents:
diff
changeset
|
32 daemon off; |
79753dd514e6
Tests: added test for mail proxy timeout.
Rob Mueller <robm@fastmailteam.com>
parents:
diff
changeset
|
33 |
79753dd514e6
Tests: added test for mail proxy timeout.
Rob Mueller <robm@fastmailteam.com>
parents:
diff
changeset
|
34 events { |
79753dd514e6
Tests: added test for mail proxy timeout.
Rob Mueller <robm@fastmailteam.com>
parents:
diff
changeset
|
35 } |
79753dd514e6
Tests: added test for mail proxy timeout.
Rob Mueller <robm@fastmailteam.com>
parents:
diff
changeset
|
36 |
79753dd514e6
Tests: added test for mail proxy timeout.
Rob Mueller <robm@fastmailteam.com>
parents:
diff
changeset
|
37 mail { |
79753dd514e6
Tests: added test for mail proxy timeout.
Rob Mueller <robm@fastmailteam.com>
parents:
diff
changeset
|
38 proxy_pass_error_message on; |
79753dd514e6
Tests: added test for mail proxy timeout.
Rob Mueller <robm@fastmailteam.com>
parents:
diff
changeset
|
39 timeout 2s; |
79753dd514e6
Tests: added test for mail proxy timeout.
Rob Mueller <robm@fastmailteam.com>
parents:
diff
changeset
|
40 proxy_timeout 2s; |
79753dd514e6
Tests: added test for mail proxy timeout.
Rob Mueller <robm@fastmailteam.com>
parents:
diff
changeset
|
41 auth_http http://127.0.0.1:8080/mail/auth; |
79753dd514e6
Tests: added test for mail proxy timeout.
Rob Mueller <robm@fastmailteam.com>
parents:
diff
changeset
|
42 |
79753dd514e6
Tests: added test for mail proxy timeout.
Rob Mueller <robm@fastmailteam.com>
parents:
diff
changeset
|
43 server { |
79753dd514e6
Tests: added test for mail proxy timeout.
Rob Mueller <robm@fastmailteam.com>
parents:
diff
changeset
|
44 listen 127.0.0.1:8143; |
79753dd514e6
Tests: added test for mail proxy timeout.
Rob Mueller <robm@fastmailteam.com>
parents:
diff
changeset
|
45 protocol imap; |
79753dd514e6
Tests: added test for mail proxy timeout.
Rob Mueller <robm@fastmailteam.com>
parents:
diff
changeset
|
46 imap_auth plain cram-md5 external; |
79753dd514e6
Tests: added test for mail proxy timeout.
Rob Mueller <robm@fastmailteam.com>
parents:
diff
changeset
|
47 } |
79753dd514e6
Tests: added test for mail proxy timeout.
Rob Mueller <robm@fastmailteam.com>
parents:
diff
changeset
|
48 } |
79753dd514e6
Tests: added test for mail proxy timeout.
Rob Mueller <robm@fastmailteam.com>
parents:
diff
changeset
|
49 |
79753dd514e6
Tests: added test for mail proxy timeout.
Rob Mueller <robm@fastmailteam.com>
parents:
diff
changeset
|
50 http { |
79753dd514e6
Tests: added test for mail proxy timeout.
Rob Mueller <robm@fastmailteam.com>
parents:
diff
changeset
|
51 %%TEST_GLOBALS_HTTP%% |
79753dd514e6
Tests: added test for mail proxy timeout.
Rob Mueller <robm@fastmailteam.com>
parents:
diff
changeset
|
52 |
79753dd514e6
Tests: added test for mail proxy timeout.
Rob Mueller <robm@fastmailteam.com>
parents:
diff
changeset
|
53 map $http_auth_pass $reply { |
79753dd514e6
Tests: added test for mail proxy timeout.
Rob Mueller <robm@fastmailteam.com>
parents:
diff
changeset
|
54 secret OK; |
79753dd514e6
Tests: added test for mail proxy timeout.
Rob Mueller <robm@fastmailteam.com>
parents:
diff
changeset
|
55 default ERROR; |
79753dd514e6
Tests: added test for mail proxy timeout.
Rob Mueller <robm@fastmailteam.com>
parents:
diff
changeset
|
56 } |
79753dd514e6
Tests: added test for mail proxy timeout.
Rob Mueller <robm@fastmailteam.com>
parents:
diff
changeset
|
57 |
79753dd514e6
Tests: added test for mail proxy timeout.
Rob Mueller <robm@fastmailteam.com>
parents:
diff
changeset
|
58 server { |
79753dd514e6
Tests: added test for mail proxy timeout.
Rob Mueller <robm@fastmailteam.com>
parents:
diff
changeset
|
59 listen 127.0.0.1:8080; |
79753dd514e6
Tests: added test for mail proxy timeout.
Rob Mueller <robm@fastmailteam.com>
parents:
diff
changeset
|
60 server_name localhost; |
79753dd514e6
Tests: added test for mail proxy timeout.
Rob Mueller <robm@fastmailteam.com>
parents:
diff
changeset
|
61 |
79753dd514e6
Tests: added test for mail proxy timeout.
Rob Mueller <robm@fastmailteam.com>
parents:
diff
changeset
|
62 location = /mail/auth { |
79753dd514e6
Tests: added test for mail proxy timeout.
Rob Mueller <robm@fastmailteam.com>
parents:
diff
changeset
|
63 add_header Auth-Status $reply; |
79753dd514e6
Tests: added test for mail proxy timeout.
Rob Mueller <robm@fastmailteam.com>
parents:
diff
changeset
|
64 add_header Auth-Server 127.0.0.1; |
79753dd514e6
Tests: added test for mail proxy timeout.
Rob Mueller <robm@fastmailteam.com>
parents:
diff
changeset
|
65 add_header Auth-Port %%PORT_8144%%; |
79753dd514e6
Tests: added test for mail proxy timeout.
Rob Mueller <robm@fastmailteam.com>
parents:
diff
changeset
|
66 add_header Auth-Pass ""; |
79753dd514e6
Tests: added test for mail proxy timeout.
Rob Mueller <robm@fastmailteam.com>
parents:
diff
changeset
|
67 add_header Auth-Wait 1; |
79753dd514e6
Tests: added test for mail proxy timeout.
Rob Mueller <robm@fastmailteam.com>
parents:
diff
changeset
|
68 return 204; |
79753dd514e6
Tests: added test for mail proxy timeout.
Rob Mueller <robm@fastmailteam.com>
parents:
diff
changeset
|
69 } |
79753dd514e6
Tests: added test for mail proxy timeout.
Rob Mueller <robm@fastmailteam.com>
parents:
diff
changeset
|
70 } |
79753dd514e6
Tests: added test for mail proxy timeout.
Rob Mueller <robm@fastmailteam.com>
parents:
diff
changeset
|
71 } |
79753dd514e6
Tests: added test for mail proxy timeout.
Rob Mueller <robm@fastmailteam.com>
parents:
diff
changeset
|
72 |
79753dd514e6
Tests: added test for mail proxy timeout.
Rob Mueller <robm@fastmailteam.com>
parents:
diff
changeset
|
73 EOF |
79753dd514e6
Tests: added test for mail proxy timeout.
Rob Mueller <robm@fastmailteam.com>
parents:
diff
changeset
|
74 |
79753dd514e6
Tests: added test for mail proxy timeout.
Rob Mueller <robm@fastmailteam.com>
parents:
diff
changeset
|
75 $t->run_daemon(\&Test::Nginx::IMAP::imap_test_daemon); |
79753dd514e6
Tests: added test for mail proxy timeout.
Rob Mueller <robm@fastmailteam.com>
parents:
diff
changeset
|
76 $t->run()->plan(8); |
79753dd514e6
Tests: added test for mail proxy timeout.
Rob Mueller <robm@fastmailteam.com>
parents:
diff
changeset
|
77 |
79753dd514e6
Tests: added test for mail proxy timeout.
Rob Mueller <robm@fastmailteam.com>
parents:
diff
changeset
|
78 $t->waitforsocket('127.0.0.1:' . port(8144)); |
79753dd514e6
Tests: added test for mail proxy timeout.
Rob Mueller <robm@fastmailteam.com>
parents:
diff
changeset
|
79 |
79753dd514e6
Tests: added test for mail proxy timeout.
Rob Mueller <robm@fastmailteam.com>
parents:
diff
changeset
|
80 ############################################################################### |
79753dd514e6
Tests: added test for mail proxy timeout.
Rob Mueller <robm@fastmailteam.com>
parents:
diff
changeset
|
81 |
79753dd514e6
Tests: added test for mail proxy timeout.
Rob Mueller <robm@fastmailteam.com>
parents:
diff
changeset
|
82 # check proxy timeout |
79753dd514e6
Tests: added test for mail proxy timeout.
Rob Mueller <robm@fastmailteam.com>
parents:
diff
changeset
|
83 |
79753dd514e6
Tests: added test for mail proxy timeout.
Rob Mueller <robm@fastmailteam.com>
parents:
diff
changeset
|
84 my $s = Test::Nginx::IMAP->new(); |
79753dd514e6
Tests: added test for mail proxy timeout.
Rob Mueller <robm@fastmailteam.com>
parents:
diff
changeset
|
85 $s->read(); |
79753dd514e6
Tests: added test for mail proxy timeout.
Rob Mueller <robm@fastmailteam.com>
parents:
diff
changeset
|
86 |
79753dd514e6
Tests: added test for mail proxy timeout.
Rob Mueller <robm@fastmailteam.com>
parents:
diff
changeset
|
87 # Each of these will wait 1 second before response |
79753dd514e6
Tests: added test for mail proxy timeout.
Rob Mueller <robm@fastmailteam.com>
parents:
diff
changeset
|
88 |
79753dd514e6
Tests: added test for mail proxy timeout.
Rob Mueller <robm@fastmailteam.com>
parents:
diff
changeset
|
89 $s->send('a01 LOGIN test@example.com bad'); |
79753dd514e6
Tests: added test for mail proxy timeout.
Rob Mueller <robm@fastmailteam.com>
parents:
diff
changeset
|
90 $s->check(qr/^a01 NO/, 'login with bad password'); |
79753dd514e6
Tests: added test for mail proxy timeout.
Rob Mueller <robm@fastmailteam.com>
parents:
diff
changeset
|
91 |
79753dd514e6
Tests: added test for mail proxy timeout.
Rob Mueller <robm@fastmailteam.com>
parents:
diff
changeset
|
92 $s->send('a01 LOGIN test@example.com bad'); |
79753dd514e6
Tests: added test for mail proxy timeout.
Rob Mueller <robm@fastmailteam.com>
parents:
diff
changeset
|
93 $s->check(qr/^a01 NO/, 'login with bad password'); |
79753dd514e6
Tests: added test for mail proxy timeout.
Rob Mueller <robm@fastmailteam.com>
parents:
diff
changeset
|
94 |
79753dd514e6
Tests: added test for mail proxy timeout.
Rob Mueller <robm@fastmailteam.com>
parents:
diff
changeset
|
95 sleep(1); |
79753dd514e6
Tests: added test for mail proxy timeout.
Rob Mueller <robm@fastmailteam.com>
parents:
diff
changeset
|
96 |
79753dd514e6
Tests: added test for mail proxy timeout.
Rob Mueller <robm@fastmailteam.com>
parents:
diff
changeset
|
97 # Total timeout is 2 seconds, so connection should have been closed |
79753dd514e6
Tests: added test for mail proxy timeout.
Rob Mueller <robm@fastmailteam.com>
parents:
diff
changeset
|
98 |
79753dd514e6
Tests: added test for mail proxy timeout.
Rob Mueller <robm@fastmailteam.com>
parents:
diff
changeset
|
99 my @ready = $s->can_read(0); |
79753dd514e6
Tests: added test for mail proxy timeout.
Rob Mueller <robm@fastmailteam.com>
parents:
diff
changeset
|
100 is(scalar @ready, 1, "ready for reading"); |
79753dd514e6
Tests: added test for mail proxy timeout.
Rob Mueller <robm@fastmailteam.com>
parents:
diff
changeset
|
101 ok($s->eof(), "session closed"); |
79753dd514e6
Tests: added test for mail proxy timeout.
Rob Mueller <robm@fastmailteam.com>
parents:
diff
changeset
|
102 |
79753dd514e6
Tests: added test for mail proxy timeout.
Rob Mueller <robm@fastmailteam.com>
parents:
diff
changeset
|
103 |
79753dd514e6
Tests: added test for mail proxy timeout.
Rob Mueller <robm@fastmailteam.com>
parents:
diff
changeset
|
104 $s = Test::Nginx::IMAP->new(); |
79753dd514e6
Tests: added test for mail proxy timeout.
Rob Mueller <robm@fastmailteam.com>
parents:
diff
changeset
|
105 $s->read(); |
79753dd514e6
Tests: added test for mail proxy timeout.
Rob Mueller <robm@fastmailteam.com>
parents:
diff
changeset
|
106 |
79753dd514e6
Tests: added test for mail proxy timeout.
Rob Mueller <robm@fastmailteam.com>
parents:
diff
changeset
|
107 $s->send('a01 LOGIN test@example.com secret'); |
79753dd514e6
Tests: added test for mail proxy timeout.
Rob Mueller <robm@fastmailteam.com>
parents:
diff
changeset
|
108 $s->ok('login'); |
79753dd514e6
Tests: added test for mail proxy timeout.
Rob Mueller <robm@fastmailteam.com>
parents:
diff
changeset
|
109 |
79753dd514e6
Tests: added test for mail proxy timeout.
Rob Mueller <robm@fastmailteam.com>
parents:
diff
changeset
|
110 @ready = $s->can_read(0.1); |
79753dd514e6
Tests: added test for mail proxy timeout.
Rob Mueller <robm@fastmailteam.com>
parents:
diff
changeset
|
111 is(scalar @ready, 0, "nothing to read after login"); |
79753dd514e6
Tests: added test for mail proxy timeout.
Rob Mueller <robm@fastmailteam.com>
parents:
diff
changeset
|
112 |
79753dd514e6
Tests: added test for mail proxy timeout.
Rob Mueller <robm@fastmailteam.com>
parents:
diff
changeset
|
113 sleep(3); |
79753dd514e6
Tests: added test for mail proxy timeout.
Rob Mueller <robm@fastmailteam.com>
parents:
diff
changeset
|
114 |
79753dd514e6
Tests: added test for mail proxy timeout.
Rob Mueller <robm@fastmailteam.com>
parents:
diff
changeset
|
115 # Total timeout is 2 seconds, so connection should have been closed |
79753dd514e6
Tests: added test for mail proxy timeout.
Rob Mueller <robm@fastmailteam.com>
parents:
diff
changeset
|
116 |
79753dd514e6
Tests: added test for mail proxy timeout.
Rob Mueller <robm@fastmailteam.com>
parents:
diff
changeset
|
117 @ready = $s->can_read(0); |
79753dd514e6
Tests: added test for mail proxy timeout.
Rob Mueller <robm@fastmailteam.com>
parents:
diff
changeset
|
118 is(scalar @ready, 1, "ready for reading"); |
79753dd514e6
Tests: added test for mail proxy timeout.
Rob Mueller <robm@fastmailteam.com>
parents:
diff
changeset
|
119 ok($s->eof(), "session closed"); |
79753dd514e6
Tests: added test for mail proxy timeout.
Rob Mueller <robm@fastmailteam.com>
parents:
diff
changeset
|
120 |
79753dd514e6
Tests: added test for mail proxy timeout.
Rob Mueller <robm@fastmailteam.com>
parents:
diff
changeset
|
121 ############################################################################### |