@@ -585,6 +585,83 @@ public function testGetRemoteAddressWithNotMatchingCidrTrustedRemote() {
585585 $ this ->assertSame ('192.168.3.99 ' , $ request ->getRemoteAddress ());
586586 }
587587
588+ public function testGetRemoteIpv6AddressWithMatchingIpv6CidrTrustedRemote () {
589+ $ this ->config
590+ ->expects ($ this ->exactly (2 ))
591+ ->method ('getSystemValue ' )
592+ ->withConsecutive (
593+ ['trusted_proxies ' ],
594+ ['forwarded_for_headers ' ]
595+ )->willReturnOnConsecutiveCalls (
596+ ['2001:db8:85a3:8d3:1319:8a20::/95 ' ],
597+ ['HTTP_X_FORWARDED_FOR ' ]
598+ );
599+
600+ $ request = new Request (
601+ [
602+ 'server ' => [
603+ 'REMOTE_ADDR ' => '2001:db8:85a3:8d3:1319:8a21:370:7348 ' ,
604+ 'HTTP_X_FORWARDED ' => '10.4.0.5, 10.4.0.4 ' ,
605+ 'HTTP_X_FORWARDED_FOR ' => '192.168.0.233 '
606+ ],
607+ ],
608+ $ this ->requestId ,
609+ $ this ->config ,
610+ $ this ->csrfTokenManager ,
611+ $ this ->stream
612+ );
613+
614+ $ this ->assertSame ('192.168.0.233 ' , $ request ->getRemoteAddress ());
615+ }
616+
617+ public function testGetRemoteAddressIpv6WithNotMatchingCidrTrustedRemote () {
618+ $ this ->config
619+ ->expects ($ this ->once ())
620+ ->method ('getSystemValue ' )
621+ ->with ('trusted_proxies ' )
622+ ->willReturn (['fd::/8 ' ]);
623+
624+ $ request = new Request (
625+ [
626+ 'server ' => [
627+ 'REMOTE_ADDR ' => '2001:db8:85a3:8d3:1319:8a2e:370:7348 ' ,
628+ 'HTTP_X_FORWARDED ' => '10.4.0.5, 10.4.0.4 ' ,
629+ 'HTTP_X_FORWARDED_FOR ' => '192.168.0.233 '
630+ ],
631+ ],
632+ $ this ->requestId ,
633+ $ this ->config ,
634+ $ this ->csrfTokenManager ,
635+ $ this ->stream
636+ );
637+
638+ $ this ->assertSame ('2001:db8:85a3:8d3:1319:8a2e:370:7348 ' , $ request ->getRemoteAddress ());
639+ }
640+
641+ public function testGetRemoteAddressIpv6WithInvalidTrustedProxy () {
642+ $ this ->config
643+ ->expects ($ this ->once ())
644+ ->method ('getSystemValue ' )
645+ ->with ('trusted_proxies ' )
646+ ->willReturn (['fx::/8 ' ]);
647+
648+ $ request = new Request (
649+ [
650+ 'server ' => [
651+ 'REMOTE_ADDR ' => '2001:db8:85a3:8d3:1319:8a2e:370:7348 ' ,
652+ 'HTTP_X_FORWARDED ' => '10.4.0.5, 10.4.0.4 ' ,
653+ 'HTTP_X_FORWARDED_FOR ' => '192.168.0.233 '
654+ ],
655+ ],
656+ $ this ->requestId ,
657+ $ this ->config ,
658+ $ this ->csrfTokenManager ,
659+ $ this ->stream
660+ );
661+
662+ $ this ->assertSame ('2001:db8:85a3:8d3:1319:8a2e:370:7348 ' , $ request ->getRemoteAddress ());
663+ }
664+
588665 public function testGetRemoteAddressWithXForwardedForIPv6 () {
589666 $ this ->config
590667 ->expects ($ this ->exactly (2 ))
0 commit comments