Mercurial > hg > nginx-tests
annotate uwsgi_ssl.t @ 1962:f1ba89f735ba
Tests: fixed auth_basic.t on OpenBSD.
OpenBSD does not provide any crypt() schemes except bcrypt-based "$2"
anymore. As such, relevant tests are now skipped not for win32 only,
but based on crypt() results.
Note that just testing crypt('password', 'salt') is not enough, since
Perl on win32 provides its own crypt() implementation, which is able
to handle traditional DES crypt(), but rejects "$1$".
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Sun, 05 May 2024 23:56:07 +0300 |
parents | 1b9f21836f57 |
children |
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 | |
1923
1b9f21836f57
Tests: enabled TLSv1 in uwsgi SSL tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1693
diff
changeset
|
101 if ($uwsgihelp =~ /--ssl-enable-tlsv1/) { |
1b9f21836f57
Tests: enabled TLSv1 in uwsgi SSL tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1693
diff
changeset
|
102 # uwsgi disables TLSv1 by default since 2.0.17.1 |
1b9f21836f57
Tests: enabled TLSv1 in uwsgi SSL tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1693
diff
changeset
|
103 push @uwsgiopts, '--ssl-enable-tlsv1'; |
1b9f21836f57
Tests: enabled TLSv1 in uwsgi SSL tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1693
diff
changeset
|
104 } |
1b9f21836f57
Tests: enabled TLSv1 in uwsgi SSL tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1693
diff
changeset
|
105 |
1598
f069dd7ba5a7
Tests: compatibility with uwsgi python package on Fedora Linux.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1575
diff
changeset
|
106 open OLDERR, ">&", \*STDERR; close STDERR; |
1575 | 107 $t->run_daemon('uwsgi', @uwsgiopts, |
108 '--ssl-socket', '127.0.0.1:' . port(8081) . ",$crt,$key", | |
109 '--wsgi-file', $d . '/uwsgi_test_app.py', | |
110 '--logto', $d . '/uwsgi_log'); | |
1598
f069dd7ba5a7
Tests: compatibility with uwsgi python package on Fedora Linux.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1575
diff
changeset
|
111 open STDERR, ">&", \*OLDERR; |
1575 | 112 |
113 $t->run(); | |
114 | |
115 $t->waitforsocket('127.0.0.1:' . port(8081)) | |
116 or die "Can't start uwsgi"; | |
117 | |
118 ############################################################################### | |
119 | |
120 like(http_get('/'), qr/SEE-THIS/, 'uwsgi request'); | |
121 like(http_head('/head'), qr/200 OK(?!.*SEE-THIS)/s, 'no data in HEAD'); | |
122 | |
123 like(http_get_headers('/headers'), qr/SEE-THIS/, | |
124 'uwsgi request with many ignored headers'); | |
125 | |
126 like(http_get('/var?b=127.0.0.1:' . port(8081)), qr/SEE-THIS/, | |
127 'uwsgi with variables'); | |
128 like(http_get('/var?b=u'), qr/SEE-THIS/, 'uwsgi with variables to upstream'); | |
129 | |
130 like(http_post('/'), qr/SEE-THIS/, 'uwsgi post'); | |
131 like(http_post_big('/'), qr/SEE-THIS/, 'uwsgi big post'); | |
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 ############################################################################### |