Mercurial > hg > nginx-tests
annotate mail_resolver.t @ 1990:85d88cd5091c
Tests: SSI include stub tests.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Thu, 04 Jul 2024 17:42:55 +0300 |
parents | cdcd75657e52 |
children |
rev | line source |
---|---|
352
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2 |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
3 # (C) Sergey Kandaurov |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
4 # (C) Nginx, Inc. |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
5 |
355
14eba1ad0880
Tests: reduce race in mail resolver test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
352
diff
changeset
|
6 # Tests for mail resolver. |
352
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
7 |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
8 ############################################################################### |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
9 |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
10 use warnings; |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
11 use strict; |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
12 |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
13 use Test::More; |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
14 |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
15 BEGIN { use FindBin; chdir($FindBin::Bin); } |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
16 |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
17 use lib 'lib'; |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
18 use Test::Nginx; |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
19 use Test::Nginx::SMTP; |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
20 |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
21 ############################################################################### |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
22 |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
23 select STDERR; $| = 1; |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
24 select STDOUT; $| = 1; |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
25 |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
26 local $SIG{PIPE} = 'IGNORE'; |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
27 |
1858
cdcd75657e52
Tests: added has_feature() tests for IO::Socket::SSL.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1693
diff
changeset
|
28 my $t = Test::Nginx->new()->has(qw/mail mail_ssl smtp http rewrite socket_ssl/) |
1496
e1eb3432487b
Tests: added mail resolver tests with ssl.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1494
diff
changeset
|
29 ->has_daemon('openssl')->plan(11) |
976
a8b8dd6e8ae1
Tests: changed startup order in mail tests for consistency.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
970
diff
changeset
|
30 ->write_file_expand('nginx.conf', <<'EOF'); |
352
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
31 |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
32 %%TEST_GLOBALS%% |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
33 |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
34 daemon off; |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
35 |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
36 events { |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
37 } |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
38 |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
39 mail { |
970
c227348453db
Tests: simplified parallel modifications in mail tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
952
diff
changeset
|
40 auth_http http://127.0.0.1:8080/mail/auth; |
352
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
41 smtp_auth none; |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
42 server_name locahost; |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
43 |
1679
74986ebee2fd
Tests: added proxy_timeout in mail tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1496
diff
changeset
|
44 proxy_timeout 15s; |
74986ebee2fd
Tests: added proxy_timeout in mail tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1496
diff
changeset
|
45 |
362
8ca9c75c97d2
Tests: more resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
361
diff
changeset
|
46 # prevent useless resend |
906
0654d7315b52
Tests: adjusted resolver timeout in mail resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
839
diff
changeset
|
47 resolver_timeout 2s; |
362
8ca9c75c97d2
Tests: more resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
361
diff
changeset
|
48 |
352
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
49 server { |
970
c227348453db
Tests: simplified parallel modifications in mail tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
952
diff
changeset
|
50 listen 127.0.0.1:8025; |
352
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
51 protocol smtp; |
1237
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1215
diff
changeset
|
52 resolver 127.0.0.1:%%PORT_8981_UDP%% |
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1215
diff
changeset
|
53 127.0.0.1:%%PORT_8982_UDP%% |
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1215
diff
changeset
|
54 127.0.0.1:%%PORT_8983_UDP%%; |
352
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
55 } |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
56 |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
57 server { |
970
c227348453db
Tests: simplified parallel modifications in mail tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
952
diff
changeset
|
58 listen 127.0.0.1:8027; |
352
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
59 protocol smtp; |
1237
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1215
diff
changeset
|
60 resolver 127.0.0.1:%%PORT_8982_UDP%%; |
352
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
61 } |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
62 |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
63 server { |
970
c227348453db
Tests: simplified parallel modifications in mail tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
952
diff
changeset
|
64 listen 127.0.0.1:8028; |
352
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
65 protocol smtp; |
1237
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1215
diff
changeset
|
66 resolver 127.0.0.1:%%PORT_8983_UDP%%; |
1126
65fc7a0ca418
Tests: adjusted mail resolver timeout below client read timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1020
diff
changeset
|
67 resolver_timeout 1s; |
352
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
68 } |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
69 |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
70 server { |
970
c227348453db
Tests: simplified parallel modifications in mail tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
952
diff
changeset
|
71 listen 127.0.0.1:8029; |
352
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
72 protocol smtp; |
1237
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1215
diff
changeset
|
73 resolver 127.0.0.1:%%PORT_8984_UDP%%; |
352
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
74 } |
362
8ca9c75c97d2
Tests: more resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
361
diff
changeset
|
75 |
8ca9c75c97d2
Tests: more resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
361
diff
changeset
|
76 server { |
970
c227348453db
Tests: simplified parallel modifications in mail tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
952
diff
changeset
|
77 listen 127.0.0.1:8030; |
362
8ca9c75c97d2
Tests: more resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
361
diff
changeset
|
78 protocol smtp; |
1237
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1215
diff
changeset
|
79 resolver 127.0.0.1:%%PORT_8985_UDP%%; |
362
8ca9c75c97d2
Tests: more resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
361
diff
changeset
|
80 } |
8ca9c75c97d2
Tests: more resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
361
diff
changeset
|
81 |
8ca9c75c97d2
Tests: more resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
361
diff
changeset
|
82 server { |
970
c227348453db
Tests: simplified parallel modifications in mail tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
952
diff
changeset
|
83 listen 127.0.0.1:8031; |
362
8ca9c75c97d2
Tests: more resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
361
diff
changeset
|
84 protocol smtp; |
1237
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1215
diff
changeset
|
85 resolver 127.0.0.1:%%PORT_8986_UDP%%; |
1215
26884729e06b
Tests: cope with resolver resend in mail resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1126
diff
changeset
|
86 resolver_timeout 1s; |
362
8ca9c75c97d2
Tests: more resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
361
diff
changeset
|
87 } |
809
ded6b7648d6e
Tests: added mail resolver test for CNAME and PTR records combined.
Sergey Kandaurov <pluknet@nginx.com>
parents:
806
diff
changeset
|
88 |
ded6b7648d6e
Tests: added mail resolver test for CNAME and PTR records combined.
Sergey Kandaurov <pluknet@nginx.com>
parents:
806
diff
changeset
|
89 server { |
970
c227348453db
Tests: simplified parallel modifications in mail tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
952
diff
changeset
|
90 listen 127.0.0.1:8032; |
809
ded6b7648d6e
Tests: added mail resolver test for CNAME and PTR records combined.
Sergey Kandaurov <pluknet@nginx.com>
parents:
806
diff
changeset
|
91 protocol smtp; |
1237
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1215
diff
changeset
|
92 resolver 127.0.0.1:%%PORT_8987_UDP%%; |
809
ded6b7648d6e
Tests: added mail resolver test for CNAME and PTR records combined.
Sergey Kandaurov <pluknet@nginx.com>
parents:
806
diff
changeset
|
93 } |
ded6b7648d6e
Tests: added mail resolver test for CNAME and PTR records combined.
Sergey Kandaurov <pluknet@nginx.com>
parents:
806
diff
changeset
|
94 |
1496
e1eb3432487b
Tests: added mail resolver tests with ssl.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1494
diff
changeset
|
95 server { |
e1eb3432487b
Tests: added mail resolver tests with ssl.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1494
diff
changeset
|
96 ssl_certificate_key localhost.key; |
e1eb3432487b
Tests: added mail resolver tests with ssl.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1494
diff
changeset
|
97 ssl_certificate localhost.crt; |
e1eb3432487b
Tests: added mail resolver tests with ssl.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1494
diff
changeset
|
98 |
e1eb3432487b
Tests: added mail resolver tests with ssl.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1494
diff
changeset
|
99 listen 127.0.0.1:8033 ssl; |
e1eb3432487b
Tests: added mail resolver tests with ssl.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1494
diff
changeset
|
100 protocol smtp; |
e1eb3432487b
Tests: added mail resolver tests with ssl.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1494
diff
changeset
|
101 resolver 127.0.0.1:%%PORT_8983_UDP%%; |
e1eb3432487b
Tests: added mail resolver tests with ssl.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1494
diff
changeset
|
102 } |
352
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
103 } |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
104 |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
105 http { |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
106 %%TEST_GLOBALS_HTTP%% |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
107 |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
108 server { |
970
c227348453db
Tests: simplified parallel modifications in mail tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
952
diff
changeset
|
109 listen 127.0.0.1:8080; |
352
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
110 server_name localhost; |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
111 |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
112 location = /mail/auth { |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
113 set $reply $http_client_host; |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
114 |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
115 if ($http_client_host !~ UNAVAIL) { |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
116 set $reply OK; |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
117 } |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
118 |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
119 add_header Auth-Status $reply; |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
120 add_header Auth-Server 127.0.0.1; |
970
c227348453db
Tests: simplified parallel modifications in mail tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
952
diff
changeset
|
121 add_header Auth-Port %%PORT_8026%%; |
352
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
122 return 204; |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
123 } |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
124 } |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
125 } |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
126 |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
127 EOF |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
128 |
1496
e1eb3432487b
Tests: added mail resolver tests with ssl.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1494
diff
changeset
|
129 $t->write_file('openssl.conf', <<EOF); |
e1eb3432487b
Tests: added mail resolver tests with ssl.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1494
diff
changeset
|
130 [ req ] |
e1eb3432487b
Tests: added mail resolver tests with ssl.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1494
diff
changeset
|
131 default_bits = 2048 |
e1eb3432487b
Tests: added mail resolver tests with ssl.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1494
diff
changeset
|
132 encrypt_key = no |
e1eb3432487b
Tests: added mail resolver tests with ssl.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1494
diff
changeset
|
133 distinguished_name = req_distinguished_name |
e1eb3432487b
Tests: added mail resolver tests with ssl.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1494
diff
changeset
|
134 [ req_distinguished_name ] |
e1eb3432487b
Tests: added mail resolver tests with ssl.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1494
diff
changeset
|
135 EOF |
e1eb3432487b
Tests: added mail resolver tests with ssl.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1494
diff
changeset
|
136 |
e1eb3432487b
Tests: added mail resolver tests with ssl.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1494
diff
changeset
|
137 my $d = $t->testdir(); |
e1eb3432487b
Tests: added mail resolver tests with ssl.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1494
diff
changeset
|
138 |
e1eb3432487b
Tests: added mail resolver tests with ssl.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1494
diff
changeset
|
139 foreach my $name ('localhost') { |
e1eb3432487b
Tests: added mail resolver tests with ssl.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1494
diff
changeset
|
140 system('openssl req -x509 -new ' |
e1eb3432487b
Tests: added mail resolver tests with ssl.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1494
diff
changeset
|
141 . "-config $d/openssl.conf -subj /CN=$name/ " |
e1eb3432487b
Tests: added mail resolver tests with ssl.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1494
diff
changeset
|
142 . "-out $d/$name.crt -keyout $d/$name.key " |
e1eb3432487b
Tests: added mail resolver tests with ssl.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1494
diff
changeset
|
143 . ">>$d/openssl.out 2>&1") == 0 |
e1eb3432487b
Tests: added mail resolver tests with ssl.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1494
diff
changeset
|
144 or die "Can't create certificate for $name: $!\n"; |
e1eb3432487b
Tests: added mail resolver tests with ssl.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1494
diff
changeset
|
145 } |
e1eb3432487b
Tests: added mail resolver tests with ssl.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1494
diff
changeset
|
146 |
976
a8b8dd6e8ae1
Tests: changed startup order in mail tests for consistency.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
970
diff
changeset
|
147 $t->run_daemon(\&Test::Nginx::SMTP::smtp_test_daemon); |
1237
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1215
diff
changeset
|
148 $t->run_daemon(\&dns_daemon, port($_), $t) foreach (8981 .. 8987); |
976
a8b8dd6e8ae1
Tests: changed startup order in mail tests for consistency.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
970
diff
changeset
|
149 |
352
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
150 $t->run(); |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
151 |
976
a8b8dd6e8ae1
Tests: changed startup order in mail tests for consistency.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
970
diff
changeset
|
152 $t->waitforsocket('127.0.0.1:' . port(8026)); |
1237
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1215
diff
changeset
|
153 $t->waitforfile($t->testdir . '/' . port($_)) foreach (8981 .. 8987); |
352
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
154 |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
155 ############################################################################### |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
156 |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
157 # PTR |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
158 |
970
c227348453db
Tests: simplified parallel modifications in mail tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
952
diff
changeset
|
159 my $s = Test::Nginx::SMTP->new(); |
1494
1356e7374c57
Tests: added mail resolver tests for PTR with rn->waiting.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1237
diff
changeset
|
160 my $s2 = Test::Nginx::SMTP->new(); |
352
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
161 $s->read(); |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
162 $s->send('EHLO example.com'); |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
163 $s->read(); |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
164 $s->send('MAIL FROM:<test@example.com> SIZE=100'); |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
165 $s->read(); |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
166 |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
167 $s->send('RCPT TO:<test@example.com>'); |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
168 $s->ok('PTR'); |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
169 |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
170 $s->send('QUIT'); |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
171 $s->read(); |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
172 |
1494
1356e7374c57
Tests: added mail resolver tests for PTR with rn->waiting.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1237
diff
changeset
|
173 $s2->read(); |
1356e7374c57
Tests: added mail resolver tests for PTR with rn->waiting.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1237
diff
changeset
|
174 $s2->send('EHLO example.com'); |
1356e7374c57
Tests: added mail resolver tests for PTR with rn->waiting.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1237
diff
changeset
|
175 $s2->ok('PTR waiting'); |
1356e7374c57
Tests: added mail resolver tests for PTR with rn->waiting.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1237
diff
changeset
|
176 |
1237
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1215
diff
changeset
|
177 # Cached PTR prevents from querying bad ns on port 8983 |
352
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
178 |
970
c227348453db
Tests: simplified parallel modifications in mail tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
952
diff
changeset
|
179 $s = Test::Nginx::SMTP->new(); |
352
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
180 $s->read(); |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
181 $s->send('EHLO example.com'); |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
182 $s->read(); |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
183 $s->send('MAIL FROM:<test@example.com> SIZE=100'); |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
184 $s->read(); |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
185 |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
186 $s->send('RCPT TO:<test@example.com>'); |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
187 $s->ok('PTR cached'); |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
188 |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
189 $s->send('QUIT'); |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
190 $s->read(); |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
191 |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
192 # SERVFAIL |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
193 |
970
c227348453db
Tests: simplified parallel modifications in mail tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
952
diff
changeset
|
194 $s = Test::Nginx::SMTP->new(PeerAddr => '127.0.0.1:' . port(8027)); |
352
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
195 $s->read(); |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
196 $s->send('EHLO example.com'); |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
197 $s->read(); |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
198 $s->send('MAIL FROM:<test@example.com> SIZE=100'); |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
199 $s->read(); |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
200 |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
201 $s->send('RCPT TO:<test@example.com>'); |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
202 $s->check(qr/TEMPUNAVAIL/, 'PTR SERVFAIL'); |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
203 |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
204 $s->send('QUIT'); |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
205 $s->read(); |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
206 |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
207 # PTR with zero length RDATA |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
208 |
970
c227348453db
Tests: simplified parallel modifications in mail tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
952
diff
changeset
|
209 $s = Test::Nginx::SMTP->new(PeerAddr => '127.0.0.1:' . port(8028)); |
1494
1356e7374c57
Tests: added mail resolver tests for PTR with rn->waiting.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1237
diff
changeset
|
210 $s2 = Test::Nginx::SMTP->new(PeerAddr => '127.0.0.1:' . port(8028)); |
352
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
211 $s->read(); |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
212 $s->send('EHLO example.com'); |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
213 $s->read(); |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
214 $s->send('MAIL FROM:<test@example.com> SIZE=100'); |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
215 $s->read(); |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
216 |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
217 $s->send('RCPT TO:<test@example.com>'); |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
218 $s->check(qr/TEMPUNAVAIL/, 'PTR empty'); |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
219 |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
220 $s->send('QUIT'); |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
221 $s->read(); |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
222 |
1494
1356e7374c57
Tests: added mail resolver tests for PTR with rn->waiting.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1237
diff
changeset
|
223 # resolver timeout is set |
1356e7374c57
Tests: added mail resolver tests for PTR with rn->waiting.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1237
diff
changeset
|
224 |
1356e7374c57
Tests: added mail resolver tests for PTR with rn->waiting.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1237
diff
changeset
|
225 $s2->read(); |
1356e7374c57
Tests: added mail resolver tests for PTR with rn->waiting.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1237
diff
changeset
|
226 $s2->send('EHLO example.com'); |
1356e7374c57
Tests: added mail resolver tests for PTR with rn->waiting.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1237
diff
changeset
|
227 $s2->ok('PTR empty waiting'); |
1356e7374c57
Tests: added mail resolver tests for PTR with rn->waiting.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1237
diff
changeset
|
228 |
352
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
229 # CNAME |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
230 |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
231 TODO: { |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
232 local $TODO = 'support for CNAME RR'; |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
233 |
970
c227348453db
Tests: simplified parallel modifications in mail tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
952
diff
changeset
|
234 $s = Test::Nginx::SMTP->new(PeerAddr => '127.0.0.1:' . port(8029)); |
352
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
235 $s->read(); |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
236 $s->send('EHLO example.com'); |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
237 $s->read(); |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
238 $s->send('MAIL FROM:<test@example.com> SIZE=100'); |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
239 $s->read(); |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
240 |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
241 $s->send('RCPT TO:<test@example.com>'); |
809
ded6b7648d6e
Tests: added mail resolver test for CNAME and PTR records combined.
Sergey Kandaurov <pluknet@nginx.com>
parents:
806
diff
changeset
|
242 $s->ok('CNAME'); |
352
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
243 |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
244 $s->send('QUIT'); |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
245 $s->read(); |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
246 |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
247 } |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
248 |
362
8ca9c75c97d2
Tests: more resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
361
diff
changeset
|
249 # uncompressed answer |
8ca9c75c97d2
Tests: more resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
361
diff
changeset
|
250 |
970
c227348453db
Tests: simplified parallel modifications in mail tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
952
diff
changeset
|
251 $s = Test::Nginx::SMTP->new(PeerAddr => '127.0.0.1:' . port(8030)); |
362
8ca9c75c97d2
Tests: more resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
361
diff
changeset
|
252 $s->read(); |
8ca9c75c97d2
Tests: more resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
361
diff
changeset
|
253 $s->send('EHLO example.com'); |
8ca9c75c97d2
Tests: more resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
361
diff
changeset
|
254 $s->read(); |
8ca9c75c97d2
Tests: more resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
361
diff
changeset
|
255 $s->send('MAIL FROM:<test@example.com> SIZE=100'); |
8ca9c75c97d2
Tests: more resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
361
diff
changeset
|
256 $s->read(); |
8ca9c75c97d2
Tests: more resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
361
diff
changeset
|
257 |
8ca9c75c97d2
Tests: more resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
361
diff
changeset
|
258 $s->send('RCPT TO:<test@example.com>'); |
8ca9c75c97d2
Tests: more resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
361
diff
changeset
|
259 $s->ok('uncompressed PTR'); |
8ca9c75c97d2
Tests: more resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
361
diff
changeset
|
260 |
8ca9c75c97d2
Tests: more resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
361
diff
changeset
|
261 $s->send('QUIT'); |
8ca9c75c97d2
Tests: more resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
361
diff
changeset
|
262 $s->read(); |
8ca9c75c97d2
Tests: more resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
361
diff
changeset
|
263 |
970
c227348453db
Tests: simplified parallel modifications in mail tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
952
diff
changeset
|
264 $s = Test::Nginx::SMTP->new(PeerAddr => '127.0.0.1:' . port(8031)); |
362
8ca9c75c97d2
Tests: more resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
361
diff
changeset
|
265 $s->read(); |
8ca9c75c97d2
Tests: more resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
361
diff
changeset
|
266 $s->send('EHLO example.com'); |
8ca9c75c97d2
Tests: more resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
361
diff
changeset
|
267 $s->read(); |
8ca9c75c97d2
Tests: more resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
361
diff
changeset
|
268 $s->send('MAIL FROM:<test@example.com> SIZE=100'); |
8ca9c75c97d2
Tests: more resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
361
diff
changeset
|
269 $s->read(); |
8ca9c75c97d2
Tests: more resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
361
diff
changeset
|
270 |
8ca9c75c97d2
Tests: more resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
361
diff
changeset
|
271 $s->send('RCPT TO:<test@example.com>'); |
8ca9c75c97d2
Tests: more resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
361
diff
changeset
|
272 $s->check(qr/TEMPUNAVAIL/, 'PTR type'); |
8ca9c75c97d2
Tests: more resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
361
diff
changeset
|
273 |
8ca9c75c97d2
Tests: more resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
361
diff
changeset
|
274 $s->send('QUIT'); |
8ca9c75c97d2
Tests: more resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
361
diff
changeset
|
275 $s->read(); |
8ca9c75c97d2
Tests: more resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
361
diff
changeset
|
276 |
809
ded6b7648d6e
Tests: added mail resolver test for CNAME and PTR records combined.
Sergey Kandaurov <pluknet@nginx.com>
parents:
806
diff
changeset
|
277 # CNAME and PTR in one answer section |
ded6b7648d6e
Tests: added mail resolver test for CNAME and PTR records combined.
Sergey Kandaurov <pluknet@nginx.com>
parents:
806
diff
changeset
|
278 |
970
c227348453db
Tests: simplified parallel modifications in mail tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
952
diff
changeset
|
279 $s = Test::Nginx::SMTP->new(PeerAddr => '127.0.0.1:' . port(8032)); |
809
ded6b7648d6e
Tests: added mail resolver test for CNAME and PTR records combined.
Sergey Kandaurov <pluknet@nginx.com>
parents:
806
diff
changeset
|
280 $s->read(); |
ded6b7648d6e
Tests: added mail resolver test for CNAME and PTR records combined.
Sergey Kandaurov <pluknet@nginx.com>
parents:
806
diff
changeset
|
281 $s->send('EHLO example.com'); |
ded6b7648d6e
Tests: added mail resolver test for CNAME and PTR records combined.
Sergey Kandaurov <pluknet@nginx.com>
parents:
806
diff
changeset
|
282 $s->read(); |
ded6b7648d6e
Tests: added mail resolver test for CNAME and PTR records combined.
Sergey Kandaurov <pluknet@nginx.com>
parents:
806
diff
changeset
|
283 $s->send('MAIL FROM:<test@example.com> SIZE=100'); |
ded6b7648d6e
Tests: added mail resolver test for CNAME and PTR records combined.
Sergey Kandaurov <pluknet@nginx.com>
parents:
806
diff
changeset
|
284 $s->read(); |
ded6b7648d6e
Tests: added mail resolver test for CNAME and PTR records combined.
Sergey Kandaurov <pluknet@nginx.com>
parents:
806
diff
changeset
|
285 |
ded6b7648d6e
Tests: added mail resolver test for CNAME and PTR records combined.
Sergey Kandaurov <pluknet@nginx.com>
parents:
806
diff
changeset
|
286 $s->send('RCPT TO:<test@example.com>'); |
ded6b7648d6e
Tests: added mail resolver test for CNAME and PTR records combined.
Sergey Kandaurov <pluknet@nginx.com>
parents:
806
diff
changeset
|
287 $s->ok('CNAME with PTR'); |
ded6b7648d6e
Tests: added mail resolver test for CNAME and PTR records combined.
Sergey Kandaurov <pluknet@nginx.com>
parents:
806
diff
changeset
|
288 |
ded6b7648d6e
Tests: added mail resolver test for CNAME and PTR records combined.
Sergey Kandaurov <pluknet@nginx.com>
parents:
806
diff
changeset
|
289 $s->send('QUIT'); |
ded6b7648d6e
Tests: added mail resolver test for CNAME and PTR records combined.
Sergey Kandaurov <pluknet@nginx.com>
parents:
806
diff
changeset
|
290 $s->read(); |
ded6b7648d6e
Tests: added mail resolver test for CNAME and PTR records combined.
Sergey Kandaurov <pluknet@nginx.com>
parents:
806
diff
changeset
|
291 |
1496
e1eb3432487b
Tests: added mail resolver tests with ssl.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1494
diff
changeset
|
292 # before 1.17.3, read event while in resolving resulted in duplicate resolving |
e1eb3432487b
Tests: added mail resolver tests with ssl.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1494
diff
changeset
|
293 |
e1eb3432487b
Tests: added mail resolver tests with ssl.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1494
diff
changeset
|
294 my %ssl = ( |
e1eb3432487b
Tests: added mail resolver tests with ssl.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1494
diff
changeset
|
295 SSL => 1, |
e1eb3432487b
Tests: added mail resolver tests with ssl.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1494
diff
changeset
|
296 SSL_verify_mode => IO::Socket::SSL::SSL_VERIFY_NONE(), |
e1eb3432487b
Tests: added mail resolver tests with ssl.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1494
diff
changeset
|
297 SSL_error_trap => sub { die $_[1] }, |
e1eb3432487b
Tests: added mail resolver tests with ssl.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1494
diff
changeset
|
298 ); |
e1eb3432487b
Tests: added mail resolver tests with ssl.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1494
diff
changeset
|
299 |
e1eb3432487b
Tests: added mail resolver tests with ssl.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1494
diff
changeset
|
300 $s = Test::Nginx::SMTP->new(PeerAddr => '127.0.0.1:' . port(8033), %ssl); |
e1eb3432487b
Tests: added mail resolver tests with ssl.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1494
diff
changeset
|
301 $s->send('EHLO example.com'); |
e1eb3432487b
Tests: added mail resolver tests with ssl.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1494
diff
changeset
|
302 $s->read(); |
e1eb3432487b
Tests: added mail resolver tests with ssl.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1494
diff
changeset
|
303 $s->send('MAIL FROM:<test@example.com> SIZE=100'); |
e1eb3432487b
Tests: added mail resolver tests with ssl.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1494
diff
changeset
|
304 $s->read(); |
e1eb3432487b
Tests: added mail resolver tests with ssl.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1494
diff
changeset
|
305 $s->read(); |
e1eb3432487b
Tests: added mail resolver tests with ssl.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1494
diff
changeset
|
306 |
e1eb3432487b
Tests: added mail resolver tests with ssl.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1494
diff
changeset
|
307 $s->send('RCPT TO:<test@example.com>'); |
e1eb3432487b
Tests: added mail resolver tests with ssl.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1494
diff
changeset
|
308 $s->check(qr/TEMPUNAVAIL/, 'PTR SSL empty'); |
e1eb3432487b
Tests: added mail resolver tests with ssl.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1494
diff
changeset
|
309 |
e1eb3432487b
Tests: added mail resolver tests with ssl.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1494
diff
changeset
|
310 $s->send('QUIT'); |
e1eb3432487b
Tests: added mail resolver tests with ssl.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1494
diff
changeset
|
311 $s->read(); |
e1eb3432487b
Tests: added mail resolver tests with ssl.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1494
diff
changeset
|
312 |
352
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
313 ############################################################################### |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
314 |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
315 sub reply_handler { |
357
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
355
diff
changeset
|
316 my ($recv_data, $port) = @_; |
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
355
diff
changeset
|
317 |
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
355
diff
changeset
|
318 my (@name, @rdata); |
352
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
319 |
357
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
355
diff
changeset
|
320 use constant NOERROR => 0; |
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
355
diff
changeset
|
321 use constant SERVFAIL => 2; |
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
355
diff
changeset
|
322 use constant NXDOMAIN => 3; |
352
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
323 |
357
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
355
diff
changeset
|
324 use constant A => 1; |
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
355
diff
changeset
|
325 use constant CNAME => 5; |
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
355
diff
changeset
|
326 use constant PTR => 12; |
937
b1fa8e0cc27b
Tests: whitespaces fix.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
906
diff
changeset
|
327 use constant DNAME => 39; |
357
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
355
diff
changeset
|
328 |
937
b1fa8e0cc27b
Tests: whitespaces fix.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
906
diff
changeset
|
329 use constant IN => 1; |
352
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
330 |
357
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
355
diff
changeset
|
331 # default values |
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
355
diff
changeset
|
332 |
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
355
diff
changeset
|
333 my ($hdr, $rcode, $ttl) = (0x8180, NOERROR, 3600); |
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
355
diff
changeset
|
334 |
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
355
diff
changeset
|
335 # decode name |
352
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
336 |
357
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
355
diff
changeset
|
337 my ($len, $offset) = (undef, 12); |
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
355
diff
changeset
|
338 while (1) { |
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
355
diff
changeset
|
339 $len = unpack("\@$offset C", $recv_data); |
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
355
diff
changeset
|
340 last if $len == 0; |
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
355
diff
changeset
|
341 $offset++; |
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
355
diff
changeset
|
342 push @name, unpack("\@$offset A$len", $recv_data); |
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
355
diff
changeset
|
343 $offset += $len; |
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
355
diff
changeset
|
344 } |
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
355
diff
changeset
|
345 |
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
355
diff
changeset
|
346 $offset -= 1; |
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
355
diff
changeset
|
347 my ($id, $type, $class) = unpack("n x$offset n2", $recv_data); |
352
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
348 |
357
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
355
diff
changeset
|
349 my $name = join('.', @name); |
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
355
diff
changeset
|
350 if ($name eq 'a.example.net' && $type == A) { |
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
355
diff
changeset
|
351 push @rdata, rd_addr($ttl, '127.0.0.1'); |
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
355
diff
changeset
|
352 |
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
355
diff
changeset
|
353 } elsif ($name eq '1.0.0.127.in-addr.arpa' && $type == PTR) { |
1237
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1215
diff
changeset
|
354 if ($port == port(8981)) { |
357
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
355
diff
changeset
|
355 push @rdata, rd_name(PTR, $ttl, 'a.example.net'); |
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
355
diff
changeset
|
356 |
1237
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1215
diff
changeset
|
357 } elsif ($port == port(8982)) { |
357
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
355
diff
changeset
|
358 $rcode = SERVFAIL; |
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
355
diff
changeset
|
359 |
1237
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1215
diff
changeset
|
360 } elsif ($port == port(8983)) { |
352
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
361 # zero length RDATA |
357
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
355
diff
changeset
|
362 |
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
355
diff
changeset
|
363 push @rdata, pack("n3N n", 0xc00c, PTR, IN, $ttl, 0); |
352
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
364 |
1237
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1215
diff
changeset
|
365 } elsif ($port == port(8984)) { |
352
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
366 # PTR answered with CNAME |
357
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
355
diff
changeset
|
367 |
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
355
diff
changeset
|
368 push @rdata, rd_name(CNAME, $ttl, |
352
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
369 '1.1.0.0.127.in-addr.arpa'); |
362
8ca9c75c97d2
Tests: more resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
361
diff
changeset
|
370 |
1237
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1215
diff
changeset
|
371 } elsif ($port == port(8985)) { |
362
8ca9c75c97d2
Tests: more resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
361
diff
changeset
|
372 # uncompressed answer |
8ca9c75c97d2
Tests: more resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
361
diff
changeset
|
373 |
775
a6764c2a9f12
Tests: fixed DNS label coding in resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
540
diff
changeset
|
374 push @rdata, pack("(C/a*)6x n2N n(C/a*)3x", |
362
8ca9c75c97d2
Tests: more resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
361
diff
changeset
|
375 ('1', '0', '0', '127', 'in-addr', 'arpa'), |
8ca9c75c97d2
Tests: more resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
361
diff
changeset
|
376 PTR, IN, $ttl, 15, ('a', 'example', 'net')); |
8ca9c75c97d2
Tests: more resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
361
diff
changeset
|
377 |
1237
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1215
diff
changeset
|
378 } elsif ($port == port(8986)) { |
806
ffdd33c64193
Tests: use DNAME type in PTR type checking test in mail_resolver.t.
Sergey Kandaurov <pluknet@nginx.com>
parents:
775
diff
changeset
|
379 push @rdata, rd_name(DNAME, $ttl, 'a.example.net'); |
ffdd33c64193
Tests: use DNAME type in PTR type checking test in mail_resolver.t.
Sergey Kandaurov <pluknet@nginx.com>
parents:
775
diff
changeset
|
380 |
1237
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1215
diff
changeset
|
381 } elsif ($port == port(8987)) { |
809
ded6b7648d6e
Tests: added mail resolver test for CNAME and PTR records combined.
Sergey Kandaurov <pluknet@nginx.com>
parents:
806
diff
changeset
|
382 # PTR answered with CNAME+PTR |
ded6b7648d6e
Tests: added mail resolver test for CNAME and PTR records combined.
Sergey Kandaurov <pluknet@nginx.com>
parents:
806
diff
changeset
|
383 |
ded6b7648d6e
Tests: added mail resolver test for CNAME and PTR records combined.
Sergey Kandaurov <pluknet@nginx.com>
parents:
806
diff
changeset
|
384 push @rdata, rd_name(CNAME, $ttl, |
ded6b7648d6e
Tests: added mail resolver test for CNAME and PTR records combined.
Sergey Kandaurov <pluknet@nginx.com>
parents:
806
diff
changeset
|
385 '1.1.0.0.127.in-addr.arpa'); |
ded6b7648d6e
Tests: added mail resolver test for CNAME and PTR records combined.
Sergey Kandaurov <pluknet@nginx.com>
parents:
806
diff
changeset
|
386 push @rdata, pack("n3N n(C/a*)3 x", 0xc034, |
ded6b7648d6e
Tests: added mail resolver test for CNAME and PTR records combined.
Sergey Kandaurov <pluknet@nginx.com>
parents:
806
diff
changeset
|
387 PTR, IN, $ttl, 15, ('a', 'example', 'net')); |
352
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
388 } |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
389 |
357
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
355
diff
changeset
|
390 } elsif ($name eq '1.1.0.0.127.in-addr.arpa' && $type == PTR) { |
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
355
diff
changeset
|
391 push @rdata, rd_name(PTR, $ttl, 'a.example.net'); |
352
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
392 } |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
393 |
357
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
355
diff
changeset
|
394 $len = @name; |
775
a6764c2a9f12
Tests: fixed DNS label coding in resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
540
diff
changeset
|
395 pack("n6 (C/a*)$len x n2", $id, $hdr | $rcode, 1, scalar @rdata, |
357
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
355
diff
changeset
|
396 0, 0, @name, $type, $class) . join('', @rdata); |
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
355
diff
changeset
|
397 } |
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
355
diff
changeset
|
398 |
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
355
diff
changeset
|
399 sub rd_name { |
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
355
diff
changeset
|
400 my ($type, $ttl, $name) = @_; |
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
355
diff
changeset
|
401 my ($rdlen, @rdname); |
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
355
diff
changeset
|
402 |
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
355
diff
changeset
|
403 @rdname = split /\./, $name; |
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
355
diff
changeset
|
404 $rdlen = length(join '', @rdname) + @rdname + 1; |
775
a6764c2a9f12
Tests: fixed DNS label coding in resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
540
diff
changeset
|
405 pack("n3N n(C/a*)* x", 0xc00c, $type, IN, $ttl, $rdlen, @rdname); |
357
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
355
diff
changeset
|
406 } |
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
355
diff
changeset
|
407 |
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
355
diff
changeset
|
408 sub rd_addr { |
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
355
diff
changeset
|
409 my ($ttl, $addr) = @_; |
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
355
diff
changeset
|
410 |
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
355
diff
changeset
|
411 my $code = 'split(/\./, $addr)'; |
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
355
diff
changeset
|
412 |
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
355
diff
changeset
|
413 # use a special pack string to not zero pad |
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
355
diff
changeset
|
414 |
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
355
diff
changeset
|
415 return pack 'n3N', 0xc00c, A, IN, $ttl if $addr eq ''; |
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
355
diff
changeset
|
416 |
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
355
diff
changeset
|
417 pack 'n3N nC4', 0xc00c, A, IN, $ttl, eval "scalar $code", eval($code); |
352
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
418 } |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
419 |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
420 sub dns_daemon { |
357
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
355
diff
changeset
|
421 my ($port, $t) = @_; |
352
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
422 |
357
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
355
diff
changeset
|
423 my ($data, $recv_data); |
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
355
diff
changeset
|
424 my $socket = IO::Socket::INET->new( |
937
b1fa8e0cc27b
Tests: whitespaces fix.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
906
diff
changeset
|
425 LocalAddr => '127.0.0.1', |
b1fa8e0cc27b
Tests: whitespaces fix.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
906
diff
changeset
|
426 LocalPort => $port, |
b1fa8e0cc27b
Tests: whitespaces fix.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
906
diff
changeset
|
427 Proto => 'udp', |
352
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
428 ) |
357
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
355
diff
changeset
|
429 or die "Can't create listening socket: $!\n"; |
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
355
diff
changeset
|
430 |
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
355
diff
changeset
|
431 # signal we are ready |
352
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
432 |
357
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
355
diff
changeset
|
433 open my $fh, '>', $t->testdir() . '/' . $port; |
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
355
diff
changeset
|
434 close $fh; |
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
355
diff
changeset
|
435 |
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
355
diff
changeset
|
436 while (1) { |
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
355
diff
changeset
|
437 $socket->recv($recv_data, 65536); |
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
355
diff
changeset
|
438 $data = reply_handler($recv_data, $port); |
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
355
diff
changeset
|
439 $socket->send($data); |
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
355
diff
changeset
|
440 } |
352
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
441 } |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
442 |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
443 ############################################################################### |