comparison mail_proxy_timeout.t @ 1978:79753dd514e6

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