Mercurial > hg > nginx-tests
annotate scgi_cache.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 | 196d33c2bb45 |
children |
rev | line source |
---|---|
308 | 1 #!/usr/bin/perl |
2 | |
3 # (C) Maxim Dounin | |
4 | |
5 # Tests for scgi_cache. | |
6 | |
7 ############################################################################### | |
8 | |
9 use warnings; | |
10 use strict; | |
11 | |
12 use Test::More; | |
13 use Socket qw/ CRLF /; | |
14 | |
15 BEGIN { use FindBin; chdir($FindBin::Bin); } | |
16 | |
17 use lib 'lib'; | |
18 use Test::Nginx; | |
19 | |
20 ############################################################################### | |
21 | |
22 select STDERR; $| = 1; | |
23 select STDOUT; $| = 1; | |
24 | |
25 eval { require SCGI; }; | |
26 plan(skip_all => 'SCGI not installed') if $@; | |
27 | |
1020
196d33c2bb45
Tests: removed TODO and try_run() checks for legacy versions.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
974
diff
changeset
|
28 my $t = Test::Nginx->new()->has(qw/http scgi cache/)->plan(10) |
308 | 29 ->write_file_expand('nginx.conf', <<'EOF'); |
30 | |
31 %%TEST_GLOBALS%% | |
32 | |
33 daemon off; | |
34 | |
35 events { | |
36 } | |
37 | |
38 http { | |
39 %%TEST_GLOBALS_HTTP%% | |
40 | |
41 scgi_cache_path %%TESTDIR%%/cache keys_zone=one:1m; | |
42 scgi_cache_key $request_uri; | |
43 | |
44 add_header X-Cache-Status $upstream_cache_status; | |
45 | |
46 server { | |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
960
diff
changeset
|
47 listen 127.0.0.1:8080; |
308 | 48 server_name localhost; |
49 | |
50 location / { | |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
960
diff
changeset
|
51 scgi_pass 127.0.0.1:8081; |
308 | 52 scgi_param SCGI 1; |
53 scgi_param REQUEST_URI $uri; | |
54 scgi_cache one; | |
55 } | |
56 } | |
57 } | |
58 | |
59 EOF | |
60 | |
61 $t->run_daemon(\&scgi_daemon); | |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
960
diff
changeset
|
62 $t->run()->waitforsocket('127.0.0.1:' . port(8081)); |
308 | 63 |
64 ############################################################################### | |
65 | |
66 like(http_get('/len'), qr/MISS/, 'length'); | |
67 like(http_get('/len'), qr/HIT/, 'length cached'); | |
68 | |
69 like(http_get('/nolen'), qr/MISS/, 'no length'); | |
70 like(http_get('/nolen'), qr/HIT/, 'no length cached'); | |
71 | |
72 like(http_get('/len/empty'), qr/MISS/, 'empty length'); | |
73 like(http_get('/len/empty'), qr/HIT/, 'empty length cached'); | |
74 | |
75 like(http_get('/nolen/empty'), qr/MISS/, 'empty no length'); | |
76 like(http_get('/nolen/empty'), qr/HIT/, 'empty no length cached'); | |
77 | |
78 like(http_get('/unfinished'), qr/MISS/, 'unfinished'); | |
79 like(http_get('/unfinished'), qr/MISS/, 'unfinished not cached'); | |
80 | |
81 ############################################################################### | |
82 | |
83 sub scgi_daemon { | |
84 my $server = IO::Socket::INET->new( | |
85 Proto => 'tcp', | |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
960
diff
changeset
|
86 LocalHost => '127.0.0.1:' . port(8081), |
308 | 87 Listen => 5, |
88 Reuse => 1 | |
89 ) | |
90 or die "Can't create listening socket: $!\n"; | |
91 | |
92 my $scgi = SCGI->new($server, blocking => 1); | |
93 my %count; | |
94 | |
95 while (my $request = $scgi->accept()) { | |
960
d4a0232425ee
Tests: fixed race in SCGI tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
952
diff
changeset
|
96 eval { $request->read_env(); }; |
d4a0232425ee
Tests: fixed race in SCGI tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
952
diff
changeset
|
97 next if $@; |
308 | 98 |
99 my $uri = $request->env->{REQUEST_URI} || ''; | |
100 my $c = $request->connection(); | |
101 | |
102 $count{$uri} ||= 0; | |
103 $count{$uri}++; | |
104 | |
105 if ($uri eq '/len') { | |
106 $c->print( | |
107 "Content-Length: 9" . CRLF . | |
108 "Content-Type: text/html" . CRLF . | |
109 "Cache-Control: max-age=300" . CRLF . CRLF . | |
110 "test body" | |
111 ); | |
112 | |
113 } elsif ($uri eq '/nolen') { | |
114 $c->print( | |
115 "Content-Type: text/html" . CRLF . | |
116 "Cache-Control: max-age=300" . CRLF . CRLF . | |
117 "test body" | |
118 ); | |
119 | |
120 } elsif ($uri eq '/len/empty') { | |
121 $c->print( | |
122 "Content-Length: 0" . CRLF . | |
123 "Content-Type: text/html" . CRLF . | |
124 "Cache-Control: max-age=300" . CRLF . CRLF | |
125 ); | |
126 | |
127 } elsif ($uri eq '/nolen/empty') { | |
128 $c->print( | |
129 "Content-Type: text/html" . CRLF . | |
130 "Cache-Control: max-age=300" . CRLF . CRLF | |
131 ); | |
132 | |
133 } elsif ($uri eq '/unfinished') { | |
134 $c->print( | |
135 "Content-Length: 10" . CRLF . | |
136 "Content-Type: text/html" . CRLF . | |
137 "Cache-Control: max-age=300" . CRLF . CRLF | |
138 ); | |
139 } | |
140 } | |
141 } | |
142 | |
143 ############################################################################### |