diff options
author | Sven Nierlein <sven@consol.de> | 2024-07-29 18:53:32 (GMT) |
---|---|---|
committer | Sven Nierlein <sven@nierlein.org> | 2024-07-30 15:13:03 (GMT) |
commit | acbfbf3de614f03ea5f9d3942558f1661fc202a4 (patch) | |
tree | c19efcc783679d7f6b3b5686d2111052f3882128 /plugins/tests | |
parent | 4ab154d5c3640d7f2cc3180d2f05ac688be7a11b (diff) | |
download | monitoring-plugins-acbfbf3de614f03ea5f9d3942558f1661fc202a4.tar.gz |
check_curl: fix relative redirects on non-standard port
Having a webserver respond with a relative redirect as for ex. in `Location: /path/to.html`
check_curl would use the wrong standard http/https port instead
of crafting the absolute url using the given scheme/hostname and port.
Adding a new test case for this for check_http and check_curl. check_http did
it correct already, so no fix necessary there.
before:
%>./check_curl -H 127.0.0.1 -p 50493 -f follow -u /redirect_rel -s redirected -vvv
**** HEADER ****
HTTP/1.1 302 Found
...
Location: /redirect2
...
* Seen redirect location /redirect2
** scheme: (null)
** host: (null)
** port: (null)
** path: /redirect2
Redirection to http://127.0.0.1:80/redirect2
fixed:
%>./check_curl -H 127.0.0.1 -p 50493 -f follow -u /redirect_rel -s redirected -vvv
**** HEADER ****
HTTP/1.1 302 Found
...
Location: /redirect2
...
* Seen redirect location /redirect2
** scheme: (null)
** host: (null)
** port: (null)
** path: /redirect2
Redirection to http://127.0.0.1:50493/redirect2
Signed-off-by: Sven Nierlein <sven@nierlein.de>
Diffstat (limited to 'plugins/tests')
-rwxr-xr-x | plugins/tests/check_curl.t | 14 | ||||
-rwxr-xr-x | plugins/tests/check_http.t | 12 |
2 files changed, 22 insertions, 4 deletions
diff --git a/plugins/tests/check_curl.t b/plugins/tests/check_curl.t index 3c91483..eaa9f51 100755 --- a/plugins/tests/check_curl.t +++ b/plugins/tests/check_curl.t | |||
@@ -21,7 +21,7 @@ use FindBin qw($Bin); | |||
21 | 21 | ||
22 | $ENV{'LC_TIME'} = "C"; | 22 | $ENV{'LC_TIME'} = "C"; |
23 | 23 | ||
24 | my $common_tests = 73; | 24 | my $common_tests = 75; |
25 | my $ssl_only_tests = 8; | 25 | my $ssl_only_tests = 8; |
26 | # Check that all dependent modules are available | 26 | # Check that all dependent modules are available |
27 | eval "use HTTP::Daemon 6.01;"; | 27 | eval "use HTTP::Daemon 6.01;"; |
@@ -178,6 +178,11 @@ sub run_server { | |||
178 | $c->send_basic_header; | 178 | $c->send_basic_header; |
179 | $c->send_crlf; | 179 | $c->send_crlf; |
180 | $c->send_response(HTTP::Response->new( 200, 'OK', undef, 'redirected' )); | 180 | $c->send_response(HTTP::Response->new( 200, 'OK', undef, 'redirected' )); |
181 | } elsif ($r->url->path eq "/redirect_rel") { | ||
182 | $c->send_basic_header(302); | ||
183 | $c->send_header("Location", "/redirect2" ); | ||
184 | $c->send_crlf; | ||
185 | $c->send_response('moved to /redirect2'); | ||
181 | } elsif ($r->url->path eq "/redir_timeout") { | 186 | } elsif ($r->url->path eq "/redir_timeout") { |
182 | $c->send_redirect( "/timeout" ); | 187 | $c->send_redirect( "/timeout" ); |
183 | } elsif ($r->url->path eq "/timeout") { | 188 | } elsif ($r->url->path eq "/timeout") { |
@@ -471,9 +476,12 @@ sub run_common_tests { | |||
471 | is( $result->return_code, 0, $cmd); | 476 | is( $result->return_code, 0, $cmd); |
472 | like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output ); | 477 | like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output ); |
473 | 478 | ||
474 | # These tests may block | 479 | $cmd = "$command -f follow -u /redirect_rel -s redirected"; |
475 | print "ALRM\n"; | 480 | $result = NPTest->testCmd( $cmd ); |
481 | is( $result->return_code, 0, $cmd); | ||
482 | like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output ); | ||
476 | 483 | ||
484 | # These tests may block | ||
477 | # stickyport - on full urlS port is set back to 80 otherwise | 485 | # stickyport - on full urlS port is set back to 80 otherwise |
478 | $cmd = "$command -f stickyport -u /redir_external -t 5 -s redirected"; | 486 | $cmd = "$command -f stickyport -u /redir_external -t 5 -s redirected"; |
479 | eval { | 487 | eval { |
diff --git a/plugins/tests/check_http.t b/plugins/tests/check_http.t index 6078b27..6eaf85b 100755 --- a/plugins/tests/check_http.t +++ b/plugins/tests/check_http.t | |||
@@ -13,7 +13,7 @@ use IO::Socket::INET; | |||
13 | 13 | ||
14 | $ENV{'LC_TIME'} = "C"; | 14 | $ENV{'LC_TIME'} = "C"; |
15 | 15 | ||
16 | my $common_tests = 71; | 16 | my $common_tests = 73; |
17 | my $virtual_port_tests = 8; | 17 | my $virtual_port_tests = 8; |
18 | my $ssl_only_tests = 12; | 18 | my $ssl_only_tests = 12; |
19 | my $chunked_encoding_special_tests = 1; | 19 | my $chunked_encoding_special_tests = 1; |
@@ -199,6 +199,11 @@ sub run_server { | |||
199 | $c->send_basic_header; | 199 | $c->send_basic_header; |
200 | $c->send_crlf; | 200 | $c->send_crlf; |
201 | $c->send_response(HTTP::Response->new( 200, 'OK', undef, 'redirected' )); | 201 | $c->send_response(HTTP::Response->new( 200, 'OK', undef, 'redirected' )); |
202 | } elsif ($r->url->path eq "/redirect_rel") { | ||
203 | $c->send_basic_header(302); | ||
204 | $c->send_header("Location", "/redirect2" ); | ||
205 | $c->send_crlf; | ||
206 | $c->send_response('moved to /redirect2'); | ||
202 | } elsif ($r->url->path eq "/redir_timeout") { | 207 | } elsif ($r->url->path eq "/redir_timeout") { |
203 | $c->send_redirect( "/timeout" ); | 208 | $c->send_redirect( "/timeout" ); |
204 | } elsif ($r->url->path eq "/timeout") { | 209 | } elsif ($r->url->path eq "/timeout") { |
@@ -515,6 +520,11 @@ sub run_common_tests { | |||
515 | is( $result->return_code, 0, $cmd); | 520 | is( $result->return_code, 0, $cmd); |
516 | like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output ); | 521 | like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output ); |
517 | 522 | ||
523 | $cmd = "$command -f follow -u /redirect_rel -s redirected"; | ||
524 | $result = NPTest->testCmd( $cmd ); | ||
525 | is( $result->return_code, 0, $cmd); | ||
526 | like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output ); | ||
527 | |||
518 | # These tests may block | 528 | # These tests may block |
519 | print "ALRM\n"; | 529 | print "ALRM\n"; |
520 | 530 | ||