Mercurial > hg > nginx-tests
annotate uwsgi.t @ 1896:8b74936ff2ac
Tests: added has_feature() test for CryptX.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Mon, 29 May 2023 17:04:36 +0400 |
parents | 1d7932bc2847 |
children | a095b971fbcc |
rev | line source |
---|---|
168 | 1 #!/usr/bin/perl |
2 | |
3 # (C) Maxim Dounin | |
4 | |
5 # Test for uwsgi 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 | |
1765
1d7932bc2847
Tests: uwsgi tests for combining headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1598
diff
changeset
|
24 my $t = Test::Nginx->new()->has(qw/http uwsgi/)->has_daemon('uwsgi')->plan(8) |
168 | 25 ->write_file_expand('nginx.conf', <<'EOF'); |
26 | |
27 %%TEST_GLOBALS%% | |
28 | |
249
6a0d934950bc
Tests: remove extra spaces in "daemon off".
Maxim Dounin <mdounin@mdounin.ru>
parents:
241
diff
changeset
|
29 daemon off; |
168 | 30 |
31 events { | |
32 } | |
33 | |
34 http { | |
35 %%TEST_GLOBALS_HTTP%% | |
36 | |
802
eca9b1d19021
Tests: tests for host expansion to an explicit upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
801
diff
changeset
|
37 upstream u { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
38 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
|
39 } |
eca9b1d19021
Tests: tests for host expansion to an explicit upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
801
diff
changeset
|
40 |
168 | 41 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
42 listen 127.0.0.1:8080; |
168 | 43 server_name localhost; |
44 | |
45 location / { | |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
46 uwsgi_pass 127.0.0.1:8081; |
168 | 47 uwsgi_param SERVER_PROTOCOL $server_protocol; |
48 uwsgi_param HTTP_X_BLAH "blah"; | |
49 } | |
801
d95c4b8e5517
Tests: more tests for passing requests to host given by expression.
Sergey Kandaurov <pluknet@nginx.com>
parents:
590
diff
changeset
|
50 |
d95c4b8e5517
Tests: more tests for passing requests to host given by expression.
Sergey Kandaurov <pluknet@nginx.com>
parents:
590
diff
changeset
|
51 location /var { |
d95c4b8e5517
Tests: more tests for passing requests to host given by expression.
Sergey Kandaurov <pluknet@nginx.com>
parents:
590
diff
changeset
|
52 uwsgi_pass $arg_b; |
d95c4b8e5517
Tests: more tests for passing requests to host given by expression.
Sergey Kandaurov <pluknet@nginx.com>
parents:
590
diff
changeset
|
53 uwsgi_param SERVER_PROTOCOL $server_protocol; |
d95c4b8e5517
Tests: more tests for passing requests to host given by expression.
Sergey Kandaurov <pluknet@nginx.com>
parents:
590
diff
changeset
|
54 } |
168 | 55 } |
56 } | |
57 | |
58 EOF | |
59 | |
60 $t->write_file('uwsgi_test_app.py', <<END); | |
61 | |
62 def application(env, start_response): | |
1765
1d7932bc2847
Tests: uwsgi tests for combining headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1598
diff
changeset
|
63 start_response('200 OK', [ |
1d7932bc2847
Tests: uwsgi tests for combining headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1598
diff
changeset
|
64 ('Content-Type', 'text/plain'), |
1d7932bc2847
Tests: uwsgi tests for combining headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1598
diff
changeset
|
65 ('X-Forwarded-For', env.get('HTTP_X_FORWARDED_FOR', '')), |
1d7932bc2847
Tests: uwsgi tests for combining headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1598
diff
changeset
|
66 ('X-Cookie', env.get('HTTP_COOKIE', '')), |
1d7932bc2847
Tests: uwsgi tests for combining headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1598
diff
changeset
|
67 ('X-Foo', env.get('HTTP_FOO', '')) |
1d7932bc2847
Tests: uwsgi tests for combining headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1598
diff
changeset
|
68 ]) |
1480
d23d959713b5
Tests: Python 3.7 (PEP 3333) compatibility in uwsgi tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
69 return b"SEE-THIS" |
168 | 70 |
71 END | |
72 | |
363
98f3a8568b0c
Tests: try to load python plugin if uwsgi has no wsgi option.
Sergey Budnevitch <sb@waeme.net>
parents:
249
diff
changeset
|
73 my $uwsgihelp = `uwsgi -h`; |
98f3a8568b0c
Tests: try to load python plugin if uwsgi has no wsgi option.
Sergey Budnevitch <sb@waeme.net>
parents:
249
diff
changeset
|
74 my @uwsgiopts = (); |
98f3a8568b0c
Tests: try to load python plugin if uwsgi has no wsgi option.
Sergey Budnevitch <sb@waeme.net>
parents:
249
diff
changeset
|
75 |
98f3a8568b0c
Tests: try to load python plugin if uwsgi has no wsgi option.
Sergey Budnevitch <sb@waeme.net>
parents:
249
diff
changeset
|
76 if ($uwsgihelp !~ /--wsgi-file/) { |
98f3a8568b0c
Tests: try to load python plugin if uwsgi has no wsgi option.
Sergey Budnevitch <sb@waeme.net>
parents:
249
diff
changeset
|
77 # uwsgi has no python support, maybe plugin load is necessary |
98f3a8568b0c
Tests: try to load python plugin if uwsgi has no wsgi option.
Sergey Budnevitch <sb@waeme.net>
parents:
249
diff
changeset
|
78 push @uwsgiopts, '--plugin', 'python'; |
1598
f069dd7ba5a7
Tests: compatibility with uwsgi python package on Fedora Linux.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1480
diff
changeset
|
79 push @uwsgiopts, '--plugin', 'python3'; |
363
98f3a8568b0c
Tests: try to load python plugin if uwsgi has no wsgi option.
Sergey Budnevitch <sb@waeme.net>
parents:
249
diff
changeset
|
80 } |
98f3a8568b0c
Tests: try to load python plugin if uwsgi has no wsgi option.
Sergey Budnevitch <sb@waeme.net>
parents:
249
diff
changeset
|
81 |
1598
f069dd7ba5a7
Tests: compatibility with uwsgi python package on Fedora Linux.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1480
diff
changeset
|
82 open OLDERR, ">&", \*STDERR; close STDERR; |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
83 $t->run_daemon('uwsgi', '--socket', '127.0.0.1:' . port(8081), @uwsgiopts, |
168 | 84 '--wsgi-file', $t->testdir() . '/uwsgi_test_app.py', |
85 '--logto', $t->testdir() . '/uwsgi_log'); | |
1598
f069dd7ba5a7
Tests: compatibility with uwsgi python package on Fedora Linux.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1480
diff
changeset
|
86 open STDERR, ">&", \*OLDERR; |
168 | 87 |
88 $t->run(); | |
89 | |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
90 $t->waitforsocket('127.0.0.1:' . port(8081)) |
174
c8169c827d18
Tests: use waitoforsocket() as uwsgi startup may take a while.
Maxim Dounin <mdounin@mdounin.ru>
parents:
168
diff
changeset
|
91 or die "Can't start uwsgi"; |
c8169c827d18
Tests: use waitoforsocket() as uwsgi startup may take a while.
Maxim Dounin <mdounin@mdounin.ru>
parents:
168
diff
changeset
|
92 |
168 | 93 ############################################################################### |
94 | |
95 like(http_get('/'), qr/SEE-THIS/, 'uwsgi request'); | |
96 unlike(http_head('/head'), qr/SEE-THIS/, 'no data in HEAD'); | |
97 | |
98 like(http_get_headers('/headers'), qr/SEE-THIS/, | |
99 'uwsgi request with many ignored headers'); | |
100 | |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
101 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
|
102 'uwsgi with variables'); |
802
eca9b1d19021
Tests: tests for host expansion to an explicit upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
801
diff
changeset
|
103 like(http_get('/var?b=u'), qr/SEE-THIS/, 'uwsgi 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
|
104 |
1765
1d7932bc2847
Tests: uwsgi tests for combining headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1598
diff
changeset
|
105 TODO: { |
1d7932bc2847
Tests: uwsgi tests for combining headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1598
diff
changeset
|
106 local $TODO = 'not yet' unless $t->has_version('1.23.0'); |
1d7932bc2847
Tests: uwsgi tests for combining headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1598
diff
changeset
|
107 |
1d7932bc2847
Tests: uwsgi tests for combining headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1598
diff
changeset
|
108 my $r = http(<<EOF); |
1d7932bc2847
Tests: uwsgi tests for combining headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1598
diff
changeset
|
109 GET / HTTP/1.0 |
1d7932bc2847
Tests: uwsgi tests for combining headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1598
diff
changeset
|
110 Host: localhost |
1d7932bc2847
Tests: uwsgi tests for combining headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1598
diff
changeset
|
111 X-Forwarded-For: foo |
1d7932bc2847
Tests: uwsgi tests for combining headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1598
diff
changeset
|
112 X-Forwarded-For: bar |
1d7932bc2847
Tests: uwsgi tests for combining headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1598
diff
changeset
|
113 X-Forwarded-For: bazz |
1d7932bc2847
Tests: uwsgi tests for combining headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1598
diff
changeset
|
114 Cookie: foo |
1d7932bc2847
Tests: uwsgi tests for combining headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1598
diff
changeset
|
115 Cookie: bar |
1d7932bc2847
Tests: uwsgi tests for combining headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1598
diff
changeset
|
116 Cookie: bazz |
1d7932bc2847
Tests: uwsgi tests for combining headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1598
diff
changeset
|
117 Foo: foo |
1d7932bc2847
Tests: uwsgi tests for combining headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1598
diff
changeset
|
118 Foo: bar |
1d7932bc2847
Tests: uwsgi tests for combining headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1598
diff
changeset
|
119 Foo: bazz |
1d7932bc2847
Tests: uwsgi tests for combining headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1598
diff
changeset
|
120 |
1d7932bc2847
Tests: uwsgi tests for combining headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1598
diff
changeset
|
121 EOF |
1d7932bc2847
Tests: uwsgi tests for combining headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1598
diff
changeset
|
122 |
1d7932bc2847
Tests: uwsgi tests for combining headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1598
diff
changeset
|
123 like($r, qr/X-Forwarded-For: foo, bar, bazz/, |
1d7932bc2847
Tests: uwsgi tests for combining headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1598
diff
changeset
|
124 'uwsgi with multiple X-Forwarded-For headers'); |
1d7932bc2847
Tests: uwsgi tests for combining headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1598
diff
changeset
|
125 like($r, qr/X-Cookie: foo; bar; bazz/, |
1d7932bc2847
Tests: uwsgi tests for combining headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1598
diff
changeset
|
126 'uwsgi with multiple Cookie headers'); |
1d7932bc2847
Tests: uwsgi tests for combining headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1598
diff
changeset
|
127 like($r, qr/X-Foo: foo, bar, bazz/, |
1d7932bc2847
Tests: uwsgi tests for combining headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1598
diff
changeset
|
128 'uwsgi with multiple unknown headers'); |
1d7932bc2847
Tests: uwsgi tests for combining headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1598
diff
changeset
|
129 |
1d7932bc2847
Tests: uwsgi tests for combining headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1598
diff
changeset
|
130 } |
1d7932bc2847
Tests: uwsgi tests for combining headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1598
diff
changeset
|
131 |
168 | 132 ############################################################################### |
133 | |
134 sub http_get_headers { | |
590
dc2f8aac0553
Tests: whitespace fixes.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
363
diff
changeset
|
135 my ($url, %extra) = @_; |
dc2f8aac0553
Tests: whitespace fixes.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
363
diff
changeset
|
136 return http(<<EOF, %extra); |
168 | 137 GET $url HTTP/1.0 |
138 Host: localhost | |
139 X-Blah: ignored header | |
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 | |
159 EOF | |
160 } | |
161 | |
162 ############################################################################### |