From c0cf9b11fb4a21387126069ff8cd7e3400a8de39 Mon Sep 17 00:00:00 2001 From: Dylan William Hardison Date: Fri, 8 Jul 2016 12:13:09 -0400 Subject: Bug 1284277 - nits --- t/013remote_ip.t | 81 -------------------------------------------------------- t/015remote_ip.t | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+), 81 deletions(-) delete mode 100644 t/013remote_ip.t create mode 100644 t/015remote_ip.t (limited to 't') diff --git a/t/013remote_ip.t b/t/013remote_ip.t deleted file mode 100644 index 1cc832a9b..000000000 --- a/t/013remote_ip.t +++ /dev/null @@ -1,81 +0,0 @@ -#!/usr/bin/perl -# This Source Code Form is subject to the terms of the Mozilla Public -# License, v. 2.0. If a copy of the MPL was not distributed with this -# file, You can obtain one at http://mozilla.org/MPL/2.0/. -# -# This Source Code Form is "Incompatible With Secondary Licenses", as -# defined by the Mozilla Public License, v. 2.0. - -use strict; -use lib qw(. lib t); -use Test::More qw(no_plan); -use Bugzilla; -use Bugzilla::Util qw(remote_ip); - -my $params = Bugzilla->params; - -{ - local $params->{inbound_proxies} = '10.0.0.1,10.0.0.2'; - local $ENV{REMOTE_ADDR} = '10.0.0.2'; - local $ENV{HTTP_X_FORWARDED_FOR} = '10.42.42.42'; - - is(remote_ip(), '10.42.42.42', "from proxy 2"); -} - -{ - local $params->{inbound_proxies} = '10.0.0.1,10.0.0.2'; - local $ENV{REMOTE_ADDR} = '10.0.0.1'; - local $ENV{HTTP_X_FORWARDED_FOR} = '10.42.42.42'; - - is(remote_ip(), '10.42.42.42', "from proxy 1"); -} - -{ - local $params->{inbound_proxies} = '10.0.0.1,10.0.0.2'; - local $ENV{REMOTE_ADDR} = '10.0.0.3'; - local $ENV{HTTP_X_FORWARDED_FOR} = '10.42.42.42'; - - is(remote_ip(), '10.0.0.3', "not a proxy"); -} - -{ - local $params->{inbound_proxies} = '*'; - local $ENV{REMOTE_ADDR} = '10.0.0.3'; - local $ENV{HTTP_X_FORWARDED_FOR} = '10.42.42.42,1.4.9.2'; - - is(remote_ip(), '10.42.42.42', "always proxy"); -} - -{ - local $params->{inbound_proxies} = ''; - local $ENV{REMOTE_ADDR} = '10.9.8.7'; - local $ENV{HTTP_X_FORWARDED_FOR} = '10.42.42.42,1.4.9.2'; - - is(remote_ip(), '10.9.8.7', "never proxy"); -} - - -{ - local $params->{inbound_proxies} = '10.0.0.1,2600:cafe::cafe:ffff:bf42:4998'; - local $ENV{REMOTE_ADDR} = '2600:cafe::cafe:ffff:bf42:4998'; - local $ENV{HTTP_X_FORWARDED_FOR} = '2600:cafe::cafe:ffff:bf42:BEEF'; - - is(remote_ip(), '2600:cafe::cafe:ffff:bf42:BEEF', "from proxy ipv6"); -} - -{ - local $params->{inbound_proxies} = '10.0.0.1,2600:cafe::cafe:ffff:bf42:4998'; - local $ENV{REMOTE_ADDR} = '2600:cafe::cafe:ffff:bf42:DEAD'; - local $ENV{HTTP_X_FORWARDED_FOR} = '2600:cafe::cafe:ffff:bf42:BEEF'; - - is(remote_ip(), '2600:cafe::cafe:ffff:bf42:DEAD', "invalid proxy ipv6"); -} - - -{ - local $params->{inbound_proxies} = '*'; - local $ENV{REMOTE_ADDR} = '2600:cafe::cafe:ffff:bf42:DEAD'; - local $ENV{HTTP_X_FORWARDED_FOR} = ''; - - is(remote_ip(), '2600:cafe::cafe:ffff:bf42:DEAD', "always proxy ipv6"); -} diff --git a/t/015remote_ip.t b/t/015remote_ip.t new file mode 100644 index 000000000..bf0ebf3c2 --- /dev/null +++ b/t/015remote_ip.t @@ -0,0 +1,80 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# This Source Code Form is "Incompatible With Secondary Licenses", as +# defined by the Mozilla Public License, v. 2.0. + +use strict; +use lib qw(. lib t); +use Test::More qw(no_plan); +use Bugzilla; +use Bugzilla::Util qw(remote_ip); + +my $params = Bugzilla->params; + +{ + local $params->{inbound_proxies} = '10.0.0.1,10.0.0.2'; + local $ENV{REMOTE_ADDR} = '10.0.0.2'; + local $ENV{HTTP_X_FORWARDED_FOR} = '10.42.42.42'; + + is(remote_ip(), '10.42.42.42', "from proxy 2"); +} + +{ + local $params->{inbound_proxies} = '10.0.0.1,10.0.0.2'; + local $ENV{REMOTE_ADDR} = '10.0.0.1'; + local $ENV{HTTP_X_FORWARDED_FOR} = '10.42.42.42'; + + is(remote_ip(), '10.42.42.42', "from proxy 1"); +} + +{ + local $params->{inbound_proxies} = '10.0.0.1,10.0.0.2'; + local $ENV{REMOTE_ADDR} = '10.0.0.3'; + local $ENV{HTTP_X_FORWARDED_FOR} = '10.42.42.42'; + + is(remote_ip(), '10.0.0.3', "not a proxy"); +} + +{ + local $params->{inbound_proxies} = '*'; + local $ENV{REMOTE_ADDR} = '10.0.0.3'; + local $ENV{HTTP_X_FORWARDED_FOR} = '10.42.42.42,1.4.9.2'; + + is(remote_ip(), '10.42.42.42', "always proxy"); +} + +{ + local $params->{inbound_proxies} = ''; + local $ENV{REMOTE_ADDR} = '10.9.8.7'; + local $ENV{HTTP_X_FORWARDED_FOR} = '10.42.42.42,1.4.9.2'; + + is(remote_ip(), '10.9.8.7', "never proxy"); +} + + +{ + local $params->{inbound_proxies} = '10.0.0.1,2600:cafe::cafe:ffff:bf42:4998'; + local $ENV{REMOTE_ADDR} = '2600:cafe::cafe:ffff:bf42:4998'; + local $ENV{HTTP_X_FORWARDED_FOR} = '2600:cafe::cafe:ffff:bf42:BEEF'; + + is(remote_ip(), '2600:cafe::cafe:ffff:bf42:BEEF', "from proxy ipv6"); +} + +{ + local $params->{inbound_proxies} = '10.0.0.1,2600:cafe::cafe:ffff:bf42:4998'; + local $ENV{REMOTE_ADDR} = '2600:cafe::cafe:ffff:bf42:DEAD'; + local $ENV{HTTP_X_FORWARDED_FOR} = '2600:cafe::cafe:ffff:bf42:BEEF'; + + is(remote_ip(), '2600:cafe::cafe:ffff:bf42:DEAD', "invalid proxy ipv6"); +} + + +{ + local $params->{inbound_proxies} = '*'; + local $ENV{REMOTE_ADDR} = '2600:cafe::cafe:ffff:bf42:DEAD'; + local $ENV{HTTP_X_FORWARDED_FOR} = ''; + + is(remote_ip(), '2600:cafe::cafe:ffff:bf42:DEAD', "always proxy ipv6"); +} -- cgit v1.2.3-24-g4f1b