@@ -701,6 +701,8 @@ public function testGetIPAddressNormal()
701
701
$ expected = '123.123.123.123 ' ;
702
702
$ _SERVER ['REMOTE_ADDR ' ] = $ expected ;
703
703
$ this ->request = new Request (new App ());
704
+ $ this ->request ->populateHeaders ();
705
+
704
706
$ this ->assertSame ($ expected , $ this ->request ->getIPAddress ());
705
707
// call a second time to exercise the initial conditional block in getIPAddress()
706
708
$ this ->assertSame ($ expected , $ this ->request ->getIPAddress ());
@@ -714,6 +716,7 @@ public function testGetIPAddressThruProxy()
714
716
$ config ->proxyIPs = '10.0.1.200,192.168.5.0/24 ' ;
715
717
$ _SERVER ['HTTP_X_FORWARDED_FOR ' ] = $ expected ;
716
718
$ this ->request = new Request ($ config );
719
+ $ this ->request ->populateHeaders ();
717
720
718
721
// we should see the original forwarded address
719
722
$ this ->assertSame ($ expected , $ this ->request ->getIPAddress ());
@@ -727,6 +730,7 @@ public function testGetIPAddressThruProxyInvalid()
727
730
$ config ->proxyIPs = '10.0.1.200,192.168.5.0/24 ' ;
728
731
$ _SERVER ['HTTP_X_FORWARDED_FOR ' ] = $ expected ;
729
732
$ this ->request = new Request ($ config );
733
+ $ this ->request ->populateHeaders ();
730
734
731
735
// spoofed address invalid
732
736
$ this ->assertSame ('10.0.1.200 ' , $ this ->request ->getIPAddress ());
@@ -740,6 +744,7 @@ public function testGetIPAddressThruProxyNotWhitelisted()
740
744
$ config ->proxyIPs = '10.0.1.200,192.168.5.0/24 ' ;
741
745
$ _SERVER ['HTTP_X_FORWARDED_FOR ' ] = $ expected ;
742
746
$ this ->request = new Request ($ config );
747
+ $ this ->request ->populateHeaders ();
743
748
744
749
// spoofed address invalid
745
750
$ this ->assertSame ('10.10.1.200 ' , $ this ->request ->getIPAddress ());
@@ -753,6 +758,7 @@ public function testGetIPAddressThruProxySubnet()
753
758
$ config ->proxyIPs = ['192.168.5.0/24 ' ];
754
759
$ _SERVER ['HTTP_X_FORWARDED_FOR ' ] = $ expected ;
755
760
$ this ->request = new Request ($ config );
761
+ $ this ->request ->populateHeaders ();
756
762
757
763
// we should see the original forwarded address
758
764
$ this ->assertSame ($ expected , $ this ->request ->getIPAddress ());
@@ -766,6 +772,7 @@ public function testGetIPAddressThruProxyOutofSubnet()
766
772
$ config ->proxyIPs = ['192.168.5.0/28 ' ];
767
773
$ _SERVER ['HTTP_X_FORWARDED_FOR ' ] = $ expected ;
768
774
$ this ->request = new Request ($ config );
775
+ $ this ->request ->populateHeaders ();
769
776
770
777
// we should see the original forwarded address
771
778
$ this ->assertSame ('192.168.5.21 ' , $ this ->request ->getIPAddress ());
0 commit comments