Mercurial > hg > nginx-tests
annotate autoindex.t @ 1990:85d88cd5091c
Tests: SSI include stub tests.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Thu, 04 Jul 2024 17:42:55 +0300 |
parents | 882267679006 |
children |
rev | line source |
---|---|
108
93a8f4202b16
Tests: add autoindex module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
93a8f4202b16
Tests: add autoindex module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
2 |
93a8f4202b16
Tests: add autoindex module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
3 # (C) Maxim Dounin |
93a8f4202b16
Tests: add autoindex module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
4 |
93a8f4202b16
Tests: add autoindex module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
5 # Tests for autoindex module. |
93a8f4202b16
Tests: add autoindex module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
6 |
93a8f4202b16
Tests: add autoindex module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
7 ############################################################################### |
93a8f4202b16
Tests: add autoindex module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
8 |
93a8f4202b16
Tests: add autoindex module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
9 use warnings; |
93a8f4202b16
Tests: add autoindex module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
10 use strict; |
93a8f4202b16
Tests: add autoindex module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
11 |
93a8f4202b16
Tests: add autoindex module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
12 use Test::More; |
93a8f4202b16
Tests: add autoindex module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
13 |
93a8f4202b16
Tests: add autoindex module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
14 BEGIN { use FindBin; chdir($FindBin::Bin); } |
93a8f4202b16
Tests: add autoindex module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
15 |
93a8f4202b16
Tests: add autoindex module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
16 use lib 'lib'; |
93a8f4202b16
Tests: add autoindex module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
17 use Test::Nginx; |
93a8f4202b16
Tests: add autoindex module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
18 |
93a8f4202b16
Tests: add autoindex module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
19 ############################################################################### |
93a8f4202b16
Tests: add autoindex module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
20 |
93a8f4202b16
Tests: add autoindex module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
21 select STDERR; $| = 1; |
93a8f4202b16
Tests: add autoindex module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
22 select STDOUT; $| = 1; |
93a8f4202b16
Tests: add autoindex module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
23 |
574
2cd00179f4b2
Tests: has_feature() introduced in Test::Nginx.
Sergey Kandaurov <pluknet@nginx.com>
parents:
444
diff
changeset
|
24 my $t = Test::Nginx->new()->has(qw/http autoindex charset symlink/)->plan(16) |
108
93a8f4202b16
Tests: add autoindex module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
25 ->write_file_expand('nginx.conf', <<'EOF'); |
93a8f4202b16
Tests: add autoindex module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
26 |
93a8f4202b16
Tests: add autoindex module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
27 %%TEST_GLOBALS%% |
93a8f4202b16
Tests: add autoindex module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
28 |
249
6a0d934950bc
Tests: remove extra spaces in "daemon off".
Maxim Dounin <mdounin@mdounin.ru>
parents:
223
diff
changeset
|
29 daemon off; |
108
93a8f4202b16
Tests: add autoindex module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
30 |
93a8f4202b16
Tests: add autoindex module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
31 events { |
93a8f4202b16
Tests: add autoindex module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
32 } |
93a8f4202b16
Tests: add autoindex module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
33 |
93a8f4202b16
Tests: add autoindex module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
34 http { |
93a8f4202b16
Tests: add autoindex module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
35 %%TEST_GLOBALS_HTTP%% |
93a8f4202b16
Tests: add autoindex module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
36 |
93a8f4202b16
Tests: add autoindex module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
37 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
38 listen 127.0.0.1:8080; |
108
93a8f4202b16
Tests: add autoindex module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
39 server_name localhost; |
93a8f4202b16
Tests: add autoindex module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
40 |
93a8f4202b16
Tests: add autoindex module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
41 location / { |
93a8f4202b16
Tests: add autoindex module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
42 autoindex on; |
93a8f4202b16
Tests: add autoindex module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
43 } |
123
8aa0dd396a83
Tests: add more autoindex tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
121
diff
changeset
|
44 location /utf8/ { |
8aa0dd396a83
Tests: add more autoindex tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
121
diff
changeset
|
45 autoindex on; |
8aa0dd396a83
Tests: add more autoindex tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
121
diff
changeset
|
46 charset utf-8; |
8aa0dd396a83
Tests: add more autoindex tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
121
diff
changeset
|
47 } |
108
93a8f4202b16
Tests: add autoindex module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
48 } |
93a8f4202b16
Tests: add autoindex module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
49 } |
93a8f4202b16
Tests: add autoindex module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
50 |
93a8f4202b16
Tests: add autoindex module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
51 EOF |
93a8f4202b16
Tests: add autoindex module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
52 |
93a8f4202b16
Tests: add autoindex module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
53 my $d = $t->testdir(); |
93a8f4202b16
Tests: add autoindex module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
54 |
93a8f4202b16
Tests: add autoindex module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
55 mkdir("$d/test-dir"); |
93a8f4202b16
Tests: add autoindex module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
56 symlink("$d/test-dir", "$d/test-dir-link"); |
93a8f4202b16
Tests: add autoindex module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
57 |
93a8f4202b16
Tests: add autoindex module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
58 $t->write_file('test-file', ''); |
93a8f4202b16
Tests: add autoindex module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
59 symlink("$d/test-file", "$d/test-file-link"); |
93a8f4202b16
Tests: add autoindex module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
60 |
123
8aa0dd396a83
Tests: add more autoindex tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
121
diff
changeset
|
61 $t->write_file('test-colon:blah', ''); |
8aa0dd396a83
Tests: add more autoindex tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
121
diff
changeset
|
62 $t->write_file('test-long-' . ('0' x 50), ''); |
8aa0dd396a83
Tests: add more autoindex tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
121
diff
changeset
|
63 $t->write_file('test-long-' . ('>' x 50), ''); |
8aa0dd396a83
Tests: add more autoindex tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
121
diff
changeset
|
64 $t->write_file('test-escape-url-%', ''); |
126
0a2f750790c9
Tests: add autoindex test for '?' in file name.
Maxim Dounin <mdounin@mdounin.ru>
parents:
125
diff
changeset
|
65 $t->write_file('test-escape-url2-?', ''); |
123
8aa0dd396a83
Tests: add more autoindex tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
121
diff
changeset
|
66 $t->write_file('test-escape-html-<>&', ''); |
8aa0dd396a83
Tests: add more autoindex tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
121
diff
changeset
|
67 |
8aa0dd396a83
Tests: add more autoindex tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
121
diff
changeset
|
68 mkdir($d . '/utf8'); |
8aa0dd396a83
Tests: add more autoindex tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
121
diff
changeset
|
69 $t->write_file('utf8/test-utf8-' . ("\xd1\x84" x 3), ''); |
8aa0dd396a83
Tests: add more autoindex tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
121
diff
changeset
|
70 $t->write_file('utf8/test-utf8-' . ("\xd1\x84" x 45), ''); |
8aa0dd396a83
Tests: add more autoindex tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
121
diff
changeset
|
71 $t->write_file('utf8/test-utf8-<>&-' . "\xd1\x84", ''); |
8aa0dd396a83
Tests: add more autoindex tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
121
diff
changeset
|
72 $t->write_file('utf8/test-utf8-<>&-' . ("\xd1\x84" x 45), ''); |
8aa0dd396a83
Tests: add more autoindex tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
121
diff
changeset
|
73 $t->write_file('utf8/test-utf8-' . ("\xd1\x84" x 3) . '-' . ('>' x 45), ''); |
8aa0dd396a83
Tests: add more autoindex tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
121
diff
changeset
|
74 |
8aa0dd396a83
Tests: add more autoindex tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
121
diff
changeset
|
75 mkdir($d . '/test-dir-escape-<>&'); |
8aa0dd396a83
Tests: add more autoindex tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
121
diff
changeset
|
76 |
108
93a8f4202b16
Tests: add autoindex module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
77 $t->run(); |
93a8f4202b16
Tests: add autoindex module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
78 |
93a8f4202b16
Tests: add autoindex module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
79 ############################################################################### |
93a8f4202b16
Tests: add autoindex module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
80 |
93a8f4202b16
Tests: add autoindex module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
81 my $r = http_get('/'); |
93a8f4202b16
Tests: add autoindex module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
82 |
93a8f4202b16
Tests: add autoindex module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
83 like($r, qr!href="test-file"!ms, 'file'); |
93a8f4202b16
Tests: add autoindex module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
84 like($r, qr!href="test-file-link"!ms, 'symlink to file'); |
93a8f4202b16
Tests: add autoindex module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
85 like($r, qr!href="test-dir/"!ms, 'directory'); |
93a8f4202b16
Tests: add autoindex module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
86 like($r, qr!href="test-dir-link/"!ms, 'symlink to directory'); |
93a8f4202b16
Tests: add autoindex module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
87 |
146
afa07ae9def6
Tests: better autoindex colon test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
126
diff
changeset
|
88 unlike($r, qr!href="test-colon:blah"!ms, 'colon not scheme'); |
123
8aa0dd396a83
Tests: add more autoindex tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
121
diff
changeset
|
89 like($r, qr!test-long-0{37}\.\.>!ms, 'long name'); |
8aa0dd396a83
Tests: add more autoindex tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
121
diff
changeset
|
90 |
8aa0dd396a83
Tests: add more autoindex tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
121
diff
changeset
|
91 like($r, qr!href="test-escape-url-%25"!ms, 'escaped url'); |
444
d9cfff372a30
Tests: avoid dependency on uri escaping case.
Maxim Dounin <mdounin@mdounin.ru>
parents:
320
diff
changeset
|
92 like($r, qr!href="test-escape-url2-%3f"!msi, 'escaped ? in url'); |
123
8aa0dd396a83
Tests: add more autoindex tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
121
diff
changeset
|
93 like($r, qr!test-escape-html-<>&!ms, 'escaped html'); |
8aa0dd396a83
Tests: add more autoindex tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
121
diff
changeset
|
94 like($r, qr!test-long-(>){37}\.\.>!ms, 'long escaped html'); |
8aa0dd396a83
Tests: add more autoindex tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
121
diff
changeset
|
95 |
8aa0dd396a83
Tests: add more autoindex tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
121
diff
changeset
|
96 $r = http_get('/utf8/'); |
8aa0dd396a83
Tests: add more autoindex tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
121
diff
changeset
|
97 |
8aa0dd396a83
Tests: add more autoindex tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
121
diff
changeset
|
98 like($r, qr!test-utf8-(\xd1\x84){3}</a>!ms, 'utf8'); |
8aa0dd396a83
Tests: add more autoindex tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
121
diff
changeset
|
99 like($r, qr!test-utf8-(\xd1\x84){37}\.\.!ms, 'utf8 long'); |
125
f10f077a3174
Tests: autoindex utf8 handling fixed in 0.8.32.
Maxim Dounin <mdounin@mdounin.ru>
parents:
123
diff
changeset
|
100 |
123
8aa0dd396a83
Tests: add more autoindex tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
121
diff
changeset
|
101 like($r, qr!test-utf8-<>&-\xd1\x84</a>!ms, 'utf8 escaped'); |
8aa0dd396a83
Tests: add more autoindex tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
121
diff
changeset
|
102 like($r, qr!test-utf8-<>&-(\xd1\x84){33}\.\.!ms, |
8aa0dd396a83
Tests: add more autoindex tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
121
diff
changeset
|
103 'utf8 escaped long'); |
8aa0dd396a83
Tests: add more autoindex tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
121
diff
changeset
|
104 like($r, qr!test-utf8-(\xd1\x84){3}-(>){33}\.\.!ms, 'utf8 long escaped'); |
8aa0dd396a83
Tests: add more autoindex tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
121
diff
changeset
|
105 |
8aa0dd396a83
Tests: add more autoindex tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
121
diff
changeset
|
106 like(http_get('/test-dir-escape-<>&/'), qr!test-dir-escape-<>&!ms, |
8aa0dd396a83
Tests: add more autoindex tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
121
diff
changeset
|
107 'escaped title'); |
8aa0dd396a83
Tests: add more autoindex tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
121
diff
changeset
|
108 |
108
93a8f4202b16
Tests: add autoindex module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
109 ############################################################################### |