annotate mirror.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 97c8280de681
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1208
a6453cf5786a Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1 #!/usr/bin/perl
a6453cf5786a Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
2
a6453cf5786a Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
3 # (C) Sergey Kandaurov
a6453cf5786a Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
4 # (C) Nginx, Inc.
a6453cf5786a Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
5
a6453cf5786a Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
6 # Tests for http mirror module.
a6453cf5786a Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
7
a6453cf5786a Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
8 ###############################################################################
a6453cf5786a Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
9
a6453cf5786a Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
10 use warnings;
a6453cf5786a Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
11 use strict;
a6453cf5786a Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
12
a6453cf5786a Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
13 use Test::More;
a6453cf5786a Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
14
a6453cf5786a Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
15 BEGIN { use FindBin; chdir($FindBin::Bin); }
a6453cf5786a Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
16
a6453cf5786a Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
17 use lib 'lib';
a6453cf5786a Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
18 use Test::Nginx;
a6453cf5786a Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
19
a6453cf5786a Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
20 ###############################################################################
a6453cf5786a Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
21
a6453cf5786a Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
22 select STDERR; $| = 1;
a6453cf5786a Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
23 select STDOUT; $| = 1;
a6453cf5786a Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
24
1381
97c8280de681 Tests: removed TODO and try_run() checks for legacy versions.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1208
diff changeset
25 my $t = Test::Nginx->new()->has(qw/http mirror/)->plan(8);
1208
a6453cf5786a Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
26
a6453cf5786a Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
27 $t->write_file_expand('nginx.conf', <<'EOF');
a6453cf5786a Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
28
a6453cf5786a Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
29 %%TEST_GLOBALS%%
a6453cf5786a Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
30
a6453cf5786a Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
31 daemon off;
a6453cf5786a Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
32
a6453cf5786a Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
33 events {
a6453cf5786a Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
34 }
a6453cf5786a Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
35
a6453cf5786a Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
36 http {
a6453cf5786a Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
37 %%TEST_GLOBALS_HTTP%%
a6453cf5786a Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
38
a6453cf5786a Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
39 log_format test $uri;
a6453cf5786a Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
40
a6453cf5786a Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
41 server {
a6453cf5786a Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
42 listen 127.0.0.1:8080;
a6453cf5786a Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
43 server_name localhost;
a6453cf5786a Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
44
a6453cf5786a Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
45 location / {
a6453cf5786a Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
46 mirror /mirror;
a6453cf5786a Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
47
a6453cf5786a Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
48 location /off {
a6453cf5786a Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
49 mirror off;
a6453cf5786a Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
50 }
a6453cf5786a Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
51 }
a6453cf5786a Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
52
a6453cf5786a Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
53 location /many {
a6453cf5786a Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
54 mirror /mirror/1;
a6453cf5786a Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
55 mirror /mirror/2;
a6453cf5786a Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
56 }
a6453cf5786a Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
57
a6453cf5786a Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
58 location /mirror {
a6453cf5786a Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
59 log_subrequest on;
a6453cf5786a Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
60 access_log test$args.log test;
a6453cf5786a Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
61 }
a6453cf5786a Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
62 }
a6453cf5786a Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
63 }
a6453cf5786a Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
64
a6453cf5786a Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
65 EOF
a6453cf5786a Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
66
a6453cf5786a Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
67 $t->write_file('index.html', '');
a6453cf5786a Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
68 $t->write_file('many', '');
a6453cf5786a Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
69 $t->write_file('off', '');
1381
97c8280de681 Tests: removed TODO and try_run() checks for legacy versions.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1208
diff changeset
70 $t->run();
1208
a6453cf5786a Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
71
a6453cf5786a Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
72 ###############################################################################
a6453cf5786a Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
73
a6453cf5786a Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
74 like(http_get('/index.html?1'), qr/200 OK/, 'request');
a6453cf5786a Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
75 like(http_get('/?2'), qr/200 OK/, 'internal redirect');
a6453cf5786a Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
76 like(http_get('/off?3'), qr/200 OK/, 'mirror off');
a6453cf5786a Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
77 like(http_get('/many?4'), qr/200 OK/, 'mirror many');
a6453cf5786a Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
78
a6453cf5786a Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
79 $t->stop();
a6453cf5786a Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
80
a6453cf5786a Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
81 is($t->read_file('test1.log'), "/mirror\n", 'log - request');
a6453cf5786a Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
82 is($t->read_file('test2.log'), "/mirror\n/mirror\n", 'log - redirect');
a6453cf5786a Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
83 ok(!-e $t->testdir() . '/test3.log', 'log - mirror off');
a6453cf5786a Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
84 is($t->read_file('test4.log'), "/mirror/1\n/mirror/2\n", 'log - mirror many');
a6453cf5786a Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
85
a6453cf5786a Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
86 ###############################################################################