From 198611a3c2bd89562af87d8bf0c7584fce1ce037 Mon Sep 17 00:00:00 2001 From: Markus Frosch Date: Tue, 6 Nov 2018 11:32:52 +0100 Subject: test: Add proxy tests via proxy On Travis with a local squid --- plugins/t/NPTest.cache.travis | 2 ++ plugins/t/check_http.t | 26 +++++++++++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) (limited to 'plugins') diff --git a/plugins/t/NPTest.cache.travis b/plugins/t/NPTest.cache.travis index e9705f3b..28437a00 100644 --- a/plugins/t/NPTest.cache.travis +++ b/plugins/t/NPTest.cache.travis @@ -59,4 +59,6 @@ 'host_udp_time' => 'none', 'host_tls_http' => 'localhost', 'host_tls_cert' => 'localhost', + 'NP_HOST_TCP_PROXY' => 'localhost', + 'NP_PORT_TCP_PROXY' => '3128', } diff --git a/plugins/t/check_http.t b/plugins/t/check_http.t index 8bd484a0..416fbbcb 100644 --- a/plugins/t/check_http.t +++ b/plugins/t/check_http.t @@ -9,7 +9,7 @@ use Test::More; use POSIX qw/mktime strftime/; use NPTest; -plan tests => 49; +plan tests => 55; my $successOutput = '/OK.*HTTP.*second/'; @@ -42,6 +42,14 @@ my $host_tcp_http2 = getTestParameter( "NP_HOST_TCP_HTTP2", "A host providing an index page containing the string 'monitoring'", "test.monitoring-plugins.org" ); +my $host_tcp_proxy = getTestParameter( "NP_HOST_TCP_PROXY", + "A host providing a HTTP proxy with CONNECT support", + "localhost"); + +my $port_tcp_proxy = getTestParameter( "NP_PORT_TCP_PROXY", + "Port of the proxy with HTTP and CONNECT support", + "3128"); + my $faketime = -x '/usr/bin/faketime' ? 1 : 0; @@ -198,3 +206,19 @@ SKIP: { $res = NPTest->testCmd( "./check_http -H www.mozilla.com --extended-perfdata" ); like ( $res->output, '/time_connect=[\d\.]+/', 'Extended Performance Data Output OK' ); } + +SKIP: { + skip "No internet access or proxy configured", 6 if $internet_access eq "no" or ! $host_tcp_proxy; + + $res = NPTest->testCmd( "./check_http -I $host_tcp_proxy -p $port_tcp_proxy -u http://$host_tcp_http -e 200,301,302"); + is( $res->return_code, 0, "Proxy HTTP works"); + like($res->output, qr/OK: Status line output matched/, "Proxy HTTP Output is sufficent"); + + $res = NPTest->testCmd( "./check_http -I $host_tcp_proxy -p $port_tcp_proxy -H $host_tls_http -S -j CONNECT"); + is( $res->return_code, 0, "Proxy HTTP CONNECT works"); + like($res->output, qr/HTTP OK:/, "Proxy HTTP CONNECT output sufficent"); + + $res = NPTest->testCmd( "./check_http -I $host_tcp_proxy -p $port_tcp_proxy -H $host_tls_http -S -j CONNECT:HEAD"); + is( $res->return_code, 0, "Proxy HTTP CONNECT works with override method"); + like($res->output, qr/HTTP OK:/, "Proxy HTTP CONNECT output sufficent"); +} -- cgit v1.2.3-74-g34f1