Mercurial > hg > nginx-tests
annotate config_dump.t @ 1571:1b4ceab9cb1c
Tests: fixed ssl_certificate.t with LibreSSL client.
Net::SSLeay::connect() that manages TLS handshake could return unexpected
error when receiving server alert, as seen in server certificate tests if
it could not been selected. Typically, it returns the expected error -1,
but with certain libssl implementations it can be 0, as explained below.
The error is propagated from libssl's SSL_connect(), which is usually -1.
In modern OpenSSL versions, it is the default error code used in the state
machine returned when something went wrong with parsing TLS message header.
In versions up to OpenSSL 1.0.2, with SSLv23_method() used by default, -1
is the only error code in the ssl_connect() method implementation which is
used as well if receiving alert while parsing ServerHello. BoringSSL also
seems to return -1. But it is not so with LibreSSL that returns zero.
Previously, tests failed with client built with LibreSSL with SSLv3 removed.
Here, the error is propagated directly from ssl_read_bytes() method, which
is always implemented as ssl3_read_bytes() in all TLS methods. It could be
also seen with OpenSSL up to 1.0.2 with non-default methods explicitly set.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Fri, 29 May 2020 23:10:20 +0300 |
parents | 9d579fc770a6 |
children |
rev | line source |
---|---|
621
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2 |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
3 # (C) Sergey Kandaurov |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
4 # (C) Nginx, Inc. |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
5 |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
6 # Tests for dumped nginx configuration (nginx -T). |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
7 # Among other things, test that configuration blocks are properly processed. |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
8 |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
9 ############################################################################### |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
10 |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
11 use warnings; |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
12 use strict; |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
13 |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
14 use Test::More; |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
15 |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
16 BEGIN { use FindBin; chdir($FindBin::Bin); } |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
17 |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
18 use lib 'lib'; |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
19 use Test::Nginx; |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
20 |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
21 ############################################################################### |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
22 |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
23 select STDERR; $| = 1; |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
24 select STDOUT; $| = 1; |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
25 |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
26 my $t = Test::Nginx->new()->has(qw/http map/); |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
27 |
1060
a07205e8bb76
Tests: added "nginx -T" tests for unique dumped files.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1020
diff
changeset
|
28 $t->plan(13)->write_file_expand('nginx.conf', <<'EOF'); |
621
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
29 |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
30 %%TEST_GLOBALS%% |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
31 |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
32 daemon off; |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
33 |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
34 include %%TESTDIR%%/inc.conf; |
1060
a07205e8bb76
Tests: added "nginx -T" tests for unique dumped files.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1020
diff
changeset
|
35 include %%TESTDIR%%/inc.conf; |
621
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
36 |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
37 events { |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
38 } |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
39 |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
40 http { |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
41 %%TEST_GLOBALS_HTTP%% |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
42 |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
43 map $args $x { |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
44 default 0; |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
45 foo bar; |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
46 include map.conf; |
1060
a07205e8bb76
Tests: added "nginx -T" tests for unique dumped files.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1020
diff
changeset
|
47 include map.conf; |
621
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
48 } |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
49 |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
50 upstream u { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
51 server 127.0.0.1:8081; |
621
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
52 } |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
53 |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
54 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
55 listen 127.0.0.1:8080; |
621
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
56 server_name localhost; |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
57 |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
58 location / { } |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
59 } |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
60 } |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
61 |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
62 EOF |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
63 |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
64 $t->write_file('inc.conf', 'include inc2.conf;'); |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
65 $t->write_file('inc2.conf', '#inc2.conf'); |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
66 $t->write_file('map.conf', '#map.conf;'); |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
67 |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
68 $t->run(); |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
69 |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
70 ############################################################################### |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
71 |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
72 my $d = $t->testdir; |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
73 |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
74 my $dump = $t->dump_config(); |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
75 like($dump, qr!^# configuration file $d/nginx.conf:$!m, 'nginx.conf found'); |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
76 like($dump, qr!^# configuration file $d/inc.conf:$!m, 'inc.conf found'); |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
77 like($dump, qr!^# configuration file $d/inc2.conf:$!m, 'inc2.conf found'); |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
78 like($dump, qr!^# configuration file $d/map.conf:$!m, 'map.conf found'); |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
79 |
1060
a07205e8bb76
Tests: added "nginx -T" tests for unique dumped files.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1020
diff
changeset
|
80 unlike($dump, qr!(# configuration file $d/inc.conf:).*\1!s, 'inc.conf uniq'); |
a07205e8bb76
Tests: added "nginx -T" tests for unique dumped files.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1020
diff
changeset
|
81 unlike($dump, qr!(# configuration file $d/inc2.conf:).*\1!s, 'inc2.conf uniq'); |
a07205e8bb76
Tests: added "nginx -T" tests for unique dumped files.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1020
diff
changeset
|
82 unlike($dump, qr!(# configuration file $d/map.conf:).*\1!s, 'map.conf uniq'); |
a07205e8bb76
Tests: added "nginx -T" tests for unique dumped files.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1020
diff
changeset
|
83 |
621
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
84 is(getconf($t, $dump, 'nginx.conf'), $t->read_file('nginx.conf'), 'content'); |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
85 is(getconf($t, $dump, 'inc.conf'), $t->read_file('inc.conf'), 'content inc'); |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
86 is(getconf($t, $dump, 'map.conf'), $t->read_file('map.conf'), 'content inc 2'); |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
87 |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
88 unlink($t->testdir . "/inc.conf"); |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
89 unlink($t->testdir . "/map.conf"); |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
90 |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
91 $dump = $t->dump_config(); |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
92 unlike($dump, qr!file $d/inc.conf!, 'missing inc.conf'); |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
93 unlike($dump, qr!file $d/map.conf!, 'missing map.conf'); |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
94 like($dump, qr!file $d/nginx.conf test failed!, 'test failed'); |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
95 |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
96 $t->write_file('inc.conf', 'include inc2.conf;'); |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
97 $t->write_file('inc2.conf', '#inc2.conf'); |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
98 $t->write_file('map.conf', '#map.conf;'); |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
99 |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
100 ############################################################################### |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
101 |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
102 sub getconf { |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
103 my ($t, $string, $conf) = @_; |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
104 my $prefix = "# configuration file $d/$conf:\n"; |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
105 my $offset = index($string, $prefix) + length($prefix); |
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
106 my $len = length($t->read_file($conf)); |
624
1dd0e909fe94
Tests: compatibility with perl <= 5.12 in config_dump.t.
Sergey Kandaurov <pluknet@nginx.com>
parents:
621
diff
changeset
|
107 my $s = substr($string, $offset, $len); |
1dd0e909fe94
Tests: compatibility with perl <= 5.12 in config_dump.t.
Sergey Kandaurov <pluknet@nginx.com>
parents:
621
diff
changeset
|
108 $s =~ tr/\r//d; |
1dd0e909fe94
Tests: compatibility with perl <= 5.12 in config_dump.t.
Sergey Kandaurov <pluknet@nginx.com>
parents:
621
diff
changeset
|
109 return $s; |
621
884b2f0c173f
Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
110 } |
1451 | 111 |
112 ############################################################################### |