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

(-)a/t/Koha/Middlware/RealIP.t (-20 / +30 lines)
Lines 20-26 Link Here
20
20
21
use strict;
21
use strict;
22
use warnings;
22
use warnings;
23
use Test::More tests => 14;
23
use Test::More tests => 13;
24
use Test::Warn;
24
use Test::Warn;
25
25
26
use t::lib::Mocks;
26
use t::lib::Mocks;
Lines 85-106 t::lib::Mocks::mock_config('koha_trusted_proxies', '1.1.1.0:255.255.255.0'); Link Here
85
$address = Koha::Middleware::RealIP::get_real_ip( $remote_address, $x_forwarded_for_header );
85
$address = Koha::Middleware::RealIP::get_real_ip( $remote_address, $x_forwarded_for_header );
86
is($address,'2.2.2.2',"Trust proxy (1.1.1.1) using an IP address and netmask separated by a colon, so use the X-Forwarded-For header for the remote address");
86
is($address,'2.2.2.2',"Trust proxy (1.1.1.1) using an IP address and netmask separated by a colon, so use the X-Forwarded-For header for the remote address");
87
87
88
require Net::Netmask;
88
subtest "IPv6 support" => sub {
89
SKIP: {
89
    my ($remote_address,$x_forwarded_for_header,$address);
90
    skip "Net::Netmask at 1.9104+ supports IPv6", 2 unless Net::Netmask->VERSION < 1.9104;
90
    require Net::Netmask;
91
91
    if (Net::Netmask->VERSION < 1.9104){
92
    $remote_address         = "2001:db8:1234:5678:abcd:1234:abcd:1234";
92
        $remote_address         = "2001:db8:1234:5678:abcd:1234:abcd:1234";
93
    $x_forwarded_for_header = "2.2.2.2";
93
        $x_forwarded_for_header = "2.2.2.2";
94
    t::lib::Mocks::mock_config( 'koha_trusted_proxies', '2001:db8:1234:5678::/64' );
94
        t::lib::Mocks::mock_config( 'koha_trusted_proxies', '2001:db8:1234:5678::/64' );
95
    warning_is {
95
96
        $address = Koha::Middleware::RealIP::get_real_ip( $remote_address,
96
        warning_is {
97
            $x_forwarded_for_header );
97
            $address = Koha::Middleware::RealIP::get_real_ip( $remote_address,
98
                $x_forwarded_for_header );
99
        }
100
        "could not parse 2001:db8:1234:5678::/64",
101
          "Warn on IPv6 koha_trusted_proxies";
102
        is(
103
            $address,
104
            '2001:db8:1234:5678:abcd:1234:abcd:1234',
105
            "Unable to parse IPv6 address for trusted proxy, so ignore the X-Forwarded-For header"
106
        );
107
        done_testing(2);
108
    } else {
109
        $remote_address         = "2001:db8:1234:5678:abcd:1234:abcd:1234";
110
        $x_forwarded_for_header = "2.2.2.2";
111
        t::lib::Mocks::mock_config( 'koha_trusted_proxies', '2001:db8:1234:5678::/64' );
112
113
        $address = Koha::Middleware::RealIP::get_real_ip( $remote_address,$x_forwarded_for_header );
114
        is($address,'2.2.2.2',"Trust proxy (2001:db8:1234:5678:abcd:1234:abcd:1234) using IPv6 CIDR notation, so use the X-Forwarded-For header for the remote address");
115
        done_testing(1);
98
    }
116
    }
99
    "could not parse 2001:db8:1234:5678::/64",
117
};
100
      "Warn on IPv6 koha_trusted_proxies";
101
    is(
102
        $address,
103
        '2001:db8:1234:5678:abcd:1234:abcd:1234',
104
        "IPv6 support was added in 1.9104 version of Net::Netmask"
105
    );
106
}
107
- 

Return to bug 24739