Mercurial > hg > nginx-tests
annotate mirror.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 | 97c8280de681 |
children |
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 ############################################################################### |