From 3529d7465d31234ec634939ed1a6bdc915b73ccd Mon Sep 17 00:00:00 2001 From: Sven Nierlein Date: Thu, 12 Jun 2014 11:45:49 +0200 Subject: tests: parts of the check_procs test only work when uid -2 exists skip those tests if the uid does not exist Signed-off-by: Sven Nierlein --- plugins/tests/check_procs.t | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) (limited to 'plugins/tests') diff --git a/plugins/tests/check_procs.t b/plugins/tests/check_procs.t index 1ad2c2f1..b153d5d2 100755 --- a/plugins/tests/check_procs.t +++ b/plugins/tests/check_procs.t @@ -48,21 +48,25 @@ SKIP: { like( $result->output, '/^PROCS OK: 1 process with command name \'launchd\', UID = 501 (.*)$/', "Output correct" ); } -$result = NPTest->testCmd( "$command -u -2 -w 2:2" ); -is( $result->return_code, 1, "Checking processes with userid=-2" ); -like( $result->output, '/^PROCS WARNING: 3 processes with UID = -2 \(nobody\)$/', "Output correct" ); +SKIP: { + skip 'user with uid -2 required', 8 unless getpwuid(-2); + + $result = NPTest->testCmd( "$command -u -2 -w 2:2" ); + is( $result->return_code, 1, "Checking processes with userid=-2" ); + like( $result->output, '/^PROCS WARNING: 3 processes with UID = -2 \(nobody\)$/', "Output correct" ); -$result = NPTest->testCmd( "$command -u -2 -w 3:3" ); -is( $result->return_code, 0, "Checking processes with userid=-2 past threshold" ); -like( $result->output, '/^PROCS OK: 3 processes with UID = -2 \(nobody\)$/', "Output correct" ); + $result = NPTest->testCmd( "$command -u -2 -w 3:3" ); + is( $result->return_code, 0, "Checking processes with userid=-2 past threshold" ); + like( $result->output, '/^PROCS OK: 3 processes with UID = -2 \(nobody\)$/', "Output correct" ); -$result = NPTest->testCmd( "$command -u -2 -a usb" ); -is( $result->return_code, 0, "Checking processes with userid=-2 and usb in arguments" ); -like( $result->output, '/^PROCS OK: 1 process with UID = -2 \(nobody\), args \'usb\'/', "Output correct" ); + $result = NPTest->testCmd( "$command -u -2 -a usb" ); + is( $result->return_code, 0, "Checking processes with userid=-2 and usb in arguments" ); + like( $result->output, '/^PROCS OK: 1 process with UID = -2 \(nobody\), args \'usb\'/', "Output correct" ); -$result = NPTest->testCmd( "$command -u -2 -a UsB" ); -is( $result->return_code, 0, "Checking case sensitivity of args" ); -like( $result->output, '/^PROCS OK: 0 processes with UID = -2 \(nobody\), args \'UsB\'/', "Output correct" ); + $result = NPTest->testCmd( "$command -u -2 -a UsB" ); + is( $result->return_code, 0, "Checking case sensitivity of args" ); + like( $result->output, '/^PROCS OK: 0 processes with UID = -2 \(nobody\), args \'UsB\'/', "Output correct" ); +}; $result = NPTest->testCmd( "$command --ereg-argument-array='mdworker.*501'" ); is( $result->return_code, 0, "Checking regexp search of arguments" ); -- cgit v1.2.3-74-g34f1 From c5a6c5136a2a7e629907b04a63dff059603bdb09 Mon Sep 17 00:00:00 2001 From: Sven Nierlein Date: Thu, 12 Jun 2014 13:56:48 +0200 Subject: tests: testCmd has own timeout which overwrites local one so add configurable/optional timeout to testCmd. Signed-off-by: Sven Nierlein --- NPTest.pm | 5 +++-- plugins/tests/check_http.t | 24 +++++++++--------------- 2 files changed, 12 insertions(+), 17 deletions(-) (limited to 'plugins/tests') diff --git a/NPTest.pm b/NPTest.pm index 2baed0b0..e04ebba3 100644 --- a/NPTest.pm +++ b/NPTest.pm @@ -627,12 +627,13 @@ sub only_output { } sub testCmd { - my $class = shift; + my $class = shift; my $command = shift or die "No command passed to testCmd"; + my $timeout = shift || 120; my $object = $class->new; local $SIG{'ALRM'} = sub { die("timeout in command: $command"); }; - alarm(120); # no test should take longer than 120 seconds + alarm($timeout); # no test should take longer than 120 seconds my $output = `$command`; $object->return_code($? >> 8); diff --git a/plugins/tests/check_http.t b/plugins/tests/check_http.t index 2c89beb0..c40bb076 100755 --- a/plugins/tests/check_http.t +++ b/plugins/tests/check_http.t @@ -392,27 +392,21 @@ sub run_common_tests { skip "This doesn't seems to work all the time", 1 unless ($ENV{HTTP_EXTERNAL}); $cmd = "$command -f follow -u /redir_external -t 5"; eval { - local $SIG{ALRM} = sub { die "alarm\n" }; - alarm(2); - $result = NPTest->testCmd( $cmd ); - alarm(0); }; - is( $@, "alarm\n", $cmd ); + $result = NPTest->testCmd( $cmd, 2 ); + }; + like( $@, "/timeout in command: $cmd/", $cmd ); } $cmd = "$command -u /timeout -t 5"; eval { - local $SIG{ALRM} = sub { die "alarm\n" }; - alarm(2); - $result = NPTest->testCmd( $cmd ); - alarm(0); }; - is( $@, "alarm\n", $cmd ); + $result = NPTest->testCmd( $cmd, 2 ); + }; + like( $@, "/timeout in command: $cmd/", $cmd ); $cmd = "$command -f follow -u /redir_timeout -t 2"; eval { - local $SIG{ALRM} = sub { die "alarm\n" }; - alarm(5); - $result = NPTest->testCmd( $cmd ); - alarm(0); }; - isnt( $@, "alarm\n", $cmd ); + $result = NPTest->testCmd( $cmd, 5 ); + }; + is( $@, "", $cmd ); } -- cgit v1.2.3-74-g34f1 From fb89accaaa831def2f948192a04eae84c4777531 Mon Sep 17 00:00:00 2001 From: Sven Nierlein Date: Fri, 13 Jun 2014 14:01:12 +0200 Subject: require at least HTTP::Daemon 6.01 since the test uses send_header from HTTP::Daemon::ClientConn which has been introduced in HTTP::Daemon 6.01 --- plugins/tests/check_http.t | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'plugins/tests') diff --git a/plugins/tests/check_http.t b/plugins/tests/check_http.t index c40bb076..225b449f 100755 --- a/plugins/tests/check_http.t +++ b/plugins/tests/check_http.t @@ -20,8 +20,9 @@ use FindBin qw($Bin); my $common_tests = 70; my $ssl_only_tests = 8; # Check that all dependent modules are available +eval "use HTTP::Daemon 6.01;"; +plan skip_all => 'HTTP::Daemon >= 6.01 required' if $@; eval { - require HTTP::Daemon; require HTTP::Status; require HTTP::Response; }; -- cgit v1.2.3-74-g34f1 From 4102eaae0e50d514eb277e12c9ab382aed3a888c Mon Sep 17 00:00:00 2001 From: Sven Nierlein Date: Fri, 13 Jun 2014 15:57:21 +0200 Subject: tests: check_proc tests fail if uid -2 does not map to nobody so make sure our tests only run if -2 maps to nobody Signed-off-by: Sven Nierlein --- plugins/tests/check_procs.t | 1 + 1 file changed, 1 insertion(+) (limited to 'plugins/tests') diff --git a/plugins/tests/check_procs.t b/plugins/tests/check_procs.t index b153d5d2..54d43d9b 100755 --- a/plugins/tests/check_procs.t +++ b/plugins/tests/check_procs.t @@ -50,6 +50,7 @@ SKIP: { SKIP: { skip 'user with uid -2 required', 8 unless getpwuid(-2); + skip 'uid -2 must have name "nobody"', 8 unless getpwuid(-2) eq 'nobody'; $result = NPTest->testCmd( "$command -u -2 -w 2:2" ); is( $result->return_code, 1, "Checking processes with userid=-2" ); -- cgit v1.2.3-74-g34f1 From b2fed383b1a04e64731333957fb098d77627cfdb Mon Sep 17 00:00:00 2001 From: Sven Nierlein Date: Fri, 13 Jun 2014 16:34:03 +0200 Subject: tests: freebsds snmpd does not use quotes when returning syscontact. So make them optional since we want to test check_snmp and not the snmpd. Signed-off-by: Sven Nierlein --- plugins/tests/check_snmp.t | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'plugins/tests') diff --git a/plugins/tests/check_snmp.t b/plugins/tests/check_snmp.t index d865e190..aace9bcc 100755 --- a/plugins/tests/check_snmp.t +++ b/plugins/tests/check_snmp.t @@ -79,7 +79,7 @@ Copyright (c) 1986-2004 by cisco Systems, Inc. $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.0 -o sysContact.0 -o .1.3.6.1.4.1.8072.3.2.67.1"); cmp_ok( $res->return_code, '==', 0, "Exit OK when querying multi-line OIDs" ); like($res->output, '/^SNMP OK - /', "String contains SNMP OK"); -like($res->output, '/'.quotemeta('SNMP OK - Cisco Internetwork Operating System Software "Alice" Kisco Outernetwork Oserating Gystem Totware | +like($res->output, '/'.quotemeta('SNMP OK - Cisco Internetwork Operating System Software ').'"?Alice"?'.quotemeta(' Kisco Outernetwork Oserating Gystem Totware | .1.3.6.1.4.1.8072.3.2.67.0: "Cisco Internetwork Operating System Software IOS (tm) Catalyst 4000 \"L3\" Switch Software (cat4000-I9K91S-M), Version -- cgit v1.2.3-74-g34f1 From b785a770e4fbcdd6d11717eeb6eb00172eac4fb8 Mon Sep 17 00:00:00 2001 From: Holger Weiss Date: Mon, 21 Jul 2014 21:52:33 +0200 Subject: plugins/tests/check_http.t: Adjust date strings Adjust the expected date strings to the now-localized output produced by plugins/sslutils.c. Closes #1275. --- plugins/tests/check_http.t | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'plugins/tests') diff --git a/plugins/tests/check_http.t b/plugins/tests/check_http.t index 225b449f..d93a0ecf 100755 --- a/plugins/tests/check_http.t +++ b/plugins/tests/check_http.t @@ -186,21 +186,21 @@ SKIP: { $result = NPTest->testCmd( "$command -p $port_https -S -C 14" ); is( $result->return_code, 0, "$command -p $port_https -S -C 14" ); - is( $result->output, 'OK - Certificate \'Ton Voon\' will expire on 03/03/2019 21:41.', "output ok" ); + is( $result->output, 'OK - Certificate \'Ton Voon\' will expire on Sun Mar 3 21:41:00 2019.', "output ok" ); $result = NPTest->testCmd( "$command -p $port_https -S -C 14000" ); is( $result->return_code, 1, "$command -p $port_https -S -C 14000" ); - like( $result->output, '/WARNING - Certificate \'Ton Voon\' expires in \d+ day\(s\) \(03/03/2019 21:41\)./', "output ok" ); + like( $result->output, '/WARNING - Certificate \'Ton Voon\' expires in \d+ day\(s\) \(Sun Mar 3 21:41:00 2019\)./', "output ok" ); # Expired cert tests $result = NPTest->testCmd( "$command -p $port_https -S -C 13960,14000" ); is( $result->return_code, 2, "$command -p $port_https -S -C 13960,14000" ); - like( $result->output, '/CRITICAL - Certificate \'Ton Voon\' expires in \d+ day\(s\) \(03/03/2019 21:41\)./', "output ok" ); + like( $result->output, '/CRITICAL - Certificate \'Ton Voon\' expires in \d+ day\(s\) \(Sun Mar 3 21:41:00 2019\)./', "output ok" ); $result = NPTest->testCmd( "$command -p $port_https_expired -S -C 7" ); is( $result->return_code, 2, "$command -p $port_https_expired -S -C 7" ); is( $result->output, - 'CRITICAL - Certificate \'Ton Voon\' expired on 03/05/2009 00:13.', + 'CRITICAL - Certificate \'Ton Voon\' expired on Thu Mar 5 00:13:00 2009.', "output ok" ); } -- cgit v1.2.3-74-g34f1