summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMorris Jobke <hey@morrisjobke.de>2018-10-29 23:38:37 +0100
committerGitHub <noreply@github.com>2018-10-29 23:38:37 +0100
commit0999f079641cf25cac7aafdc1a0f604f78f3115c (patch)
tree3492808653060185c8f0e01f160c66811f37f97e /tests
parent2d5047849238c4130ca8ec78e29c9e9edcb359e2 (diff)
parent5cf8f4a407787151a8aa47c35e9aa2aa5a3d443c (diff)
downloadnextcloud-server-0999f079641cf25cac7aafdc1a0f604f78f3115c.tar.gz
nextcloud-server-0999f079641cf25cac7aafdc1a0f604f78f3115c.zip
Merge pull request #12052 from nextcloud/bugfix/11594/fix-setup-check-trusted-proxies
Fix setup check trusted proxies
Diffstat (limited to 'tests')
-rw-r--r--tests/Settings/Controller/CheckSetupControllerTest.php52
1 files changed, 28 insertions, 24 deletions
diff --git a/tests/Settings/Controller/CheckSetupControllerTest.php b/tests/Settings/Controller/CheckSetupControllerTest.php
index 6706573a1ad..34c7d19bd8d 100644
--- a/tests/Settings/Controller/CheckSetupControllerTest.php
+++ b/tests/Settings/Controller/CheckSetupControllerTest.php
@@ -295,38 +295,41 @@ class CheckSetupControllerTest extends TestCase {
);
}
- public function testForwardedForHeadersWorkingFalse() {
+ /**
+ * @dataProvider dataForwardedForHeadersWorking
+ *
+ * @param array $trustedProxies
+ * @param string $remoteAddrNoForwarded
+ * @param string $remoteAddr
+ * @param bool $result
+ */
+ public function testForwardedForHeadersWorking(array $trustedProxies, string $remoteAddrNoForwarded, string $remoteAddr, bool $result) {
$this->config->expects($this->once())
->method('getSystemValue')
->with('trusted_proxies', [])
- ->willReturn(['1.2.3.4']);
+ ->willReturn($trustedProxies);
$this->request->expects($this->once())
+ ->method('getHeader')
+ ->with('REMOTE_ADDR')
+ ->willReturn($remoteAddrNoForwarded);
+ $this->request->expects($this->any())
->method('getRemoteAddress')
- ->willReturn('1.2.3.4');
+ ->willReturn($remoteAddr);
- $this->assertFalse(
- self::invokePrivate(
- $this->checkSetupController,
- 'forwardedForHeadersWorking'
- )
+ $this->assertEquals(
+ $result,
+ self::invokePrivate($this->checkSetupController, 'forwardedForHeadersWorking')
);
}
- public function testForwardedForHeadersWorkingTrue() {
- $this->config->expects($this->once())
- ->method('getSystemValue')
- ->with('trusted_proxies', [])
- ->willReturn(['1.2.3.4']);
- $this->request->expects($this->once())
- ->method('getRemoteAddress')
- ->willReturn('4.3.2.1');
-
- $this->assertTrue(
- self::invokePrivate(
- $this->checkSetupController,
- 'forwardedForHeadersWorking'
- )
- );
+ public function dataForwardedForHeadersWorking() {
+ return [
+ // description => trusted proxies, getHeader('REMOTE_ADDR'), getRemoteAddr, expected result
+ 'no trusted proxies' => [[], '2.2.2.2', '2.2.2.2', true],
+ 'trusted proxy, remote addr not trusted proxy' => [['1.1.1.1'], '2.2.2.2', '2.2.2.2', true],
+ 'trusted proxy, remote addr is trusted proxy, x-forwarded-for working' => [['1.1.1.1'], '1.1.1.1', '2.2.2.2', true],
+ 'trusted proxy, remote addr is trusted proxy, x-forwarded-for not set' => [['1.1.1.1'], '1.1.1.1', '1.1.1.1', false],
+ ];
}
public function testCheck() {
@@ -348,7 +351,8 @@ class CheckSetupControllerTest extends TestCase {
->will($this->returnValue(false));
$this->request->expects($this->once())
- ->method('getRemoteAddress')
+ ->method('getHeader')
+ ->with('REMOTE_ADDR')
->willReturn('4.3.2.1');
$client = $this->getMockBuilder('\OCP\Http\Client\IClient')