View | Details | Raw Unified | Return to bug 14407
Collapse All | Expand All

(-)a/C4/Auth.pm (-10 / +9 lines)
Lines 2118-2133 Returns 1 if the remote address is in the provided ipset, or 0 otherwise. Link Here
2118
=cut
2118
=cut
2119
2119
2120
sub in_ipset {
2120
sub in_ipset {
2121
 my ($ipset) = @_;
2121
    my ($ipset) = @_;
2122
 my @allowedipranges = split(' ', $ipset);
2122
    my $result = 1;
2123
 if (scalar @allowedipranges > 0) {
2123
    my @allowedipranges = $ipset ? split(' ', $ipset) : ();
2124
    my @rangelist;
2124
    if (scalar @allowedipranges > 0) {
2125
    eval { @rangelist = Net::CIDR::range2cidr(@allowedipranges); }; return 0 if $@;
2125
        my @rangelist;
2126
    unless (Net::CIDR::cidrlookup($ENV{'REMOTE_ADDR'}, @rangelist)) {
2126
        eval { @rangelist = Net::CIDR::range2cidr(@allowedipranges); }; return 0 if $@;
2127
      return 0;
2127
        eval { $result = Net::CIDR::cidrlookup($ENV{'REMOTE_ADDR'}, @rangelist) } || ( $ENV{DEBUG} && warn 'cidrlookup failed for ' . join(' ',@rangelist) );
2128
    }
2128
     }
2129
 }
2129
     return $result ? 1 : 0;
2130
 return 1;
2131
}
2130
}
2132
2131
2133
sub getborrowernumber {
2132
sub getborrowernumber {
(-)a/t/Auth.t (-3 / +8 lines)
Lines 16-25 Link Here
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
use Test::More tests => 10;
19
use Test::More tests => 13;
20
use Test::Warn;
20
21
21
use C4::Auth qw / in_ipset /;
22
use C4::Auth qw / in_ipset /;
22
use warnings;
23
23
24
$ENV{REMOTE_ADDR} = '192.168.1.30';
24
$ENV{REMOTE_ADDR} = '192.168.1.30';
25
my $ipset1 = "192.168.1.30";
25
my $ipset1 = "192.168.1.30";
Lines 34-36 ok(in_ipset("192.168.1.10-192.168.1.30"), 'validly represented ip range with rem Link Here
34
ok(in_ipset("127.0.0.1 192.168.1.30 192.168.2.10-192.168.2.25"), 'multiple ips and ranges, including the remote ip');
34
ok(in_ipset("127.0.0.1 192.168.1.30 192.168.2.10-192.168.2.25"), 'multiple ips and ranges, including the remote ip');
35
ok(!in_ipset("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");
35
ok(!in_ipset("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");
36
ok(in_ipset(""), "blank list given, no preference set - implies everything goes through.");
36
ok(in_ipset(""), "blank list given, no preference set - implies everything goes through.");
37
- 
37
ok(in_ipset(), "no list given, no preference set - implies everything goes through.");
38
ok(in_ipset("192.168.1.1/36"), 'simple invalid ip range/36 with remote ip in it');
39
$ENV{DEBUG} = 1;
40
warning_like { in_ipset("192.168.1.1/36") }
41
    qr/cidrlookup failed for/,
42
    'noisy simple invalid ip range/36 with remote ip in it';

Return to bug 14407