Mercurial > hg > nginx-tests
annotate http_uri.t @ 1974:b5036a0f9ae0
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 | 2a0a6035a1af |
children |
rev | line source |
---|---|
1515
eb33558f731d
Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
eb33558f731d
Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2 |
eb33558f731d
Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
3 # (C) Sergey Kandaurov |
eb33558f731d
Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
4 # (C) Nginx, Inc. |
eb33558f731d
Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
5 |
eb33558f731d
Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
6 # Tests for URI normalization. |
eb33558f731d
Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
7 |
eb33558f731d
Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
8 ############################################################################### |
eb33558f731d
Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
9 |
eb33558f731d
Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
10 use warnings; |
eb33558f731d
Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
11 use strict; |
eb33558f731d
Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
12 |
eb33558f731d
Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
13 use Test::More; |
eb33558f731d
Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
14 |
eb33558f731d
Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
15 BEGIN { use FindBin; chdir($FindBin::Bin); } |
eb33558f731d
Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
16 |
eb33558f731d
Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
17 use lib 'lib'; |
eb33558f731d
Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
18 use Test::Nginx; |
eb33558f731d
Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
19 |
eb33558f731d
Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
20 ############################################################################### |
eb33558f731d
Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
21 |
eb33558f731d
Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
22 select STDERR; $| = 1; |
eb33558f731d
Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
23 select STDOUT; $| = 1; |
eb33558f731d
Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
24 |
1714
e4e711d07e6c
Tests: added URI tests with forbidden control characters.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1709
diff
changeset
|
25 my $t = Test::Nginx->new()->has(qw/http rewrite/)->plan(19) |
1515
eb33558f731d
Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
26 ->write_file_expand('nginx.conf', <<'EOF')->run(); |
eb33558f731d
Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
27 |
eb33558f731d
Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
28 %%TEST_GLOBALS%% |
eb33558f731d
Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
29 |
eb33558f731d
Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
30 daemon off; |
eb33558f731d
Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
31 |
eb33558f731d
Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
32 events { |
eb33558f731d
Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
33 } |
eb33558f731d
Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
34 |
eb33558f731d
Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
35 http { |
eb33558f731d
Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
36 %%TEST_GLOBALS_HTTP%% |
eb33558f731d
Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
37 |
eb33558f731d
Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
38 server { |
eb33558f731d
Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
39 listen 127.0.0.1:8080; |
eb33558f731d
Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
40 server_name localhost; |
eb33558f731d
Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
41 |
eb33558f731d
Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
42 location / { |
1635
7b80c8e0479a
Tests: absolute URI parsing tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1515
diff
changeset
|
43 add_header X-URI "x $uri x"; |
7b80c8e0479a
Tests: absolute URI parsing tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1515
diff
changeset
|
44 add_header X-Args "y $args y"; |
7b80c8e0479a
Tests: absolute URI parsing tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1515
diff
changeset
|
45 add_header X-Request-URI "z $request_uri z"; |
1515
eb33558f731d
Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
46 return 204; |
eb33558f731d
Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
47 } |
eb33558f731d
Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
48 } |
eb33558f731d
Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
49 } |
eb33558f731d
Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
50 |
eb33558f731d
Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
51 EOF |
eb33558f731d
Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
52 |
eb33558f731d
Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
53 ############################################################################### |
eb33558f731d
Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
54 |
eb33558f731d
Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
55 like(http_get('/foo/bar%'), qr/400 Bad/, 'percent'); |
eb33558f731d
Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
56 like(http_get('/foo/bar%1'), qr/400 Bad/, 'percent digit'); |
eb33558f731d
Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
57 |
eb33558f731d
Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
58 like(http_get('/foo/bar/.?args'), qr!x /foo/bar/ x!, 'dot args'); |
eb33558f731d
Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
59 like(http_get('/foo/bar/.#frag'), qr!x /foo/bar/ x!, 'dot frag'); |
eb33558f731d
Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
60 like(http_get('/foo/bar/..?args'), qr!x /foo/ x!, 'dot dot args'); |
eb33558f731d
Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
61 like(http_get('/foo/bar/..#frag'), qr!x /foo/ x!, 'dot dot frag'); |
eb33558f731d
Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
62 like(http_get('/foo/bar/.'), qr!x /foo/bar/ x!, 'trailing dot'); |
eb33558f731d
Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
63 like(http_get('/foo/bar/..'), qr!x /foo/ x!, 'trailing dot dot'); |
eb33558f731d
Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
64 |
1635
7b80c8e0479a
Tests: absolute URI parsing tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1515
diff
changeset
|
65 like(http_get('http://localhost'), qr!x / x!, 'absolute'); |
7b80c8e0479a
Tests: absolute URI parsing tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1515
diff
changeset
|
66 like(http_get('http://localhost/'), qr!x / x!, 'absolute slash'); |
7b80c8e0479a
Tests: absolute URI parsing tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1515
diff
changeset
|
67 like(http_get('http://localhost?args'), qr!x / x.*y args y!ms, |
7b80c8e0479a
Tests: absolute URI parsing tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1515
diff
changeset
|
68 'absolute args'); |
7b80c8e0479a
Tests: absolute URI parsing tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1515
diff
changeset
|
69 like(http_get('http://localhost?args#frag'), qr!x / x.*y args y!ms, |
7b80c8e0479a
Tests: absolute URI parsing tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1515
diff
changeset
|
70 'absolute args and frag'); |
7b80c8e0479a
Tests: absolute URI parsing tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1515
diff
changeset
|
71 |
7b80c8e0479a
Tests: absolute URI parsing tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1515
diff
changeset
|
72 like(http_get('http://localhost:8080'), qr!x / x!, 'port'); |
7b80c8e0479a
Tests: absolute URI parsing tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1515
diff
changeset
|
73 like(http_get('http://localhost:8080/'), qr!x / x!, 'port slash'); |
7b80c8e0479a
Tests: absolute URI parsing tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1515
diff
changeset
|
74 like(http_get('http://localhost:8080?args'), qr!x / x.*y args y!ms, |
7b80c8e0479a
Tests: absolute URI parsing tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1515
diff
changeset
|
75 'port args'); |
7b80c8e0479a
Tests: absolute URI parsing tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1515
diff
changeset
|
76 like(http_get('http://localhost:8080?args#frag'), qr!x / x.*y args y!ms, |
7b80c8e0479a
Tests: absolute URI parsing tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1515
diff
changeset
|
77 'port args and frag'); |
7b80c8e0479a
Tests: absolute URI parsing tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1515
diff
changeset
|
78 |
1706
9c79f41fdf9b
Tests: updated test for spaces in URI to expect HTTP 400.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1693
diff
changeset
|
79 like(http_get('/ /'), qr/400 Bad/, 'space'); |
1714
e4e711d07e6c
Tests: added URI tests with forbidden control characters.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1709
diff
changeset
|
80 like(http_get("/\x02"), qr/400 Bad/, 'control'); |
e4e711d07e6c
Tests: added URI tests with forbidden control characters.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1709
diff
changeset
|
81 |
e4e711d07e6c
Tests: added URI tests with forbidden control characters.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1709
diff
changeset
|
82 like(http_get('/%02'), qr!x /\x02 x!, 'control escaped'); |
e4e711d07e6c
Tests: added URI tests with forbidden control characters.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1709
diff
changeset
|
83 |
1515
eb33558f731d
Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
84 ############################################################################### |