annotate autoindex_format.t @ 1974:b5036a0f9ae0 default tip

Tests: improved compatibility when using recent "openssl" app. Starting with OpenSSL 3.0, "openssl genrsa" generates encrypted keys in PKCS#8 format instead of previously used PKCS#1 format. Further, since OpenSSL 1.1.0 such keys are using PBKDF2 hmacWithSHA256. Such keys are not supported by old SSL libraries, notably by OpenSSL before 1.0.0 (OpenSSL 0.9.8 only supports hmacWithSHA1) and by BoringSSL before May 21, 2019 (support for hmacWithSHA256 was added in 302a4dee6c), and trying to load such keys into nginx compiled with an old SSL library results in "unsupported prf" errors. To facilitate testing with old SSL libraries, keys are now generated with "openssl genrsa -traditional" if the flag is available.
author Maxim Dounin <mdounin@mdounin.ru>
date Mon, 06 May 2024 00:04:26 +0300
parents 81579df2ba8c
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
518
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1 #!/usr/bin/perl
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
2
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
3 # (C) Maxim Dounin
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
4 # (C) Sergey Kandaurov
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
5 # (C) Nginx, Inc.
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
6
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
7 # Tests for autoindex module with autoindex_format directive.
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
8
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
9 ###############################################################################
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
10
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
11 use warnings;
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
12 use strict;
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
13
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
14 use Test::More;
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
15
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
16 BEGIN { use FindBin; chdir($FindBin::Bin); }
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
17
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
18 use lib 'lib';
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
19 use Test::Nginx;
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
20
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
21 ###############################################################################
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
22
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
23 select STDERR; $| = 1;
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
24 select STDOUT; $| = 1;
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
25
574
2cd00179f4b2 Tests: has_feature() introduced in Test::Nginx.
Sergey Kandaurov <pluknet@nginx.com>
parents: 568
diff changeset
26 my $t = Test::Nginx->new()->has(qw/http autoindex symlink/)->plan(37)
518
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
27 ->write_file_expand('nginx.conf', <<'EOF');
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
28
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
29 %%TEST_GLOBALS%%
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
30
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
31 daemon off;
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
32
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
33 events {
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
34 }
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
35
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
36 http {
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
37 %%TEST_GLOBALS_HTTP%%
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
38
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
39 server {
974
882267679006 Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 952
diff changeset
40 listen 127.0.0.1:8080;
518
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
41 server_name localhost;
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
42
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
43 autoindex on;
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
44
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
45 location /xml/ {
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
46 autoindex_format xml;
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
47 alias %%TESTDIR%%/;
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
48 }
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
49 location /json/ {
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
50 autoindex_format json;
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
51 alias %%TESTDIR%%/;
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
52 }
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
53 location /jsonp/ {
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
54 autoindex_format jsonp;
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
55 alias %%TESTDIR%%/;
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
56 }
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
57 }
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
58 }
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
59
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
60 EOF
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
61
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
62 my $d = $t->testdir();
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
63
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
64 mkdir("$d/test-dir");
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
65 symlink("$d/test-dir", "$d/test-dir-link");
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
66
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
67 $t->write_file('test-file', 'x' x 42);
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
68 symlink("$d/test-file", "$d/test-file-link");
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
69
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
70 $t->write_file('test-\'-quote', '');
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
71 $t->write_file('test-"-double', '');
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
72 $t->write_file('test-<>-angle', '');
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
73
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
74 mkdir($d . '/utf8');
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
75 $t->write_file('utf8/test-utf8-' . ("\xd1\x84" x 3), '');
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
76 $t->write_file('utf8/test-utf8-' . ("\xd1\x84" x 45), '');
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
77
568
907e89fba9c3 Tests: removed TODO and try_run() checks for legacy versions.
Sergey Kandaurov <pluknet@nginx.com>
parents: 534
diff changeset
78 $t->run();
518
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
79
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
80 ###############################################################################
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
81
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
82 my ($r, $mtime, $data);
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
83
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
84 $r = http_get('/xml/');
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
85 $mtime = qr/mtime="\d{4}-\d\d-\d\dT\d\d:\d\d:\d\dZ"/;
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
86
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
87 like($r, qr!Content-Type: text/xml; charset=utf-8!, 'xml content type');
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
88 like($r, qr!<file(\s+\w+="[^=]*?")+\s*>test-file</file>!,
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
89 'xml file format');
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
90 like($r, qr!<directory(\s+\w+="[^=]*?")+\s*>test-dir</directory>!,
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
91 'xml dir format');
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
92
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
93 ($data) = $r =~ qr!<file\s+(.*?)>test-file</file>!;
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
94 like($data, $mtime, 'xml file mtime');
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
95 like($data, qr!size="42"!, 'xml file size');
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
96
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
97 ($data) = $r =~ qr!<file\s+(.*?)>test-file-link</file>!;
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
98 like($data, $mtime, 'xml file link mtime');
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
99 like($data, qr!size="42"!, 'xml file link size');
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
100
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
101 ($data) = $r =~ qr!<directory\s+(.*?)>test-dir</directory>!;
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
102 like($data, $mtime, 'xml dir mtime');
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
103 unlike($data, qr!size="\d+"!, 'xml dir size');
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
104
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
105 ($data) = $r =~ qr!<directory\s+(.*?)>test-dir-link</directory>!;
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
106 like($data, $mtime, 'xml dir link mtime');
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
107 unlike($data, qr!size="\d+"!, 'xml dir link size');
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
108
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
109 like($r, qr!<file.*?>test-\'-quote</file>!, 'xml quote');
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
110 like($r, qr!<file.*?>test-\&quot;-double</file>!, 'xml double');
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
111 like($r, qr!<file.*?>test-&lt;&gt;-angle</file>!, 'xml angle');
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
112
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
113
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
114 $r = http_get('/json/');
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
115 $mtime = qr/"mtime"\s*:\s*"\w{3}, \d\d \w{3} \d{4} \d\d:\d\d:\d\d \w{3}"/;
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
116
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
117 my $string = qr!"(?:[^\\"]+|\\["\\/bfnrt])*"!;
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
118 my $number = qr!-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][-+]?\d+)?!;
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
119 my $kv = qr!\s*$string\s*:\s*($string|$number)\s*!;
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
120
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
121 like($r, qr!Content-Type: application/json!, 'json content type');
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
122 like($r, qr!{$kv(,$kv)*}!, 'json format');
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
123
1351
81579df2ba8c Tests: fixed perl 5.28 "Unescaped left brace in regex" warnings.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
124 ($data) = $r =~ qr!(\{[^}]*?"name"\s*:\s*"test-file".*?})!;
518
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
125 like($data, qr!"type"\s*:\s*"file"!, 'json file');
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
126 like($data, $mtime, 'json file mtime');
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
127 like($data, qr!"size"\s*:\s*42!, 'json file size');
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
128
1351
81579df2ba8c Tests: fixed perl 5.28 "Unescaped left brace in regex" warnings.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
129 ($data) = $r =~ qr!(\{[^}]*?"name"\s*:\s*"test-file-link".*?})!;
518
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
130 like($data, qr!"type"\s*:\s*"file"!, 'json file link');
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
131 like($data, $mtime, 'json file link mtime');
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
132 like($data, qr!"size"\s*:\s*42!, 'json file link size');
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
133
1351
81579df2ba8c Tests: fixed perl 5.28 "Unescaped left brace in regex" warnings.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
134 ($data) = $r =~ qr!(\{[^}]*?"name"\s*:\s*"test-dir".*?})!;
518
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
135 like($data, qr!"type"\s*:\s*"directory"!, 'json dir');
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
136 like($data, $mtime, 'json dir mtime');
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
137 unlike($data, qr!"size"\s*:\s*$number!, 'json dir size');
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
138
1351
81579df2ba8c Tests: fixed perl 5.28 "Unescaped left brace in regex" warnings.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
139 ($data) = $r =~ qr!(\{[^}]*?"name"\s*:\s*"test-dir-link".*?})!;
518
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
140 like($data, qr!"type"\s*:\s*"directory"!, 'json dir link');
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
141 like($data, $mtime, 'json dir link mtime');
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
142 unlike($data, qr!"size"\s*:\s*$number!, 'json dir link size');
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
143
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
144 like($r, qr!"name"\s*:\s*"test-'-quote"!, 'json quote');
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
145 like($r, qr!"name"\s*:\s*"test-\\\"-double"!, 'json double');
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
146 like($r, qr!"name"\s*:\s*"test-<>-angle"!, 'json angle');
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
147
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
148 like(http_get_body('/jsonp/test-dir/?callback=foo'),
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
149 qr/^\s*foo\s*\(\s*\[\s*\]\s*\)\s*;\s*$/ms, 'jsonp callback');
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
150 like(http_get_body('/jsonp/test-dir/?callback='),
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
151 qr/^\s*\[\s*\s*\]\s*$/ms, 'jsonp callback empty');
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
152
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
153 # utf8 tests
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
154
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
155 $r = http_get('/xml/utf8/');
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
156 like($r, qr!test-utf8-(\xd1\x84){3}</file>!ms, 'xml utf8');
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
157 like($r, qr!test-utf8-(\xd1\x84){45}</file>!ms, 'xml utf8 long');
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
158
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
159 $r = http_get('/json/utf8/');
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
160 like($r, qr!test-utf8-(\xd1\x84){3}"!ms, 'json utf8');
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
161 like($r, qr!test-utf8-(\xd1\x84){45}"!ms, 'json utf8 long');
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
162
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
163 ###############################################################################
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
164
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
165 sub http_get_body {
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
166 my ($uri) = @_;
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
167
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
168 return undef if !defined $uri;
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
169
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
170 http_get($uri) =~ /(.*?)\x0d\x0a?\x0d\x0a?(.*)/ms;
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
171
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
172 return $2;
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
173 }
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
174
9edb609a2642 Tests: autoindex module tests with autoindex_format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
175 ###############################################################################