@@ -310,19 +310,21 @@ public function testIsPhpSupportedTrue() {
310310 * @dataProvider dataForwardedForHeadersWorking
311311 *
312312 * @param array $trustedProxies
313- * @param string $remoteAddrNoForwarded
313+ * @param string $remoteAddrNotForwarded
314314 * @param string $remoteAddr
315315 * @param bool $result
316316 */
317- public function testForwardedForHeadersWorking (array $ trustedProxies , string $ remoteAddrNoForwarded , string $ remoteAddr , bool $ result ) {
317+ public function testForwardedForHeadersWorking (array $ trustedProxies , string $ remoteAddrNotForwarded , string $ remoteAddr , bool $ result ) {
318318 $ this ->config ->expects ($ this ->once ())
319319 ->method ('getSystemValue ' )
320320 ->with ('trusted_proxies ' , [])
321321 ->willReturn ($ trustedProxies );
322- $ this ->request ->expects ($ this ->once ())
322+ $ this ->request ->expects ($ this ->atLeastOnce ())
323323 ->method ('getHeader ' )
324- ->with ('REMOTE_ADDR ' )
325- ->willReturn ($ remoteAddrNoForwarded );
324+ ->willReturnMap ([
325+ ['REMOTE_ADDR ' , $ remoteAddrNotForwarded ],
326+ ['X-Forwarded-Host ' , '' ]
327+ ]);
326328 $ this ->request ->expects ($ this ->any ())
327329 ->method ('getRemoteAddress ' )
328330 ->willReturn ($ remoteAddr );
@@ -343,6 +345,27 @@ public function dataForwardedForHeadersWorking() {
343345 ];
344346 }
345347
348+ public function testForwardedHostPresentButTrustedProxiesEmpty () {
349+ $ this ->config ->expects ($ this ->once ())
350+ ->method ('getSystemValue ' )
351+ ->with ('trusted_proxies ' , [])
352+ ->willReturn ([]);
353+ $ this ->request ->expects ($ this ->atLeastOnce ())
354+ ->method ('getHeader ' )
355+ ->willReturnMap ([
356+ ['REMOTE_ADDR ' , '1.1.1.1 ' ],
357+ ['X-Forwarded-Host ' , 'nextcloud.test ' ]
358+ ]);
359+ $ this ->request ->expects ($ this ->any ())
360+ ->method ('getRemoteAddress ' )
361+ ->willReturn ('1.1.1.1 ' );
362+
363+ $ this ->assertEquals (
364+ false ,
365+ self ::invokePrivate ($ this ->checkSetupController , 'forwardedForHeadersWorking ' )
366+ );
367+ }
368+
346369 public function testCheck () {
347370 $ this ->config ->expects ($ this ->at (0 ))
348371 ->method ('getAppValue ' )
@@ -365,10 +388,12 @@ public function testCheck() {
365388 ->with ('appstoreenabled ' , true )
366389 ->will ($ this ->returnValue (false ));
367390
368- $ this ->request ->expects ($ this ->once ())
391+ $ this ->request ->expects ($ this ->atLeastOnce ())
369392 ->method ('getHeader ' )
370- ->with ('REMOTE_ADDR ' )
371- ->willReturn ('4.3.2.1 ' );
393+ ->willReturnMap ([
394+ ['REMOTE_ADDR ' , '4.3.2.1 ' ],
395+ ['X-Forwarded-Host ' , '' ]
396+ ]);
372397
373398 $ client = $ this ->getMockBuilder ('\OCP\Http\Client\IClient ' )
374399 ->disableOriginalConstructor ()->getMock ();
0 commit comments