diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-13 21:12:02 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-13 21:12:02 +0000 |
commit | 77e50caaf2ef81cd91075cf836fed0e75718ffb4 (patch) | |
tree | 53b7b411290b63192fc9e924a3b6b65cdf67e9d0 /debian/vendor-h2o/t/50reverse-proxy-config.t | |
parent | Adding upstream version 1.8.3. (diff) | |
download | dnsdist-77e50caaf2ef81cd91075cf836fed0e75718ffb4.tar.xz dnsdist-77e50caaf2ef81cd91075cf836fed0e75718ffb4.zip |
Adding debian version 1.8.3-2.debian/1.8.3-2
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'debian/vendor-h2o/t/50reverse-proxy-config.t')
-rw-r--r-- | debian/vendor-h2o/t/50reverse-proxy-config.t | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/debian/vendor-h2o/t/50reverse-proxy-config.t b/debian/vendor-h2o/t/50reverse-proxy-config.t new file mode 100644 index 0000000..62b3466 --- /dev/null +++ b/debian/vendor-h2o/t/50reverse-proxy-config.t @@ -0,0 +1,104 @@ +use strict; +use warnings; +use Digest::MD5 qw(md5_hex); +use Net::EmptyPort qw(check_port empty_port); +use Test::More; +use t::Util; + +plan skip_all => 'plackup not found' + unless prog_exists('plackup'); + +plan skip_all => 'Starlet not found' + unless system('perl -MStarlet /dev/null > /dev/null 2>&1') == 0; + +plan skip_all => 'curl not found' + unless prog_exists('curl'); + +# start upstream +my $upstream_port = empty_port(); +my $upstream = spawn_server( + argv => [ + qw(plackup -MPlack::App::File -s Starlet --access-log /dev/null -p), $upstream_port, + ASSETS_DIR . "/upstream.psgi", + ], + is_ready => sub { + check_port($upstream_port); + }, +); + +subtest 'preserve-host' => sub { + my $doit = sub { + my $flag = shift; + my $server = spawn_h2o(<< "EOT"); +hosts: + default: + paths: + /: + proxy.reverse.url: http://127.0.0.1:$upstream_port + proxy.preserve-host: @{[ $flag ? 'ON' : 'OFF' ]} +EOT + my $res = `curl --silent http://127.0.0.1:$server->{port}/echo-headers`; + like $res, qr/^host: 127.0.0.1:@{[ $flag ? $server->{port} : $upstream_port ]}$/im, 'host header'; + + $res = `curl --silent --dump-header /dev/stdout "http://127.0.0.1:$server->{port}/?resp:status=302&resp:location=http://127.0.0.1:$server->{port}/foo"`; + like $res, qr{^location: http://127\.0\.0\.1:$server->{port}/foo}im, 'location: :server_port'; + warn qq{curl --silent --dump-header /dev/stdout "http://127.0.0.1:$server->{port}/?resp:status=302&resp:location=http://127.0.0.1:$upstream_port/foo"}; + $res = `curl --silent --dump-header /dev/stdout "http://127.0.0.1:$server->{port}/?resp:status=302&resp:location=http://127.0.0.1:$upstream_port/foo"`; + like $res, qr{^location: http://127\.0\.0\.1:$server->{port}/foo}im, 'location :upstream_port'; + }; + + subtest 'ON' => sub { + $doit->(1); + }; + subtest 'OFF' => sub { + $doit->(0); + }; +}; + +subtest 'timeout.io' => sub { + my $server = spawn_h2o(<< "EOT"); +hosts: + default: + paths: + /: + proxy.reverse.url: http://127.0.0.1:$upstream_port + proxy.timeout.io: 2000 +EOT + my $fetch = sub { + my $sleep = shift; + `curl --silent --dump-header /dev/stderr http://127.0.0.1:$server->{port}/sleep-and-respond?sleep=$sleep 2>&1 > /dev/null`; + }; + my $resp = $fetch->(1); + like $resp, qr{^HTTP/1\.1 200 }s, "respond before timeout"; + $resp = $fetch->(3); + like $resp, qr{^HTTP/1\.1 502 }s, "respond after timeout"; +}; + +subtest 'infinite-internal-redirect' => sub { + my $server = spawn_h2o(<< "EOT"); +hosts: + default: + paths: + /: + proxy.reverse.url: http://127.0.0.1:$upstream_port +reproxy: ON +EOT + my $resp = `curl --silent --dump-header /dev/stderr "http://127.0.0.1:$server->{port}/?resp:x-reproxy-url=http://127.0.0.1:$upstream_port/infinite-redirect" 2>&1 > /dev/null`; + like $resp, qr{^HTTP/1\.1 502 }s; +}; + +subtest 'max-delegations' => sub { + my $server = spawn_h2o(<< "EOT"); +hosts: + default: + paths: + /: + proxy.reverse.url: http://127.0.0.1:$upstream_port +reproxy: ON +max-delegations: 0 +EOT + my $resp = `curl --silent --dump-header /dev/stderr "http://127.0.0.1:$server->{port}/?resp:x-reproxy-url=http://127.0.0.1:$upstream_port/index.txt" 2>&1 > /dev/null`; + like $resp, qr{^HTTP/1\.1 502 }s; +}; + +done_testing; |