Mercurial > hg > nginx-tests
annotate uwsgi_ssl.t @ 1606:e4e0695552ed
Tests: fixed stream_proxy_ssl_conf_command.t.
The stream_proxy_ssl_conf_command.t test used stream return module
to return the response. Since this ignores actual request, but the
perl test code used http_get(). This might result in the request being
sent after the response is returned and the connection closed by the server,
resulting in RST being generated and no response seen by the client at all.
Fix is to use "stream(...)->read()" instead of http_get(), so
no request is sent at all, eliminating possibility of RST being
generated.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Tue, 10 Nov 2020 05:03:29 +0300 |
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 ############################################################################### |