Mercurial > hg > nginx-tests
annotate config_dump.t @ 1974:b5036a0f9ae0 default tip
Tests: improved compatibility when using recent "openssl" app.
Starting with OpenSSL 3.0, "openssl genrsa" generates encrypted keys
in PKCS#8 format instead of previously used PKCS#1 format. Further,
since OpenSSL 1.1.0 such keys are using PBKDF2 hmacWithSHA256.
Such keys are not supported by old SSL libraries, notably by OpenSSL
before 1.0.0 (OpenSSL 0.9.8 only supports hmacWithSHA1) and by BoringSSL
before May 21, 2019 (support for hmacWithSHA256 was added in 302a4dee6c),
and trying to load such keys into nginx compiled with an old SSL library
results in "unsupported prf" errors.
To facilitate testing with old SSL libraries, keys are now generated
with "openssl genrsa -traditional" if the flag is available.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Mon, 06 May 2024 00:04:26 +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 ############################################################################### |