check_dns: Tests and info

This commit is contained in:
Nicolai 2016-12-23 20:44:45 +01:00
parent 22e78763ea
commit ea756ac4ad
4 changed files with 26 additions and 3 deletions

4
NEWS
View file

@ -1,6 +1,10 @@
This file documents the major additions and syntax changes between releases.
2.3 [...]
ENHANCEMENTS
check_dns: allow 'expected address' (-a) to be specified in CIDR notation
(IPv4 only).
FIXES
Fix regression where check_dhcp was rereading response in a tight loop

View file

@ -355,3 +355,4 @@ Michael Melcher
Sven Geggus
Thomas Kurschel
Yannick Charton
Nicolai Søborg

View file

@ -308,7 +308,7 @@ ip_match_cidr(const char *addr, const char *cidr_ro)
mask = atoi(mask_c);
/* https://www.cryptobells.com/verifying-ips-in-a-subnet-in-php/ */
return ( ip2long(addr) & ~ ( ( 1 << ( 32 - mask ) ) - 1 ) ) == ( ip2long(subnet) >> (32 - mask) ) << (32 - mask);
return (ip2long(addr) & ~((1 << (32 - mask)) - 1)) == (ip2long(subnet) >> (32 - mask)) << (32 - mask);
}
unsigned long

View file

@ -10,7 +10,7 @@ use NPTest;
plan skip_all => "check_dns not compiled" unless (-x "check_dns");
plan tests => 16;
plan tests => 19;
my $successOutput = '/DNS OK: [\.0-9]+ seconds? response time/';
@ -23,7 +23,19 @@ my $hostname_valid = getTestParameter(
my $hostname_valid_ip = getTestParameter(
"NP_HOSTNAME_VALID_IP",
"The IP address of the valid hostname $hostname_valid",
"66.118.156.50",
"130.133.8.40",
);
my $hostname_valid_cidr = getTestParameter(
"NP_HOSTNAME_VALID_CIDR",
"An valid CIDR range containing $hostname_valid_ip",
"130.133.8.41/30",
);
my $hostname_invalid_cidr = getTestParameter(
"NP_HOSTNAME_INVALID_CIDR",
"An valid CIDR range not containing $hostname_valid_ip",
"130.133.8.39/30",
);
my $hostname_valid_reverse = getTestParameter(
@ -87,3 +99,9 @@ $res = NPTest->testCmd("./check_dns -H $hostname_valid_ip -a $hostname_valid_rev
cmp_ok( $res->return_code, '==', 0, "Got expected fqdn");
like ( $res->output, $successOutput, "Output OK");
$res = NPTest->testCmd("./check_dns -H $hostname_valid -a $hostname_valid_cidr -t 5");
cmp_ok( $res->return_code, '==', 0, "Got expected address");
$res = NPTest->testCmd("./check_dns -H $hostname_valid -a $hostname_invalid_cidr -t 5");
cmp_ok( $res->return_code, '==', 2, "Got wrong address");
like ( $res->output, "/^DNS CRITICAL.*expected '$hostname_invalid_cidr' but got '$hostname_valid_ip'".'$/', "Output OK");