Mercurial > hg > nginx-tests
annotate uwsgi_ssl.t @ 1619:436d0ffc2ea3
Tests: correctly shutdown ssl for reproducible session reuse tests.
Previously, session reuse tests in stream_ssl_certificate.t were prone
to testing errors, since the client doesn't write any application data
before closing a connection, which is done so to pass tests on win32.
In this case, the server may happened to get an unexpected eof meaning
that it will abandon that session. This is specific to stream testing
pattern, changes to ssl_certificate.t are applied too for consistency.
This is also specific to SSL_R_UNEXPECTED_EOF_WHILE_READING, which is
implemented in OpenSSL 3.0.0.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Mon, 23 Nov 2020 22:46:06 +0000 |
parents | f069dd7ba5a7 |
children | 5ac6efbe5552 |
rev | line source |
---|---|
1575 | 1 #!/usr/bin/perl |
2 | |
3 # (C) Maxim Dounin | |
4 # (C) Nginx, Inc. | |
5 | |
6 # Test for uwsgi backend with SSL. | |
7 | |
8 ############################################################################### | |
9 | |
10 use warnings; | |
11 use strict; | |
12 | |
13 use Test::More; | |
14 use Socket qw/ CRLF /; | |
15 | |
16 BEGIN { use FindBin; chdir($FindBin::Bin); } | |
17 | |
18 use lib 'lib'; | |
19 use Test::Nginx; | |
20 | |
21 ############################################################################### | |
22 | |
23 select STDERR; $| = 1; | |
24 select STDOUT; $| = 1; | |
25 | |
26 my $t = Test::Nginx->new()->has(qw/http uwsgi http_ssl/) | |
27 ->has_daemon('uwsgi')->has_daemon('openssl')->plan(7) | |
28 ->write_file_expand('nginx.conf', <<'EOF'); | |
29 | |
30 %%TEST_GLOBALS%% | |
31 | |
32 daemon off; | |
33 | |
34 events { | |
35 } | |
36 | |
37 http { | |
38 %%TEST_GLOBALS_HTTP%% | |
39 | |
40 upstream u { | |
41 server 127.0.0.1:8081; | |
42 } | |
43 | |
44 server { | |
45 listen 127.0.0.1:8080; | |
46 server_name localhost; | |
47 | |
48 location / { | |
49 uwsgi_pass suwsgi://127.0.0.1:8081; | |
50 uwsgi_param SERVER_PROTOCOL $server_protocol; | |
51 uwsgi_param HTTP_X_BLAH "blah"; | |
52 uwsgi_pass_request_body off; | |
53 } | |
54 | |
55 location /var { | |
56 uwsgi_pass suwsgi://$arg_b; | |
57 uwsgi_param SERVER_PROTOCOL $server_protocol; | |
58 } | |
59 } | |
60 } | |
61 | |
62 EOF | |
63 | |
64 $t->write_file('openssl.conf', <<EOF); | |
65 [ req ] | |
66 default_bits = 2048 | |
67 encrypt_key = no | |
68 distinguished_name = req_distinguished_name | |
69 [ req_distinguished_name ] | |
70 EOF | |
71 | |
72 my $d = $t->testdir(); | |
73 my $crt = "$d/uwsgi.crt"; | |
74 my $key = "$d/uwsgi.key"; | |
75 | |
76 foreach my $name ('uwsgi') { | |
77 system('openssl req -x509 -new ' | |
78 . "-config $d/openssl.conf -subj /CN=$name/ " | |
79 . "-out $d/$name.crt -keyout $d/$name.key " | |
80 . ">>$d/openssl.out 2>&1") == 0 | |
81 or die "Can't create certificate for $name: $!\n"; | |
82 } | |
83 | |
84 $t->write_file('uwsgi_test_app.py', <<END); | |
85 | |
86 def application(env, start_response): | |
87 start_response('200 OK', [('Content-Type','text/plain')]) | |
88 return b"SEE-THIS" | |
89 | |
90 END | |
91 | |
92 my $uwsgihelp = `uwsgi -h`; | |
93 my @uwsgiopts = (); | |
94 | |
95 if ($uwsgihelp !~ /--wsgi-file/) { | |
96 # uwsgi has no python support, maybe plugin load is necessary | |
97 push @uwsgiopts, '--plugin', 'python'; | |
1598
f069dd7ba5a7
Tests: compatibility with uwsgi python package on Fedora Linux.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1575
diff
changeset
|
98 push @uwsgiopts, '--plugin', 'python3'; |
1575 | 99 } |
100 | |
1598
f069dd7ba5a7
Tests: compatibility with uwsgi python package on Fedora Linux.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1575
diff
changeset
|
101 open OLDERR, ">&", \*STDERR; close STDERR; |
1575 | 102 $t->run_daemon('uwsgi', @uwsgiopts, |
103 '--ssl-socket', '127.0.0.1:' . port(8081) . ",$crt,$key", | |
104 '--wsgi-file', $d . '/uwsgi_test_app.py', | |
105 '--logto', $d . '/uwsgi_log'); | |
1598
f069dd7ba5a7
Tests: compatibility with uwsgi python package on Fedora Linux.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1575
diff
changeset
|
106 open STDERR, ">&", \*OLDERR; |
1575 | 107 |
108 $t->run(); | |
109 | |
110 $t->waitforsocket('127.0.0.1:' . port(8081)) | |
111 or die "Can't start uwsgi"; | |
112 | |
113 ############################################################################### | |
114 | |
115 TODO: { | |
116 todo_skip 'not yet', 7 unless $t->has_version('1.19.1'); | |
117 | |
118 like(http_get('/'), qr/SEE-THIS/, 'uwsgi request'); | |
119 like(http_head('/head'), qr/200 OK(?!.*SEE-THIS)/s, 'no data in HEAD'); | |
120 | |
121 like(http_get_headers('/headers'), qr/SEE-THIS/, | |
122 'uwsgi request with many ignored headers'); | |
123 | |
124 like(http_get('/var?b=127.0.0.1:' . port(8081)), qr/SEE-THIS/, | |
125 'uwsgi with variables'); | |
126 like(http_get('/var?b=u'), qr/SEE-THIS/, 'uwsgi with variables to upstream'); | |
127 | |
128 like(http_post('/'), qr/SEE-THIS/, 'uwsgi post'); | |
129 like(http_post_big('/'), qr/SEE-THIS/, 'uwsgi big post'); | |
130 | |
131 } | |
132 | |
133 ############################################################################### | |
134 | |
135 sub http_get_headers { | |
136 my ($url, %extra) = @_; | |
137 return http(<<EOF, %extra); | |
138 GET $url HTTP/1.0 | |
139 Host: localhost | |
140 X-Blah: ignored header | |
141 X-Blah: ignored header | |
142 X-Blah: ignored header | |
143 X-Blah: ignored header | |
144 X-Blah: ignored header | |
145 X-Blah: ignored header | |
146 X-Blah: ignored header | |
147 X-Blah: ignored header | |
148 X-Blah: ignored header | |
149 X-Blah: ignored header | |
150 X-Blah: ignored header | |
151 X-Blah: ignored header | |
152 X-Blah: ignored header | |
153 X-Blah: ignored header | |
154 X-Blah: ignored header | |
155 X-Blah: ignored header | |
156 X-Blah: ignored header | |
157 X-Blah: ignored header | |
158 X-Blah: ignored header | |
159 | |
160 EOF | |
161 } | |
162 | |
163 sub http_post { | |
164 my ($url, %extra) = @_; | |
165 | |
166 my $p = "POST $url HTTP/1.0" . CRLF . | |
167 "Host: localhost" . CRLF . | |
168 "Content-Length: 10" . CRLF . | |
169 CRLF . | |
170 "1234567890"; | |
171 | |
172 return http($p, %extra); | |
173 } | |
174 | |
175 sub http_post_big { | |
176 my ($url, %extra) = @_; | |
177 | |
178 my $p = "POST $url HTTP/1.0" . CRLF . | |
179 "Host: localhost" . CRLF . | |
180 "Content-Length: 10240" . CRLF . | |
181 CRLF . | |
182 ("1234567890" x 1024); | |
183 | |
184 return http($p, %extra); | |
185 } | |
186 | |
187 ############################################################################### |