From 99fb0df9a67deff6be753cfd2f55c740aadb90fb Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Fri, 19 May 2023 12:02:54 -0400 Subject: [PATCH] Bug 28657: (QA follow-up) Return 1 if no range, improve unit tests Signed-off-by: Kyle M Hall --- C4/Auth.pm | 1 + t/Auth.t | 24 ++++++++++++------------ 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/C4/Auth.pm b/C4/Auth.pm index deed07b2ec..4f616333f5 100644 --- a/C4/Auth.pm +++ b/C4/Auth.pm @@ -2262,6 +2262,7 @@ Returns 1 if the remote address is in the provided iprange, or 0 otherwise. sub in_iprange { my ($iprange) = @_; + return 1 unless $iprange; my $result = 0; # FIXME remove '*' for backwards compatibility in branchip settings $iprange =~ s|\*||g; diff --git a/t/Auth.t b/t/Auth.t index d5b2f1e7fa..62db18df6a 100755 --- a/t/Auth.t +++ b/t/Auth.t @@ -23,15 +23,15 @@ use C4::Auth qw( in_iprange ); $ENV{REMOTE_ADDR} = '192.168.1.30'; -ok(in_iprange("192.168.1.30"), 'simple single ip matching remote ip'); -ok(!in_iprange("192.168.1.31"), 'simple single ip not match remote ip'); -ok(in_iprange("192.168.1.1/24"), 'simple ip range/24 with remote ip in it'); -ok(!in_iprange("192.168.2.1/24"), 'simple ip range/24 with remote ip not in it'); -ok(in_iprange("192.168.2.1/16"), 'simple ip range/16 with remote ip in it'); -ok(!in_iprange("192.168.1.10-30"), 'invalidly represented IP range with remote ip in it'); -ok(in_iprange("192.168.1.10-192.168.1.30"), 'validly represented ip range with remote ip in it'); -ok(in_iprange("127.0.0.1 192.168.1.30 192.168.2.10-192.168.2.25"), 'multiple ips and ranges, including the remote ip'); -ok(!in_iprange("127.0.0.1 8.8.8.8 192.168.2.1/24 192.168.3.1/24 192.168.1.1-192.168.1.29"), "multiple ip and ip ranges, with the remote ip in none of them"); -ok(in_iprange(""), "blank list given, no preference set - implies everything goes through."); -ok(in_iprange(), "no list given, no preference set - implies everything goes through."); -ok(in_iprange("192.168.1.1/36"), 'simple invalid ip range/36 with remote ip in it'); +is( 1, in_iprange("192.168.1.30"), 'simple single ip matching remote ip' ); +is( 0, in_iprange("192.168.1.31"), 'simple single ip not match remote ip' ); +is( 1, in_iprange("192.168.1.1/24"), 'simple ip range/24 with remote ip in it' ); +is( 0, in_iprange("192.168.2.1/24"), 'simple ip range/24 with remote ip not in it' ); +is( 1, in_iprange("192.168.2.1/16"), 'simple ip range/16 with remote ip in it' ); +is( 0, in_iprange("192.168.1.10-30"), 'invalidly represented IP range with remote ip in it' ); +is( 1, in_iprange("192.168.1.10-192.168.1.30"), 'validly represented ip range with remote ip in it' ); +is( 1, in_iprange("127.0.0.1 192.168.1.30 192.168.2.10-192.168.2.25"), 'multiple ips and ranges, including the remote ip' ); +is( 0, in_iprange("127.0.0.1 8.8.8.8 192.168.2.1/24 192.168.3.1/24 192.168.1.1-192.168.1.29" ), "multiple ip and ip ranges, with the remote ip in none of them" ); +is( 1, in_iprange(""), "blank list given, no preference set - implies everything goes through." ); +is( 1, in_iprange(), "no list given, no preference set - implies everything goes through." ); +is( 0, in_iprange("192.168.1.1/36"), 'simple invalid ip range/36 with remote ip in it' ); -- 2.30.2