annotate http_location_auto.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 882267679006
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
330
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
1 #!/usr/bin/perl
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
2
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
3 # (C) Maxim Dounin
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
4
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
5 # Tests for location selection, an auto_redirect edge case.
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
6
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
7 ###############################################################################
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
8
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
9 use warnings;
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
10 use strict;
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
11
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
12 use Test::More;
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
13
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
14 BEGIN { use FindBin; chdir($FindBin::Bin); }
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
15
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
16 use lib 'lib';
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
17 use Test::Nginx;
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
18
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
19 ###############################################################################
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
20
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
21 select STDERR; $| = 1;
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
22 select STDOUT; $| = 1;
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
23
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
24 my $t = Test::Nginx->new()->has(qw/http proxy rewrite/)->plan(4)
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
25 ->write_file_expand('nginx.conf', <<'EOF');
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
26
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
27 %%TEST_GLOBALS%%
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
28
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
29 daemon off;
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
30
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
31 events {
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
32 }
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
33
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
34 http {
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
35 %%TEST_GLOBALS_HTTP%%
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
36
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
37 server {
974
882267679006 Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 952
diff changeset
38 listen 127.0.0.1:8080;
330
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
39 server_name localhost;
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
40
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
41 proxy_hide_header X-Location;
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
42 add_header X-Location unset;
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
43
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
44 # As of nginx 1.5.4, this results in the following
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
45 # location tree:
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
46 #
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
47 # "/a-b"
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
48 # "/a-a" "/a/"
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
49 #
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
50 # A request to "/a" is expected to match "/a/" with auto_redirect,
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
51 # but with such a tree it tests locations "/a-b", "/a-a" and then
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
52 # falls back to null location.
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
53 #
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
54 # Key factor is that "-" is less than "/".
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
55
974
882267679006 Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 952
diff changeset
56 location /a/ { proxy_pass http://127.0.0.1:8080/a-a; }
330
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
57 location /a-a { add_header X-Location a-a; return 204; }
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
58 location /a-b { add_header X-Location a-b; return 204; }
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
59 }
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
60 }
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
61
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
62 EOF
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
63
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
64 $t->run();
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
65
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
66 ###############################################################################
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
67
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
68 like(http_get('/a'), qr/301 Moved/, 'auto redirect');
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
69 like(http_get('/a/'), qr/X-Location: unset/, 'match a');
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
70 like(http_get('/a-a'), qr/X-Location: a-a/, 'match a-a');
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
71 like(http_get('/a-b'), qr/X-Location: a-b/, 'match a-b');
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
72
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
73 ###############################################################################