diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-03-09 13:19:48 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-03-09 13:20:02 +0000 |
commit | 58daab21cd043e1dc37024a7f99b396788372918 (patch) | |
tree | 96771e43bb69f7c1c2b0b4f7374cb74d7866d0cb /web/server/h2o/libh2o/t/50errordoc.t | |
parent | Releasing debian version 1.43.2-1. (diff) | |
download | netdata-58daab21cd043e1dc37024a7f99b396788372918.tar.xz netdata-58daab21cd043e1dc37024a7f99b396788372918.zip |
Merging upstream version 1.44.3.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'web/server/h2o/libh2o/t/50errordoc.t')
-rw-r--r-- | web/server/h2o/libh2o/t/50errordoc.t | 179 |
1 files changed, 179 insertions, 0 deletions
diff --git a/web/server/h2o/libh2o/t/50errordoc.t b/web/server/h2o/libh2o/t/50errordoc.t new file mode 100644 index 000000000..6f847dae4 --- /dev/null +++ b/web/server/h2o/libh2o/t/50errordoc.t @@ -0,0 +1,179 @@ +use strict; +use warnings; +use Test::More; +use Test::Exception; +use t::Util; + +subtest 'basic' => sub { + my $server = spawn_h2o(<< "EOT"); +hosts: + default: + paths: + /: + file.dir: @{[DOC_ROOT]} +error-doc: + status: 404 + url: /404.html +EOT + + my $expected = do { + open my $fh, '<', "@{[DOC_ROOT]}/404.html" + or die "failed to read file:@{[DOC_ROOT]}/404.html:$!"; + local $/; + <$fh>; + }; + run_with_curl($server, sub { + my ($proto, $port, $curl) = @_; + my $resp = `$curl --silent $proto://127.0.0.1:$port/nonexist`; + is $resp, $expected, "content"; + $resp = `$curl --silent --dump-header /dev/stderr $proto://127.0.0.1:$port/nonexist 2>&1 > /dev/null`; + like $resp, qr{^HTTP/[^ ]+ 404\s}s, "status"; + like $resp, qr{\r\ncontent-type:\s*text/html.*\r\n}is, "content-type"; + like $resp, qr{\r\ncontent-length:\s*@{[length $expected]}\r\n}is, "content-length"; + unlike $resp, qr{\r\nlast-modified:}is, "no last-modified"; + unlike $resp, qr{\r\etag:}is, "no etag"; + }); +}; + +subtest 'double-error' => sub { + my $server = spawn_h2o(<< "EOT"); +hosts: + default: + paths: + /: + file.dir: @{[DOC_ROOT]} +error-doc: + status: 404 + url: /nonexist +EOT + + run_with_curl($server, sub { + my ($proto, $port, $curl) = @_; + my $resp = `$curl --silent $proto://127.0.0.1:$port/nonexist`; + is $resp, "not found", "content"; + $resp = `$curl --silent --dump-header /dev/stderr $proto://127.0.0.1:$port/nonexist 2>&1 > /dev/null`; + like $resp, qr{^HTTP/[^ ]+ 404\s}s, "status"; + like $resp, qr{\r\ncontent-type:\s*text/plain.*\r\n}is, "content-type"; + like $resp, qr{\r\ncontent-length:\s*@{[length "not found"]}\r\n}is, "content-length"; + unlike $resp, qr{\r\nlast-modified:}is, "no last-modified"; + unlike $resp, qr{\r\etag:}is, "no etag"; + }); +}; + +subtest 'redirect' => sub { + my $server = spawn_h2o(<< "EOT"); +hosts: + default: + paths: + /: + file.dir: @{[DOC_ROOT]} +error-doc: + status: 404 + url: /subdir +EOT + + my $expected = do { + open my $fh, '<', "@{[DOC_ROOT]}/subdir/index.txt" + or die "failed to read file:@{[DOC_ROOT]}/subdir/index.txt:$!"; + local $/; + <$fh>; + }; + run_with_curl($server, sub { + my ($proto, $port, $curl) = @_; + my $resp = `$curl --silent $proto://127.0.0.1:$port/nonexist`; + is $resp, $expected, "content"; + $resp = `$curl --silent --dump-header /dev/stderr $proto://127.0.0.1:$port/nonexist 2>&1 > /dev/null`; + like $resp, qr{^HTTP/[^ ]+ 404\s}s, "status"; + like $resp, qr{\r\ncontent-type:\s*text/plain.*\r\n}is, "content-type"; + like $resp, qr{\r\ncontent-length:\s*@{[length $expected]}\r\n}is, "content-length"; + unlike $resp, qr{\r\nlast-modified:}is, "no last-modified"; + unlike $resp, qr{\r\etag:}is, "no etag"; + }); +}; + +subtest 'multi-error' => sub { + my $server = spawn_h2o(<< "EOT"); +hosts: + default: + paths: + /: + file.dir: @{[DOC_ROOT]} +error-doc: + - status: 404 + url: /404.html + - status: 500 + url: /500.html +EOT + + run_with_curl($server, sub { + my ($proto, $port, $curl) = @_; + my $resp = `$curl --silent --dump-header /dev/stderr $proto://127.0.0.1:$port/nonexist 2>&1 > /dev/null`; + like $resp, qr{^HTTP/[^ ]+ 404\s}s, "status"; + }); +}; + +subtest 'multi-status-error' => sub { + my $server = spawn_h2o(<< "EOT"); +hosts: + default: + paths: + /: + file.dir: @{[DOC_ROOT]} +error-doc: + - status: [404, 405] + url: /404.html +EOT + + my $expected = do { + open my $fh, '<', "@{[DOC_ROOT]}/404.html" + or die "failed to read file:@{[DOC_ROOT]}/404.html:$!"; + local $/; + <$fh>; + }; + run_with_curl($server, sub { + my ($proto, $port, $curl) = @_; + my $resp = `$curl --silent $proto://127.0.0.1:$port/nonexist`; + is $resp, $expected, "content"; + $resp = `$curl --silent --dump-header /dev/stderr $proto://127.0.0.1:$port/nonexist 2>&1 > /dev/null`; + like $resp, qr{^HTTP/[^ ]+ 404\s}s, "status"; + }); + run_with_curl($server, sub { + my ($proto, $port, $curl) = @_; + my $resp = `$curl --silent -X POST $proto://127.0.0.1:$port/index.txt`; + is $resp, $expected, "content"; + $resp = `$curl --silent --dump-header /dev/stderr -X POST $proto://127.0.0.1:$port/index.txt 2>&1 > /dev/null`; + like $resp, qr{^HTTP/[^ ]+ 405\s}s, "status"; + }); +}; + +subtest "empty status" => sub { + throws_ok sub { + spawn_h2o(<< "EOT"); +hosts: + default: + paths: + /: + file.dir: @{[DOC_ROOT]} +error-doc: + - status: [] + url: /404.html +EOT + }, qr/server failed to start/, 'status must not be empty'; +}; + +subtest "duplicated statuses" => sub { + throws_ok sub { + spawn_h2o(<< "EOT"); +hosts: + default: + paths: + /: + file.dir: @{[DOC_ROOT]} +error-doc: + - status: [@{[ join(', ', (400 .. 599), 599) ]}] + url: /error.html +EOT + }, qr/server failed to start/, 'duplicated statuses'; +}; + +done_testing; |