annotate index.t @ 1961:fe6f22da53ec default tip

Tests: tests for usage of discarded body. The client_max_body_size limit should be ignored when the request body is already discarded. In HTTP/1.x, this is done by checking the r->discard_body flag when the body is being discarded, and because r->headers_in.content_length_n is 0 when it's already discarded. This, however, does not happen with HTTP/2 and HTTP/3, and therefore "error_page 413" does not work without relaxing the limit. Further, with proxy_pass, r->headers_in.content_length_n is used to determine length of the request body, and therefore is not correct if discarding of the request body isn't yet complete. While discarding the request body, r->headers_in.content_length_n contains the rest of the body to discard (or, in case of chunked request body, the rest of the current chunk to discard). Similarly, the $content_length variable uses r->headers_in.content_length if available, and also incorrect. The $content_length variable is used when proxying with fastcgi_pass, grpc_pass, and uwsgi_pass (scgi_pass uses the value calculated based on the actual request body buffers, and therefore works correctly).
author Maxim Dounin <mdounin@mdounin.ru>
date Sat, 27 Apr 2024 18:55:50 +0300
parents ef7de70a9d3f
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
347
f6d195aa0303 Tests: added tests for index module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1 #!/usr/bin/perl
f6d195aa0303 Tests: added tests for index module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
2
f6d195aa0303 Tests: added tests for index module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
3 # (C) Sergey Kandaurov
f6d195aa0303 Tests: added tests for index module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
4 # (C) Nginx, Inc.
f6d195aa0303 Tests: added tests for index module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
5
f6d195aa0303 Tests: added tests for index module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
6 # Tests for index module.
f6d195aa0303 Tests: added tests for index module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
7
f6d195aa0303 Tests: added tests for index module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
8 ###############################################################################
f6d195aa0303 Tests: added tests for index module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
9
f6d195aa0303 Tests: added tests for index module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
10 use warnings;
f6d195aa0303 Tests: added tests for index module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
11 use strict;
f6d195aa0303 Tests: added tests for index module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
12
f6d195aa0303 Tests: added tests for index module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
13 use Test::More;
f6d195aa0303 Tests: added tests for index module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
14
f6d195aa0303 Tests: added tests for index module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
15 BEGIN { use FindBin; chdir($FindBin::Bin); }
f6d195aa0303 Tests: added tests for index module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
16
f6d195aa0303 Tests: added tests for index module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
17 use lib 'lib';
f6d195aa0303 Tests: added tests for index module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
18 use Test::Nginx;
f6d195aa0303 Tests: added tests for index module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
19
f6d195aa0303 Tests: added tests for index module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
20 ###############################################################################
f6d195aa0303 Tests: added tests for index module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
21
f6d195aa0303 Tests: added tests for index module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
22 select STDERR; $| = 1;
f6d195aa0303 Tests: added tests for index module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
23 select STDOUT; $| = 1;
f6d195aa0303 Tests: added tests for index module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
24
1528
f0a9f5fecc8f Tests: various index module error cases.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1386
diff changeset
25 my $t = Test::Nginx->new()->has(qw/http/)->plan(14)
347
f6d195aa0303 Tests: added tests for index module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
26 ->write_file_expand('nginx.conf', <<'EOF');
f6d195aa0303 Tests: added tests for index module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
27
f6d195aa0303 Tests: added tests for index module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
28 %%TEST_GLOBALS%%
f6d195aa0303 Tests: added tests for index module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
29
f6d195aa0303 Tests: added tests for index module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
30 daemon off;
f6d195aa0303 Tests: added tests for index module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
31
f6d195aa0303 Tests: added tests for index module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
32 events {
f6d195aa0303 Tests: added tests for index module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
33 }
f6d195aa0303 Tests: added tests for index module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
34
f6d195aa0303 Tests: added tests for index module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
35 http {
f6d195aa0303 Tests: added tests for index module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
36 %%TEST_GLOBALS_HTTP%%
f6d195aa0303 Tests: added tests for index module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
37
f6d195aa0303 Tests: added tests for index module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
38 server {
974
882267679006 Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 952
diff changeset
39 listen 127.0.0.1:8080;
347
f6d195aa0303 Tests: added tests for index module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
40 server_name localhost;
f6d195aa0303 Tests: added tests for index module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
41 add_header X-URI $uri;
f6d195aa0303 Tests: added tests for index module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
42
f6d195aa0303 Tests: added tests for index module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
43 location / {
f6d195aa0303 Tests: added tests for index module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
44 # index index.html by default
f6d195aa0303 Tests: added tests for index module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
45 }
f6d195aa0303 Tests: added tests for index module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
46
f6d195aa0303 Tests: added tests for index module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
47 location /redirect/ {
f6d195aa0303 Tests: added tests for index module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
48 index /re.html;
f6d195aa0303 Tests: added tests for index module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
49 }
f6d195aa0303 Tests: added tests for index module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
50
f6d195aa0303 Tests: added tests for index module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
51 location /loop/ {
f6d195aa0303 Tests: added tests for index module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
52 index /loop/;
f6d195aa0303 Tests: added tests for index module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
53 }
f6d195aa0303 Tests: added tests for index module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
54
f6d195aa0303 Tests: added tests for index module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
55 location /no_index/ {
f6d195aa0303 Tests: added tests for index module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
56 alias %%TESTDIR%%/;
f6d195aa0303 Tests: added tests for index module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
57 index nonexisting.html;
f6d195aa0303 Tests: added tests for index module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
58 }
f6d195aa0303 Tests: added tests for index module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
59
f6d195aa0303 Tests: added tests for index module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
60 location /many/ {
f6d195aa0303 Tests: added tests for index module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
61 alias %%TESTDIR%%/;
f6d195aa0303 Tests: added tests for index module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
62 index nonexisting.html many.html;
f6d195aa0303 Tests: added tests for index module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
63 }
f6d195aa0303 Tests: added tests for index module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
64
f6d195aa0303 Tests: added tests for index module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
65 location /var/ {
f6d195aa0303 Tests: added tests for index module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
66 alias %%TESTDIR%%/;
f6d195aa0303 Tests: added tests for index module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
67 index $server_name.html;
f6d195aa0303 Tests: added tests for index module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
68 }
f6d195aa0303 Tests: added tests for index module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
69
1386
261f01ee5364 Tests: index module tests merged.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
70 location /va2/ {
261f01ee5364 Tests: index module tests merged.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
71 alias %%TESTDIR%%/;
261f01ee5364 Tests: index module tests merged.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
72 # before 1.13.8, the token produced emerg:
261f01ee5364 Tests: index module tests merged.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
73 # directive "index" is not terminated by ";"
261f01ee5364 Tests: index module tests merged.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
74 index ${server_name}.html;
261f01ee5364 Tests: index module tests merged.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
75 }
261f01ee5364 Tests: index module tests merged.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
76
347
f6d195aa0303 Tests: added tests for index module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
77 location /var_redirect/ {
f6d195aa0303 Tests: added tests for index module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
78 index /$server_name.html;
f6d195aa0303 Tests: added tests for index module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
79 }
1528
f0a9f5fecc8f Tests: various index module error cases.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1386
diff changeset
80
f0a9f5fecc8f Tests: various index module error cases.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1386
diff changeset
81 location /not_found/ {
f0a9f5fecc8f Tests: various index module error cases.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1386
diff changeset
82 error_log %%TESTDIR%%/log_not_found.log;
f0a9f5fecc8f Tests: various index module error cases.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1386
diff changeset
83
f0a9f5fecc8f Tests: various index module error cases.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1386
diff changeset
84 location /not_found/off/ {
f0a9f5fecc8f Tests: various index module error cases.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1386
diff changeset
85 error_log %%TESTDIR%%/off.log;
f0a9f5fecc8f Tests: various index module error cases.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1386
diff changeset
86 log_not_found off;
f0a9f5fecc8f Tests: various index module error cases.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1386
diff changeset
87 }
f0a9f5fecc8f Tests: various index module error cases.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1386
diff changeset
88 }
347
f6d195aa0303 Tests: added tests for index module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
89 }
f6d195aa0303 Tests: added tests for index module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
90 }
f6d195aa0303 Tests: added tests for index module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
91
f6d195aa0303 Tests: added tests for index module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
92 EOF
f6d195aa0303 Tests: added tests for index module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
93
f6d195aa0303 Tests: added tests for index module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
94 $t->write_file('index.html', 'body');
f6d195aa0303 Tests: added tests for index module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
95 $t->write_file('many.html', 'manybody');
f6d195aa0303 Tests: added tests for index module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
96 $t->write_file('re.html', 'rebody');
f6d195aa0303 Tests: added tests for index module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
97 $t->write_file('localhost.html', 'varbody');
f6d195aa0303 Tests: added tests for index module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
98
1528
f0a9f5fecc8f Tests: various index module error cases.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1386
diff changeset
99 my $d = $t->testdir();
f0a9f5fecc8f Tests: various index module error cases.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1386
diff changeset
100 mkdir("$d/forbidden");
f0a9f5fecc8f Tests: various index module error cases.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1386
diff changeset
101 chmod(0000, "$d/forbidden");
f0a9f5fecc8f Tests: various index module error cases.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1386
diff changeset
102
347
f6d195aa0303 Tests: added tests for index module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
103 $t->run();
f6d195aa0303 Tests: added tests for index module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
104
f6d195aa0303 Tests: added tests for index module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
105 ###############################################################################
f6d195aa0303 Tests: added tests for index module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
106
f6d195aa0303 Tests: added tests for index module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
107 like(http_get('/'), qr/X-URI: \/index.html.*body/ms, 'default index');
f6d195aa0303 Tests: added tests for index module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
108 like(http_get('/no_index/'), qr/403 Forbidden/, 'no index');
f6d195aa0303 Tests: added tests for index module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
109 like(http_get('/redirect/'), qr/X-URI: \/re.html.*rebody/ms, 'redirect');
f6d195aa0303 Tests: added tests for index module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
110 like(http_get('/loop/'), qr/500 Internal/, 'redirect loop');
f6d195aa0303 Tests: added tests for index module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
111 like(http_get('/many/'), qr/X-URI: \/many\/many.html.*manybody/ms, 'many');
f6d195aa0303 Tests: added tests for index module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
112 like(http_get('/var/'), qr/X-URI: \/var\/localhost.html.*varbody/ms, 'var');
1386
261f01ee5364 Tests: index module tests merged.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
113 like(http_get('/va2/'), qr/X-URI: \/va2\/localhost.html.*varbody/ms, 'var 2');
347
f6d195aa0303 Tests: added tests for index module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
114 like(http_get('/var_redirect/'), qr/X-URI: \/localhost.html.*varbody/ms,
f6d195aa0303 Tests: added tests for index module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
115 'var with redirect');
f6d195aa0303 Tests: added tests for index module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
116
1528
f0a9f5fecc8f Tests: various index module error cases.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1386
diff changeset
117 like(http_get('/not_found/'), qr/404 Not Found/, 'not found');
f0a9f5fecc8f Tests: various index module error cases.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1386
diff changeset
118 like(http_get('/not_found/off/'), qr/404 Not Found/, 'not found log off');
f0a9f5fecc8f Tests: various index module error cases.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1386
diff changeset
119 like(http_get('/forbidden/'), qr/403 Forbidden/, 'directory access denied');
f0a9f5fecc8f Tests: various index module error cases.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1386
diff changeset
120 like(http_get('/index.html/'), qr/404 Not Found/, 'not a directory');
f0a9f5fecc8f Tests: various index module error cases.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1386
diff changeset
121
f0a9f5fecc8f Tests: various index module error cases.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1386
diff changeset
122 $t->stop();
f0a9f5fecc8f Tests: various index module error cases.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1386
diff changeset
123
f0a9f5fecc8f Tests: various index module error cases.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1386
diff changeset
124 like($t->read_file('log_not_found.log'), qr/error/, 'log_not_found');
f0a9f5fecc8f Tests: various index module error cases.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1386
diff changeset
125 unlike($t->read_file('off.log'), qr/error/, 'log_not_found off');
f0a9f5fecc8f Tests: various index module error cases.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1386
diff changeset
126
1529
ef7de70a9d3f Tests: restored access bits in index.t.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1528
diff changeset
127 chmod(0700, "$d/forbidden");
ef7de70a9d3f Tests: restored access bits in index.t.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1528
diff changeset
128
347
f6d195aa0303 Tests: added tests for index module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
129 ###############################################################################