From 6b50b6908b37ad039a3635c2c97ad2ada5fd7422 Mon Sep 17 00:00:00 2001 From: Lari Taskula Date: Sun, 19 Oct 2025 11:03:27 +0300 Subject: [PATCH] Bug 41011: Add test --- t/Auth.t | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/t/Auth.t b/t/Auth.t index ff1201329c6..622227e4e51 100755 --- a/t/Auth.t +++ b/t/Auth.t @@ -17,7 +17,7 @@ use Modern::Perl; use Test::NoWarnings; -use Test::More tests => 13; +use Test::More tests => 14; use Test::Warn; use C4::Auth qw( in_iprange ); @@ -42,3 +42,23 @@ ok( 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' ); + +subtest 'test localhost' => sub { + plan tests => 2; + + sub _localhost_test { + my $REMOTE_ADDR = shift; + subtest "test REMOTE_ADDR = $REMOTE_ADDR" => sub { + plan tests => 3; + $ENV{REMOTE_ADDR} = $REMOTE_ADDR; + + ok(in_iprange('::1 127.0.0.1'), 'REMOTE_ADDR is in_iprange(::1 127.0.0.1)'); + ok(in_iprange($REMOTE_ADDR), 'REMOTE_ADDR is in_iprange('.$REMOTE_ADDR.')'); + my $opposite = $REMOTE_ADDR eq '127.0.0.1' ? '::1' : '127.0.0.1'; + ok(!in_iprange($opposite), 'REMOTE_ADDR is not in_iprange('.$opposite.')'); + }; + } + + _localhost_test('127.0.0.1'); + _localhost_test('::1'); +}; -- 2.34.1