Mercurial > hg > nginx-tests
annotate scgi.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 | be3ada2e9d24 |
rev | line source |
---|---|
158 | 1 #!/usr/bin/perl |
2 | |
3 # (C) Maxim Dounin | |
4 | |
5 # Test for scgi backend. | |
6 | |
7 ############################################################################### | |
8 | |
9 use warnings; | |
10 use strict; | |
11 | |
12 use Test::More; | |
13 | |
14 BEGIN { use FindBin; chdir($FindBin::Bin); } | |
15 | |
16 use lib 'lib'; | |
17 use Test::Nginx; | |
18 | |
19 ############################################################################### | |
20 | |
21 select STDERR; $| = 1; | |
22 select STDOUT; $| = 1; | |
23 | |
24 eval { require SCGI; }; | |
25 plan(skip_all => 'SCGI not installed') if $@; | |
26 | |
802
eca9b1d19021
Tests: tests for host expansion to an explicit upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
801
diff
changeset
|
27 my $t = Test::Nginx->new()->has(qw/http scgi/)->plan(7) |
158 | 28 ->write_file_expand('nginx.conf', <<'EOF'); |
29 | |
30 %%TEST_GLOBALS%% | |
31 | |
249
6a0d934950bc
Tests: remove extra spaces in "daemon off".
Maxim Dounin <mdounin@mdounin.ru>
parents:
241
diff
changeset
|
32 daemon off; |
158 | 33 |
34 events { | |
35 } | |
36 | |
37 http { | |
38 %%TEST_GLOBALS_HTTP%% | |
39 | |
802
eca9b1d19021
Tests: tests for host expansion to an explicit upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
801
diff
changeset
|
40 upstream u { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
960
diff
changeset
|
41 server 127.0.0.1:8081; |
802
eca9b1d19021
Tests: tests for host expansion to an explicit upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
801
diff
changeset
|
42 } |
eca9b1d19021
Tests: tests for host expansion to an explicit upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
801
diff
changeset
|
43 |
158 | 44 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
960
diff
changeset
|
45 listen 127.0.0.1:8080; |
158 | 46 server_name localhost; |
47 | |
48 location / { | |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
960
diff
changeset
|
49 scgi_pass 127.0.0.1:8081; |
158 | 50 scgi_param SCGI 1; |
51 scgi_param REQUEST_URI $request_uri; | |
167
b8fdbc918280
Tests: add scgi headers_param test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
52 scgi_param HTTP_X_BLAH "blah"; |
158 | 53 } |
801
d95c4b8e5517
Tests: more tests for passing requests to host given by expression.
Sergey Kandaurov <pluknet@nginx.com>
parents:
590
diff
changeset
|
54 |
d95c4b8e5517
Tests: more tests for passing requests to host given by expression.
Sergey Kandaurov <pluknet@nginx.com>
parents:
590
diff
changeset
|
55 location /var { |
d95c4b8e5517
Tests: more tests for passing requests to host given by expression.
Sergey Kandaurov <pluknet@nginx.com>
parents:
590
diff
changeset
|
56 scgi_pass $arg_b; |
d95c4b8e5517
Tests: more tests for passing requests to host given by expression.
Sergey Kandaurov <pluknet@nginx.com>
parents:
590
diff
changeset
|
57 scgi_param SCGI 1; |
d95c4b8e5517
Tests: more tests for passing requests to host given by expression.
Sergey Kandaurov <pluknet@nginx.com>
parents:
590
diff
changeset
|
58 scgi_param REQUEST_URI $request_uri; |
d95c4b8e5517
Tests: more tests for passing requests to host given by expression.
Sergey Kandaurov <pluknet@nginx.com>
parents:
590
diff
changeset
|
59 } |
d95c4b8e5517
Tests: more tests for passing requests to host given by expression.
Sergey Kandaurov <pluknet@nginx.com>
parents:
590
diff
changeset
|
60 |
158 | 61 } |
62 } | |
63 | |
64 EOF | |
65 | |
66 $t->run_daemon(\&scgi_daemon); | |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
960
diff
changeset
|
67 $t->run()->waitforsocket('127.0.0.1:' . port(8081)); |
158 | 68 |
69 ############################################################################### | |
70 | |
71 like(http_get('/'), qr/SEE-THIS/, 'scgi request'); | |
491
d5bf5942a8b2
Tests: disambiguated parsing of the status code.
Sergey Kandaurov <pluknet@nginx.com>
parents:
249
diff
changeset
|
72 like(http_get('/redir'), qr/ 302 /, 'scgi redirect'); |
158 | 73 like(http_get('/'), qr/^3$/m, 'scgi third request'); |
74 | |
75 unlike(http_head('/'), qr/SEE-THIS/, 'no data in HEAD'); | |
76 | |
167
b8fdbc918280
Tests: add scgi headers_param test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
77 like(http_get_headers('/headers'), qr/SEE-THIS/, |
b8fdbc918280
Tests: add scgi headers_param test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
78 'scgi request with many ignored headers'); |
b8fdbc918280
Tests: add scgi headers_param test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
79 |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
960
diff
changeset
|
80 like(http_get('/var?b=127.0.0.1:' . port(8081)), qr/SEE-THIS/, |
952
e9064d691790
Tests: converted tests to run in parallel.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
802
diff
changeset
|
81 'scgi with variables'); |
802
eca9b1d19021
Tests: tests for host expansion to an explicit upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
801
diff
changeset
|
82 like(http_get('/var?b=u'), qr/SEE-THIS/, 'scgi with variables to upstream'); |
801
d95c4b8e5517
Tests: more tests for passing requests to host given by expression.
Sergey Kandaurov <pluknet@nginx.com>
parents:
590
diff
changeset
|
83 |
167
b8fdbc918280
Tests: add scgi headers_param test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
84 ############################################################################### |
b8fdbc918280
Tests: add scgi headers_param test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
85 |
b8fdbc918280
Tests: add scgi headers_param test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
86 sub http_get_headers { |
590
dc2f8aac0553
Tests: whitespace fixes.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
491
diff
changeset
|
87 my ($url, %extra) = @_; |
dc2f8aac0553
Tests: whitespace fixes.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
491
diff
changeset
|
88 return http(<<EOF, %extra); |
167
b8fdbc918280
Tests: add scgi headers_param test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
89 GET $url HTTP/1.0 |
b8fdbc918280
Tests: add scgi headers_param test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
90 Host: localhost |
b8fdbc918280
Tests: add scgi headers_param test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
91 X-Blah: ignored header |
b8fdbc918280
Tests: add scgi headers_param test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
92 X-Blah: ignored header |
b8fdbc918280
Tests: add scgi headers_param test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
93 X-Blah: ignored header |
b8fdbc918280
Tests: add scgi headers_param test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
94 X-Blah: ignored header |
b8fdbc918280
Tests: add scgi headers_param test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
95 X-Blah: ignored header |
b8fdbc918280
Tests: add scgi headers_param test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
96 X-Blah: ignored header |
b8fdbc918280
Tests: add scgi headers_param test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
97 X-Blah: ignored header |
b8fdbc918280
Tests: add scgi headers_param test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
98 X-Blah: ignored header |
b8fdbc918280
Tests: add scgi headers_param test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
99 X-Blah: ignored header |
b8fdbc918280
Tests: add scgi headers_param test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
100 X-Blah: ignored header |
b8fdbc918280
Tests: add scgi headers_param test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
101 X-Blah: ignored header |
b8fdbc918280
Tests: add scgi headers_param test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
102 X-Blah: ignored header |
b8fdbc918280
Tests: add scgi headers_param test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
103 X-Blah: ignored header |
b8fdbc918280
Tests: add scgi headers_param test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
104 X-Blah: ignored header |
b8fdbc918280
Tests: add scgi headers_param test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
105 X-Blah: ignored header |
b8fdbc918280
Tests: add scgi headers_param test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
106 X-Blah: ignored header |
b8fdbc918280
Tests: add scgi headers_param test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
107 X-Blah: ignored header |
b8fdbc918280
Tests: add scgi headers_param test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
108 X-Blah: ignored header |
b8fdbc918280
Tests: add scgi headers_param test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
109 X-Blah: ignored header |
b8fdbc918280
Tests: add scgi headers_param test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
110 |
b8fdbc918280
Tests: add scgi headers_param test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
111 EOF |
b8fdbc918280
Tests: add scgi headers_param test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
112 } |
b8fdbc918280
Tests: add scgi headers_param test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
113 |
158 | 114 ############################################################################### |
115 | |
116 sub scgi_daemon { | |
117 my $server = IO::Socket::INET->new( | |
118 Proto => 'tcp', | |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
960
diff
changeset
|
119 LocalHost => '127.0.0.1:' . port(8081), |
158 | 120 Listen => 5, |
121 Reuse => 1 | |
122 ) | |
123 or die "Can't create listening socket: $!\n"; | |
124 | |
125 my $scgi = SCGI->new($server, blocking => 1); | |
126 my $count = 0; | |
212 | 127 |
158 | 128 while (my $request = $scgi->accept()) { |
960
d4a0232425ee
Tests: fixed race in SCGI tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
952
diff
changeset
|
129 eval { $request->read_env(); }; |
d4a0232425ee
Tests: fixed race in SCGI tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
952
diff
changeset
|
130 next if $@; |
d4a0232425ee
Tests: fixed race in SCGI tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
952
diff
changeset
|
131 |
158 | 132 $count++; |
133 | |
134 $request->connection()->print(<<EOF); | |
952
e9064d691790
Tests: converted tests to run in parallel.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
802
diff
changeset
|
135 Location: http://localhost/redirect |
158 | 136 Content-Type: text/html |
137 | |
138 SEE-THIS | |
139 $count | |
140 EOF | |
141 } | |
142 } | |
143 | |
144 ############################################################################### |