@@ -700,7 +700,8 @@ public function testGetIPAddressNormal()
700
700
{
701
701
$ expected = '123.123.123.123 ' ;
702
702
$ _SERVER ['REMOTE_ADDR ' ] = $ expected ;
703
- $ this ->request = new Request (new App ());
703
+
704
+ $ this ->request = new Request (new App ());
704
705
$ this ->request ->populateHeaders ();
705
706
706
707
$ this ->assertSame ($ expected , $ this ->request ->getIPAddress ());
@@ -711,11 +712,12 @@ public function testGetIPAddressNormal()
711
712
public function testGetIPAddressThruProxy ()
712
713
{
713
714
$ expected = '123.123.123.123 ' ;
715
+ $ _SERVER ['HTTP_X_FORWARDED_FOR ' ] = $ expected ;
714
716
$ _SERVER ['REMOTE_ADDR ' ] = '10.0.1.200 ' ;
715
717
$ config = new App ();
716
718
$ config ->proxyIPs = '10.0.1.200,192.168.5.0/24 ' ;
717
- $ _SERVER [ ' HTTP_X_FORWARDED_FOR ' ] = $ expected ;
718
- $ this ->request = new Request ($ config );
719
+
720
+ $ this ->request = new Request ($ config );
719
721
$ this ->request ->populateHeaders ();
720
722
721
723
// we should see the original forwarded address
@@ -724,40 +726,43 @@ public function testGetIPAddressThruProxy()
724
726
725
727
public function testGetIPAddressThruProxyInvalid ()
726
728
{
727
- $ expected = '123.456.23.123 ' ;
728
- $ _SERVER ['REMOTE_ADDR ' ] = '10.0.1.200 ' ;
729
+ $ _SERVER ['HTTP_X_FORWARDED_FOR ' ] = '123.456.23.123 ' ;
730
+ $ expected = '10.0.1.200 ' ;
731
+ $ _SERVER ['REMOTE_ADDR ' ] = $ expected ;
729
732
$ config = new App ();
730
733
$ config ->proxyIPs = '10.0.1.200,192.168.5.0/24 ' ;
731
- $ _SERVER [ ' HTTP_X_FORWARDED_FOR ' ] = $ expected ;
732
- $ this ->request = new Request ($ config );
734
+
735
+ $ this ->request = new Request ($ config );
733
736
$ this ->request ->populateHeaders ();
734
737
735
738
// spoofed address invalid
736
- $ this ->assertSame (' 10.0.1.200 ' , $ this ->request ->getIPAddress ());
739
+ $ this ->assertSame ($ expected , $ this ->request ->getIPAddress ());
737
740
}
738
741
739
742
public function testGetIPAddressThruProxyNotWhitelisted ()
740
743
{
741
- $ expected = '123.456.23.123 ' ;
742
- $ _SERVER ['REMOTE_ADDR ' ] = '10.10.1.200 ' ;
744
+ $ expected = '10.10.1.200 ' ;
745
+ $ _SERVER ['REMOTE_ADDR ' ] = $ expected ;
746
+ $ _SERVER ['HTTP_X_FORWARDED_FOR ' ] = '123.456.23.123 ' ;
743
747
$ config = new App ();
744
748
$ config ->proxyIPs = '10.0.1.200,192.168.5.0/24 ' ;
745
- $ _SERVER [ ' HTTP_X_FORWARDED_FOR ' ] = $ expected ;
746
- $ this ->request = new Request ($ config );
749
+
750
+ $ this ->request = new Request ($ config );
747
751
$ this ->request ->populateHeaders ();
748
752
749
753
// spoofed address invalid
750
- $ this ->assertSame (' 10.10.1.200 ' , $ this ->request ->getIPAddress ());
754
+ $ this ->assertSame ($ expected , $ this ->request ->getIPAddress ());
751
755
}
752
756
753
757
public function testGetIPAddressThruProxySubnet ()
754
758
{
755
759
$ expected = '123.123.123.123 ' ;
760
+ $ _SERVER ['HTTP_X_FORWARDED_FOR ' ] = $ expected ;
756
761
$ _SERVER ['REMOTE_ADDR ' ] = '192.168.5.21 ' ;
757
762
$ config = new App ();
758
763
$ config ->proxyIPs = ['192.168.5.0/24 ' ];
759
- $ _SERVER [ ' HTTP_X_FORWARDED_FOR ' ] = $ expected ;
760
- $ this ->request = new Request ($ config );
764
+
765
+ $ this ->request = new Request ($ config );
761
766
$ this ->request ->populateHeaders ();
762
767
763
768
// we should see the original forwarded address
@@ -766,16 +771,16 @@ public function testGetIPAddressThruProxySubnet()
766
771
767
772
public function testGetIPAddressThruProxyOutofSubnet ()
768
773
{
769
- $ expected = '123.123.123.123 ' ;
770
- $ _SERVER ['REMOTE_ADDR ' ] = ' 192.168.5.21 ' ;
774
+ $ expected = '192.168.5.21 ' ;
775
+ $ _SERVER ['REMOTE_ADDR ' ] = $ expected ;
771
776
$ config = new App ();
772
777
$ config ->proxyIPs = ['192.168.5.0/28 ' ];
773
- $ _SERVER ['HTTP_X_FORWARDED_FOR ' ] = $ expected ;
778
+ $ _SERVER ['HTTP_X_FORWARDED_FOR ' ] = ' 123.123.123.123 ' ;
774
779
$ this ->request = new Request ($ config );
775
780
$ this ->request ->populateHeaders ();
776
781
777
782
// we should see the original forwarded address
778
- $ this ->assertSame (' 192.168.5.21 ' , $ this ->request ->getIPAddress ());
783
+ $ this ->assertSame ($ expected , $ this ->request ->getIPAddress ());
779
784
}
780
785
781
786
// @TODO getIPAddress should have more testing, to 100% code coverage
0 commit comments