Mercurial > hg > nginx-tests
changeset 1385:5eb82b417fd6
Tests: access_log escape tests merged.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Wed, 10 Oct 2018 19:15:49 +0300 |
parents | 965bddf88b8f |
children | 261f01ee5364 |
files | access_log.t access_log_escape.t access_log_none.t |
diffstat | 3 files changed, 23 insertions(+), 124 deletions(-) [+] |
line wrap: on
line diff
--- a/access_log.t Wed Oct 10 13:24:45 2018 +0300 +++ b/access_log.t Wed Oct 10 19:15:49 2018 +0300 @@ -1,5 +1,6 @@ #!/usr/bin/perl +# (C) Sergey Kandaurov # (C) Nginx, Inc. # Tests for access_log. @@ -21,7 +22,7 @@ select STDERR; $| = 1; select STDOUT; $| = 1; -my $t = Test::Nginx->new()->has(qw/http rewrite gzip/)->plan(15) +my $t = Test::Nginx->new()->has(qw/http rewrite gzip/)->plan(18) ->write_file_expand('nginx.conf', <<'EOF'); %%TEST_GLOBALS%% @@ -38,6 +39,10 @@ log_format long "long line $uri:$status"; log_format binary $binary_remote_addr; + log_format default escape=default $arg_a$arg_b$arg_c; + log_format none escape=none $arg_a$arg_b$arg_c; + log_format json escape=json $arg_a$arg_b$arg_c; + server { listen 127.0.0.1:8080; server_name localhost; @@ -99,6 +104,12 @@ location /binary { access_log %%TESTDIR%%/binary.log binary; } + + location /escape { + access_log %%TESTDIR%%/test.log default; + access_log %%TESTDIR%%/none.log none; + access_log %%TESTDIR%%/json.log json; + } } } @@ -146,6 +157,8 @@ http_get('/binary'); +http_get('/escape?a="1 \\ ' . pack("n", 0x1b1c) . ' "&c=2'); + http_get('/cache?logname=lru'); http_get('/cache?logname=lru'); http_get('/cache?logname=once'); @@ -243,6 +256,15 @@ is($t->read_file('binary.log'), "$expected\n", 'binary'); +# characters escaping + +is($t->read_file('test.log'), + '\x221 \x5C \x1B\x1C \x22-2' . "\n", 'escape - default'); +is($t->read_file('none.log'), + '"1 \\ ' . pack("n", 0x1b1c) . " \"2\n", 'escape - none'); +is($t->read_file('json.log'), + '\"1 \\\\ \u001B\u001C \"2' . "\n", 'escape - json'); + SKIP: { skip 'win32', 4 if $^O eq 'MSWin32';
--- a/access_log_escape.t Wed Oct 10 13:24:45 2018 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,63 +0,0 @@ -#!/usr/bin/perl - -# (C) Sergey Kandaurov -# (C) Nginx, Inc. - -# Tests for access_log with escape parameter. - -############################################################################### - -use warnings; -use strict; - -use Test::More; - -BEGIN { use FindBin; chdir($FindBin::Bin); } - -use lib 'lib'; -use Test::Nginx; - -############################################################################### - -select STDERR; $| = 1; -select STDOUT; $| = 1; - -my $t = Test::Nginx->new()->has(qw/http/)->plan(2) - ->write_file_expand('nginx.conf', <<'EOF'); - -%%TEST_GLOBALS%% - -daemon off; - -events { -} - -http { - %%TEST_GLOBALS_HTTP%% - - log_format json escape=json $arg_a$arg_b$arg_c; - log_format default escape=default $arg_a$arg_b$arg_c; - - server { - listen 127.0.0.1:8080; - server_name localhost; - - access_log %%TESTDIR%%/json.log json; - access_log %%TESTDIR%%/test.log default; - } -} - -EOF - -$t->run(); - -############################################################################### - -http_get('/?a="1 \\ ' . pack("n", 0x1b1c) . ' "&c=2'); - -$t->stop(); - -is($t->read_file('json.log'), '\"1 \\\\ \u001B\u001C \"2' . "\n", 'json'); -is($t->read_file('test.log'), '\x221 \x5C \x1B\x1C \x22-2' . "\n", 'default'); - -###############################################################################
--- a/access_log_none.t Wed Oct 10 13:24:45 2018 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,60 +0,0 @@ -#!/usr/bin/perl - -# (C) Sergey Kandaurov -# (C) Nginx, Inc. - -# Tests for access_log with escape parameter. - -############################################################################### - -use warnings; -use strict; - -use Test::More; - -BEGIN { use FindBin; chdir($FindBin::Bin); } - -use lib 'lib'; -use Test::Nginx; - -############################################################################### - -select STDERR; $| = 1; -select STDOUT; $| = 1; - -my $t = Test::Nginx->new()->has(qw/http/)->plan(1) - ->write_file_expand('nginx.conf', <<'EOF'); - -%%TEST_GLOBALS%% - -daemon off; - -events { -} - -http { - %%TEST_GLOBALS_HTTP%% - - log_format none escape=none $arg_a$arg_b$arg_c; - - server { - listen 127.0.0.1:8080; - server_name localhost; - - access_log %%TESTDIR%%/none.log none; - } -} - -EOF - -$t->run(); - -############################################################################### - -http_get('/?a="1 \\ ' . pack("n", 0x1b1c) . ' "&c=2'); - -$t->stop(); - -is($t->read_file('none.log'), '"1 \\ ' . pack("n", 0x1b1c) . " \"2\n", 'none'); - -###############################################################################