Skip to content

Commit

Permalink
QATAPP-23476: Rebase nginx-tests to support nginx 1.20.1
Browse files Browse the repository at this point in the history
Signed-off-by: Chengfei Zhu <chengfei.zhu@intel.com>
  • Loading branch information
zhangp8x authored and cfzhu committed Aug 5, 2021
1 parent 9c15d5e commit 259cf1c
Show file tree
Hide file tree
Showing 199 changed files with 8,524 additions and 1,812 deletions.
4 changes: 4 additions & 0 deletions test/nginx-tests/README
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,8 @@ TEST_NGINX_GLOBALS_HTTP

Sets additional directives in http context.

TEST_NGINX_GLOBALS_STREAM

Sets additional directives in stream context.

Happy testing!
18 changes: 15 additions & 3 deletions test/nginx-tests/access_log.t
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use Test::Nginx;
select STDERR; $| = 1;
select STDOUT; $| = 1;

my $t = Test::Nginx->new()->has(qw/http rewrite gzip/)->plan(18)
my $t = Test::Nginx->new()->has(qw/http rewrite gzip/)->plan(19)
->write_file_expand('nginx.conf', <<'EOF');
%%TEST_GLOBALS%%
Expand All @@ -38,6 +38,7 @@ http {
log_format test "$uri:$status";
log_format long "long line $uri:$status";
log_format addr "$remote_addr:$remote_port:$server_addr:$server_port";
log_format binary $binary_remote_addr;
log_format default escape=default $arg_a$arg_b$arg_c;
Expand Down Expand Up @@ -102,6 +103,10 @@ http {
return 200 OK;
}
location /addr {
access_log %%TESTDIR%%/addr.log addr;
}
location /binary {
access_log %%TESTDIR%%/binary.log binary;
}
Expand Down Expand Up @@ -156,6 +161,13 @@ http_get('/varlog?logname=');
http_get('/varlog?logname=0');
http_get('/varlog?logname=filename');

my $s = http('', start => 1);
http_get('/addr', socket => $s);
my $addr = $s->sockhost();
my $port = $s->sockport();
my $saddr = $s->peerhost();
my $sport = $s->peerport();

http_get('/binary');

http_get('/escape?a="1 \\ ' . pack("n", 0x1b1c) . ' "&c=2');
Expand Down Expand Up @@ -204,8 +216,6 @@ $t->stop();

# verify that by default, 'combined' format is used, 'off' disables logging

my $addr = IO::Socket::INET->new(LocalAddr => '127.0.0.1')->sockhost();

like($t->read_file('combined.log'),
qr!^\Q$addr - - [\E .*
\Q] "GET /combined HTTP/1.0" 200 2 "-" "-"\E$!x,
Expand Down Expand Up @@ -250,6 +260,8 @@ is($t->read_file('long.log'), "long line /multi:200\n", 'long line format');
is($t->read_file('varlog_0'), "/varlog:200\n", 'varlog literal zero name');
is($t->read_file('varlog_filename'), "/varlog:200\n", 'varlog good name');

is($t->read_file('addr.log'), "$addr:$port:$saddr:$sport\n", 'addr');

# binary data is escaped
# that's "\\x7F\\x00\\x00\\x01\n" in $binary_remote_addr for "127.0.0.1"

Expand Down
14 changes: 14 additions & 0 deletions test/nginx-tests/binary_upgrade.t
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,17 @@ events {
http {
%%TEST_GLOBALS_HTTP%%
server {
listen unix:%%TESTDIR%%/unix.sock;
server_name localhost;
}
}
EOF

my $d = $t->testdir();

$t->run();

###############################################################################
Expand All @@ -66,21 +69,32 @@ for (1 .. 30) {
last if ! -e "$d/nginx.pid.oldbin";
select undef, undef, undef, 0.2
}

ok(-e "$d/unix.sock", 'unix socket exists on old master shutdown');

# unix socket on new master termination

$pid = $t->read_file('nginx.pid');

kill 'USR2', $pid;

for (1 .. 30) {
last if -e "$d/nginx.pid" && -e "$d/nginx.pid.oldbin";
select undef, undef, undef, 0.2
}

kill 'TERM', $t->read_file('nginx.pid');

for (1 .. 30) {
last if ! -e "$d/nginx.pid.oldbin";
select undef, undef, undef, 0.2
}

TODO: {
$TODO = 'not yet' unless $t->has_version('1.19.1');

ok(-e "$d/unix.sock", 'unix socket exists on new master termination');

}

###############################################################################
4 changes: 4 additions & 0 deletions test/nginx-tests/body.t
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,10 @@ like(http_get_body('/next', '0123456789'),
qr/X-Body: 0123456789\x0d?$/ms, 'body next upstream');

# discarded request body in redirect via error_page

TODO: {
local $TODO = 'not yet' unless $t->has_version('1.17.7');

unlike(
http(
'POST /redirect HTTP/1.1' . CRLF
Expand All @@ -182,7 +184,9 @@ unlike(
),
qr/400 Bad Request/ms, 'redirect - discard request body'
);

}

###############################################################################

sub read_body_file {
Expand Down
10 changes: 10 additions & 0 deletions test/nginx-tests/body_chunked.t
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,10 @@ like(http_get_body('/discard', '0123456789' x 128, '0123456789' x 512,
'chunked body discard 2');

# invalid chunks

TODO: {
local $TODO = 'not yet' unless $t->has_version('1.17.4');

like(
http(
'GET / HTTP/1.1' . CRLF
Expand All @@ -150,6 +152,7 @@ like(
),
qr/400 Bad/, 'runaway chunk'
);

like(
http(
'GET /discard HTTP/1.1' . CRLF
Expand All @@ -162,19 +165,24 @@ like(
),
qr/400 Bad/, 'runaway chunk discard'
);

}

# proxy_next_upstream

like(http_get_body('/next', '0123456789'),
qr/X-Body: 0123456789\x0d?$/ms, 'body chunked next upstream');
# invalid Transfer-Encoding

TODO: {
local $TODO = 'not yet' unless $t->has_version('1.17.9');

like(http_transfer_encoding('identity'), qr/501 Not Implemented/,
'transfer encoding identity');
like(http_transfer_encoding("chunked\nTransfer-Encoding: chunked"),
qr/400 Bad/, 'transfer encoding repeat');
}

like(http_transfer_encoding('chunked, identity'), qr/501 Not Implemented/,
'transfer encoding list');

Expand Down Expand Up @@ -215,10 +223,12 @@ sub http_get_body {

sub http_transfer_encoding {
my ($encoding) = @_;

http("GET / HTTP/1.1" . CRLF
. "Host: localhost" . CRLF
. "Connection: close" . CRLF
. "Transfer-Encoding: $encoding" . CRLF . CRLF
. "0" . CRLF . CRLF);
}

###############################################################################
122 changes: 113 additions & 9 deletions test/nginx-tests/dav.t
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use Test::Nginx;
select STDERR; $| = 1;
select STDOUT; $| = 1;

my $t = Test::Nginx->new()->has(qw/http dav/)->plan(20);
my $t = Test::Nginx->new()->has(qw/http dav/)->plan(28);

$t->write_file_expand('nginx.conf', <<'EOF');
Expand All @@ -40,6 +40,8 @@ http {
listen 127.0.0.1:8080;
server_name localhost;
absolute_redirect off;
location / {
dav_methods PUT DELETE MKCOL COPY MOVE;
}
Expand Down Expand Up @@ -107,6 +109,21 @@ like($r, qr/201 Created.*(Content-Length|\x0d\0a0\x0d\x0a)/ms,
is(-s $t->testdir() . '/file', 10,
'put file extra data size');

TODO: {
local $TODO = 'not yet' unless $t->has_version('1.21.0');

$r = http(<<EOF . '0123456789');
PUT /file%20sp HTTP/1.1
Host: localhost
Connection: close
Content-Length: 10
EOF

like($r, qr!Location: /file%20sp\x0d?$!ms, 'put file escaped');

}

# 201 replies contain body, response should indicate it's empty

$r = http(<<EOF);
Expand All @@ -118,6 +135,18 @@ EOF

like($r, qr/201 Created.*(Content-Length|\x0d\0a0\x0d\x0a)/ms, 'mkcol');

SKIP: {
skip 'perl too old', 1 if !$^V or $^V lt v5.12.0;

TODO: {
local $TODO = 'not yet' unless $t->has_version('1.17.7');

like($r, qr!(?(?{ $r =~ /Location/ })Location: /test/)!, 'mkcol location');

}

}

$r = http(<<EOF);
COPY /test/ HTTP/1.1
Host: localhost
Expand Down Expand Up @@ -147,7 +176,6 @@ Connection: close
EOF

like($r, qr/204 No Content/, 'copy file escaped');

is(-s $t->testdir() . '/file-moved escape', 10, 'file copied unescaped');

$t->write_file('file.exist', join '', (1 .. 42));
Expand All @@ -161,14 +189,8 @@ Connection: close
EOF

like($r, qr/204 No Content/, 'copy file overwrite');

TODO: {
local $TODO = 'not yet' unless $t->has_version('1.15.3');

is(-s $t->testdir() . '/file.exist', 10, 'target file truncated');

}

$r = http(<<EOF . '0123456789');
PUT /i/alias HTTP/1.1
Host: localhost
Expand All @@ -178,7 +200,89 @@ Content-Length: 10
EOF

like($r, qr/201 Created.*(Content-Length|\x0d\0a0\x0d\x0a)/ms, 'put alias');
like($r, qr!Location: http://localhost:\d+/i/alias\x0d?$!ms, 'location alias');
like($r, qr!Location: /i/alias\x0d?$!ms, 'location alias');
is(-s $t->testdir() . '/alias', 10, 'put alias size');

# request methods with unsupported request body

$r = http(<<EOF . '0123456789');
MKCOL /test/ HTTP/1.1
Host: localhost
Connection: close
Content-Length: 10
EOF

like($r, qr/415 Unsupported/, 'mkcol body');

$r = http(<<EOF . '0123456789');
COPY /file HTTP/1.1
Host: localhost
Destination: /file.exist
Connection: close
Content-Length: 10
EOF

like($r, qr/415 Unsupported/, 'copy body');


$r = http(<<EOF . '0123456789');
DELETE /file HTTP/1.1
Host: localhost
Connection: close
Content-Length: 10
EOF

like($r, qr/415 Unsupported/, 'delete body');

TODO: {
local $TODO = 'not yet' unless $t->has_version('1.17.7');

$r = http(<<EOF);
MKCOL /test/ HTTP/1.1
Host: localhost
Connection: close
Transfer-Encoding: chunked
a
0123456789
0
EOF

like($r, qr/415 Unsupported/, 'mkcol body chunked');

$r = http(<<EOF);
COPY /file HTTP/1.1
Host: localhost
Destination: /file.exist
Connection: close
Transfer-Encoding: chunked
a
0123456789
0
EOF

like($r, qr/415 Unsupported/, 'copy body chunked');

$r = http(<<EOF);
DELETE /file HTTP/1.1
Host: localhost
Connection: close
Transfer-Encoding: chunked
a
0123456789
0
EOF

like($r, qr/415 Unsupported/, 'delete body chunked');

}

###############################################################################
1 change: 0 additions & 1 deletion test/nginx-tests/dav_chunked.t
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/bin/perl

# Copyright (C) Intel, Inc.
# (C) Maxim Dounin

# Tests for nginx dav module with chunked request body.
Expand Down
Loading

0 comments on commit 259cf1c

Please sign in to comment.