Mercurial > hg > nginx-tests
annotate geo_binary.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 | 1fe8d33f75ad |
children |
rev | line source |
---|---|
1044
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2 |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
3 # (C) Andrey Zelenkov |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
4 # (C) Nginx, Inc. |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
5 |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
6 # Tests for nginx geo module with binary base. |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
7 |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
8 ############################################################################### |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
9 |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
10 use warnings; |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
11 use strict; |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
12 |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
13 use Test::More; |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
14 |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
15 BEGIN { use FindBin; chdir($FindBin::Bin); } |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
16 |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
17 use lib 'lib'; |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
18 use Test::Nginx; |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
19 |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
20 ############################################################################### |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
21 |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
22 select STDERR; $| = 1; |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
23 select STDOUT; $| = 1; |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
24 |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
25 plan(skip_all => 'long configuration parsing') unless $ENV{TEST_NGINX_UNSAFE}; |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
26 |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
27 my $t = Test::Nginx->new()->has(qw/http geo/); |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
28 |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
29 $t->write_file_expand('nginx.conf', <<'EOF'); |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
30 |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
31 %%TEST_GLOBALS%% |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
32 |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
33 daemon off; |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
34 |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
35 events { |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
36 } |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
37 |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
38 http { |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
39 %%TEST_GLOBALS_HTTP%% |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
40 |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
41 geo $geo_base_create { |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
42 ranges; |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
43 include base.conf; |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
44 } |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
45 |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
46 geo $geo_base_include { |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
47 ranges; |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
48 include base.conf; |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
49 } |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
50 |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
51 server { |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
52 listen 127.0.0.1:8080; |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
53 server_name localhost; |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
54 |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
55 location / { |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
56 add_header X-IP $remote_addr; |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
57 add_header X-GBc $geo_base_create; |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
58 add_header X-GBi $geo_base_include; |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
59 } |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
60 } |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
61 } |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
62 |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
63 EOF |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
64 |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
65 $t->write_file('1', ''); |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
66 $t->write_file('base.conf', join('', map { |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
67 "127." . $_/256/256 % 256 . "." . $_/256 % 256 . "." . $_ % 256 . |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
68 "-127." . $_/256/256 % 256 . "." . $_/256 % 256 . "." .$_ % 256 . " " . |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
69 ($_ == 1 ? "loopback" : "range$_") . ";" } (0 .. 100000))); |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
70 |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
71 $t->run(); |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
72 |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
73 plan(skip_all => 'no 127.0.0.1 on host') |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
74 if http_get('/1') !~ /X-IP: 127.0.0.1/m; |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
75 |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
76 $t->plan(2); |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
77 |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
78 ############################################################################### |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
79 |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
80 my $r = http_get('/1'); |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
81 like($r, qr/^X-GBc: loopback/m, 'geo binary base create'); |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
82 like($r, qr/^X-GBi: loopback/m, 'geo binary base include'); |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
83 |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
84 ############################################################################### |