Mercurial > hg > nginx-tests
comparison access_log.t @ 1385:5eb82b417fd6
Tests: access_log escape tests merged.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Wed, 10 Oct 2018 19:15:49 +0300 |
parents | 7df2265e61be |
children | 03cf423ea140 |
comparison
equal
deleted
inserted
replaced
1384:965bddf88b8f | 1385:5eb82b417fd6 |
---|---|
1 #!/usr/bin/perl | 1 #!/usr/bin/perl |
2 | 2 |
3 # (C) Sergey Kandaurov | |
3 # (C) Nginx, Inc. | 4 # (C) Nginx, Inc. |
4 | 5 |
5 # Tests for access_log. | 6 # Tests for access_log. |
6 | 7 |
7 ############################################################################### | 8 ############################################################################### |
19 ############################################################################### | 20 ############################################################################### |
20 | 21 |
21 select STDERR; $| = 1; | 22 select STDERR; $| = 1; |
22 select STDOUT; $| = 1; | 23 select STDOUT; $| = 1; |
23 | 24 |
24 my $t = Test::Nginx->new()->has(qw/http rewrite gzip/)->plan(15) | 25 my $t = Test::Nginx->new()->has(qw/http rewrite gzip/)->plan(18) |
25 ->write_file_expand('nginx.conf', <<'EOF'); | 26 ->write_file_expand('nginx.conf', <<'EOF'); |
26 | 27 |
27 %%TEST_GLOBALS%% | 28 %%TEST_GLOBALS%% |
28 | 29 |
29 daemon off; | 30 daemon off; |
35 %%TEST_GLOBALS_HTTP%% | 36 %%TEST_GLOBALS_HTTP%% |
36 | 37 |
37 log_format test "$uri:$status"; | 38 log_format test "$uri:$status"; |
38 log_format long "long line $uri:$status"; | 39 log_format long "long line $uri:$status"; |
39 log_format binary $binary_remote_addr; | 40 log_format binary $binary_remote_addr; |
41 | |
42 log_format default escape=default $arg_a$arg_b$arg_c; | |
43 log_format none escape=none $arg_a$arg_b$arg_c; | |
44 log_format json escape=json $arg_a$arg_b$arg_c; | |
40 | 45 |
41 server { | 46 server { |
42 listen 127.0.0.1:8080; | 47 listen 127.0.0.1:8080; |
43 server_name localhost; | 48 server_name localhost; |
44 | 49 |
96 return 200 OK; | 101 return 200 OK; |
97 } | 102 } |
98 | 103 |
99 location /binary { | 104 location /binary { |
100 access_log %%TESTDIR%%/binary.log binary; | 105 access_log %%TESTDIR%%/binary.log binary; |
106 } | |
107 | |
108 location /escape { | |
109 access_log %%TESTDIR%%/test.log default; | |
110 access_log %%TESTDIR%%/none.log none; | |
111 access_log %%TESTDIR%%/json.log json; | |
101 } | 112 } |
102 } | 113 } |
103 } | 114 } |
104 | 115 |
105 EOF | 116 EOF |
144 http_get('/varlog?logname=0'); | 155 http_get('/varlog?logname=0'); |
145 http_get('/varlog?logname=filename'); | 156 http_get('/varlog?logname=filename'); |
146 | 157 |
147 http_get('/binary'); | 158 http_get('/binary'); |
148 | 159 |
160 http_get('/escape?a="1 \\ ' . pack("n", 0x1b1c) . ' "&c=2'); | |
161 | |
149 http_get('/cache?logname=lru'); | 162 http_get('/cache?logname=lru'); |
150 http_get('/cache?logname=lru'); | 163 http_get('/cache?logname=lru'); |
151 http_get('/cache?logname=once'); | 164 http_get('/cache?logname=once'); |
152 http_get('/cache?logname=first'); | 165 http_get('/cache?logname=first'); |
153 http_get('/cache?logname=first'); | 166 http_get('/cache?logname=first'); |
241 | 254 |
242 my $expected = join '', map { sprintf "\\x%02X", $_ } split /\./, $addr; | 255 my $expected = join '', map { sprintf "\\x%02X", $_ } split /\./, $addr; |
243 | 256 |
244 is($t->read_file('binary.log'), "$expected\n", 'binary'); | 257 is($t->read_file('binary.log'), "$expected\n", 'binary'); |
245 | 258 |
259 # characters escaping | |
260 | |
261 is($t->read_file('test.log'), | |
262 '\x221 \x5C \x1B\x1C \x22-2' . "\n", 'escape - default'); | |
263 is($t->read_file('none.log'), | |
264 '"1 \\ ' . pack("n", 0x1b1c) . " \"2\n", 'escape - none'); | |
265 is($t->read_file('json.log'), | |
266 '\"1 \\\\ \u001B\u001C \"2' . "\n", 'escape - json'); | |
267 | |
246 SKIP: { | 268 SKIP: { |
247 skip 'win32', 4 if $^O eq 'MSWin32'; | 269 skip 'win32', 4 if $^O eq 'MSWin32'; |
248 | 270 |
249 is(@{[$t->read_file('/dir/cache_lru') =~ /\//g]}, 2, 'cache - closed lru'); | 271 is(@{[$t->read_file('/dir/cache_lru') =~ /\//g]}, 2, 'cache - closed lru'); |
250 is(@{[$t->read_file('/dir/cache_once') =~ /\//g]}, 1, 'cache - min_uses'); | 272 is(@{[$t->read_file('/dir/cache_once') =~ /\//g]}, 1, 'cache - min_uses'); |