@@ -750,22 +750,133 @@ public function testIsAJAX(): void
750750 $ this ->assertTrue ($ this ->request ->isAJAX ());
751751 }
752752
753- public function testIsSecure (): void
753+ #[DataProvider('provideIsSecure ' )]
754+ public function testIsSecure (array $ server , array $ proxyIPs , array $ headers , bool $ expected ): void
754755 {
755- service ('superglobals ' )->setServer ('HTTPS ' , 'on ' );
756- $ this ->assertTrue ($ this ->request ->isSecure ());
757- }
756+ $ superglobals = new Superglobals ();
758757
759- public function testIsSecureFrontEnd (): void
760- {
761- $ this ->request ->appendHeader ('Front-End-Https ' , 'on ' );
762- $ this ->assertTrue ($ this ->request ->isSecure ());
758+ foreach ($ server as $ key => $ value ) {
759+ $ superglobals ->setServer ($ key , $ value );
760+ }
761+ Services::injectMock ('superglobals ' , $ superglobals );
762+
763+ $ config = new App ();
764+ $ config ->proxyIPs = $ proxyIPs ;
765+ $ request = $ this ->createRequest ($ config );
766+
767+ foreach ($ headers as $ name => $ value ) {
768+ $ request ->appendHeader ($ name , $ value );
769+ }
770+
771+ $ this ->assertSame ($ expected , $ request ->isSecure ());
763772 }
764773
765- public function testIsSecureForwarded (): void
774+ public static function provideIsSecure (): iterable
766775 {
767- $ this ->request ->appendHeader ('X-Forwarded-Proto ' , 'https ' );
768- $ this ->assertTrue ($ this ->request ->isSecure ());
776+ yield from [
777+ 'HTTPS on ' => [
778+ 'server ' => ['HTTPS ' => 'on ' ],
779+ 'proxyIPs ' => [],
780+ 'headers ' => [],
781+ 'expected ' => true ,
782+ ],
783+ 'HTTPS ON case insensitive ' => [
784+ 'server ' => ['HTTPS ' => 'ON ' ],
785+ 'proxyIPs ' => [],
786+ 'headers ' => [],
787+ 'expected ' => true ,
788+ ],
789+ 'HTTPS 1 ' => [
790+ 'server ' => ['HTTPS ' => '1 ' ],
791+ 'proxyIPs ' => [],
792+ 'headers ' => [],
793+ 'expected ' => true ,
794+ ],
795+ 'HTTPS off ' => [
796+ 'server ' => ['HTTPS ' => 'off ' ],
797+ 'proxyIPs ' => [],
798+ 'headers ' => [],
799+ 'expected ' => false ,
800+ ],
801+ 'HTTPS not set ' => [
802+ 'server ' => [],
803+ 'proxyIPs ' => [],
804+ 'headers ' => [],
805+ 'expected ' => false ,
806+ ],
807+ 'Front-End-Https on with trusted proxy ' => [
808+ 'server ' => ['REMOTE_ADDR ' => '10.0.1.200 ' ],
809+ 'proxyIPs ' => ['10.0.1.200 ' => 'Front-End-Https ' ],
810+ 'headers ' => ['Front-End-Https ' => 'on ' ],
811+ 'expected ' => true ,
812+ ],
813+ 'Front-End-Https off with trusted proxy ' => [
814+ 'server ' => ['REMOTE_ADDR ' => '10.0.1.200 ' ],
815+ 'proxyIPs ' => ['10.0.1.200 ' => 'Front-End-Https ' ],
816+ 'headers ' => ['Front-End-Https ' => 'off ' ],
817+ 'expected ' => false ,
818+ ],
819+ 'Front-End-Https on with untrusted proxy ' => [
820+ 'server ' => ['REMOTE_ADDR ' => '10.0.1.201 ' ],
821+ 'proxyIPs ' => ['10.0.1.200 ' => 'Front-End-Https ' ],
822+ 'headers ' => ['Front-End-Https ' => 'on ' ],
823+ 'expected ' => false ,
824+ ],
825+ 'X-Forwarded-Proto https with trusted proxy ' => [
826+ 'server ' => ['REMOTE_ADDR ' => '10.0.1.200 ' ],
827+ 'proxyIPs ' => ['10.0.1.200 ' => 'X-Forwarded-Proto ' ],
828+ 'headers ' => ['X-Forwarded-Proto ' => 'https ' ],
829+ 'expected ' => true ,
830+ ],
831+ 'X-Forwarded-Proto http with trusted proxy ' => [
832+ 'server ' => ['REMOTE_ADDR ' => '10.0.1.200 ' ],
833+ 'proxyIPs ' => ['10.0.1.200 ' => 'X-Forwarded-Proto ' ],
834+ 'headers ' => ['X-Forwarded-Proto ' => 'http ' ],
835+ 'expected ' => false ,
836+ ],
837+ 'X-Forwarded-Proto https with untrusted proxy ' => [
838+ 'server ' => ['REMOTE_ADDR ' => '10.0.1.201 ' ],
839+ 'proxyIPs ' => ['10.0.1.200 ' => 'X-Forwarded-Proto ' ],
840+ 'headers ' => ['X-Forwarded-Proto ' => 'https ' ],
841+ 'expected ' => false ,
842+ ],
843+ 'Front-End-Https on with trusted proxy subnet IPv4 ' => [
844+ 'server ' => ['REMOTE_ADDR ' => '192.168.5.25 ' ],
845+ 'proxyIPs ' => ['192.168.5.0/24 ' => 'Front-End-Https ' ],
846+ 'headers ' => ['Front-End-Https ' => 'on ' ],
847+ 'expected ' => true ,
848+ ],
849+ 'Front-End-Https on with untrusted proxy subnet IPv4 ' => [
850+ 'server ' => ['REMOTE_ADDR ' => '192.168.6.25 ' ],
851+ 'proxyIPs ' => ['192.168.5.0/24 ' => 'Front-End-Https ' ],
852+ 'headers ' => ['Front-End-Https ' => 'on ' ],
853+ 'expected ' => false ,
854+ ],
855+ 'X-Forwarded-Proto https with trusted proxy subnet IPv6 ' => [
856+ 'server ' => ['REMOTE_ADDR ' => '2001:db8:1234::1 ' ],
857+ 'proxyIPs ' => ['2001:db8:1234::/48 ' => 'X-Forwarded-Proto ' ],
858+ 'headers ' => ['X-Forwarded-Proto ' => 'https ' ],
859+ 'expected ' => true ,
860+ ],
861+ 'X-Forwarded-Proto https with untrusted proxy subnet IPv6 ' => [
862+ 'server ' => ['REMOTE_ADDR ' => '2001:db8:1235::1 ' ],
863+ 'proxyIPs ' => ['2001:db8:1234::/48 ' => 'X-Forwarded-Proto ' ],
864+ 'headers ' => ['X-Forwarded-Proto ' => 'https ' ],
865+ 'expected ' => false ,
866+ ],
867+ 'IPv4 client IP against IPv6 proxy subnet ' => [
868+ 'server ' => ['REMOTE_ADDR ' => '192.168.5.25 ' ],
869+ 'proxyIPs ' => ['2001:db8:1234::/48 ' => 'X-Forwarded-Proto ' ],
870+ 'headers ' => ['X-Forwarded-Proto ' => 'https ' ],
871+ 'expected ' => false ,
872+ ],
873+ 'IPv6 client IP against IPv4 proxy subnet ' => [
874+ 'server ' => ['REMOTE_ADDR ' => '2001:db8:1234::1 ' ],
875+ 'proxyIPs ' => ['192.168.5.0/24 ' => 'X-Forwarded-Proto ' ],
876+ 'headers ' => ['X-Forwarded-Proto ' => 'https ' ],
877+ 'expected ' => false ,
878+ ],
879+ ];
769880 }
770881
771882 public function testUserAgent (): void
0 commit comments