@@ -700,7 +700,8 @@ public function testGetIPAddressNormal()
700700 {
701701 $ expected = '123.123.123.123 ' ;
702702 $ _SERVER ['REMOTE_ADDR ' ] = $ expected ;
703- $ this ->request = new Request (new App ());
703+
704+ $ this ->request = new Request (new App ());
704705 $ this ->request ->populateHeaders ();
705706
706707 $ this ->assertSame ($ expected , $ this ->request ->getIPAddress ());
@@ -711,11 +712,12 @@ public function testGetIPAddressNormal()
711712 public function testGetIPAddressThruProxy ()
712713 {
713714 $ expected = '123.123.123.123 ' ;
715+ $ _SERVER ['HTTP_X_FORWARDED_FOR ' ] = $ expected ;
714716 $ _SERVER ['REMOTE_ADDR ' ] = '10.0.1.200 ' ;
715717 $ config = new App ();
716718 $ 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 );
719721 $ this ->request ->populateHeaders ();
720722
721723 // we should see the original forwarded address
@@ -724,40 +726,43 @@ public function testGetIPAddressThruProxy()
724726
725727 public function testGetIPAddressThruProxyInvalid ()
726728 {
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 ;
729732 $ config = new App ();
730733 $ 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 );
733736 $ this ->request ->populateHeaders ();
734737
735738 // spoofed address invalid
736- $ this ->assertSame (' 10.0.1.200 ' , $ this ->request ->getIPAddress ());
739+ $ this ->assertSame ($ expected , $ this ->request ->getIPAddress ());
737740 }
738741
739742 public function testGetIPAddressThruProxyNotWhitelisted ()
740743 {
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 ' ;
743747 $ config = new App ();
744748 $ 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 );
747751 $ this ->request ->populateHeaders ();
748752
749753 // spoofed address invalid
750- $ this ->assertSame (' 10.10.1.200 ' , $ this ->request ->getIPAddress ());
754+ $ this ->assertSame ($ expected , $ this ->request ->getIPAddress ());
751755 }
752756
753757 public function testGetIPAddressThruProxySubnet ()
754758 {
755759 $ expected = '123.123.123.123 ' ;
760+ $ _SERVER ['HTTP_X_FORWARDED_FOR ' ] = $ expected ;
756761 $ _SERVER ['REMOTE_ADDR ' ] = '192.168.5.21 ' ;
757762 $ config = new App ();
758763 $ 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 );
761766 $ this ->request ->populateHeaders ();
762767
763768 // we should see the original forwarded address
@@ -766,16 +771,16 @@ public function testGetIPAddressThruProxySubnet()
766771
767772 public function testGetIPAddressThruProxyOutofSubnet ()
768773 {
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 ;
771776 $ config = new App ();
772777 $ config ->proxyIPs = ['192.168.5.0/28 ' ];
773- $ _SERVER ['HTTP_X_FORWARDED_FOR ' ] = $ expected ;
778+ $ _SERVER ['HTTP_X_FORWARDED_FOR ' ] = ' 123.123.123.123 ' ;
774779 $ this ->request = new Request ($ config );
775780 $ this ->request ->populateHeaders ();
776781
777782 // we should see the original forwarded address
778- $ this ->assertSame (' 192.168.5.21 ' , $ this ->request ->getIPAddress ());
783+ $ this ->assertSame ($ expected , $ this ->request ->getIPAddress ());
779784 }
780785
781786 // @TODO getIPAddress should have more testing, to 100% code coverage
0 commit comments