Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobin Appelman <robin@icewind.nl>2021-02-12 16:22:27 +0300
committerRobin Appelman <robin@icewind.nl>2021-02-12 16:22:27 +0300
commit01118a2218e76d5fb89eb5eaeb101ce43632996f (patch)
tree5d00cc4945689562623b3ac934a35acf68ffd22e /apps/settings/tests
parent361f160d0daa4c3baf84c801118c0d85886aa6d9 (diff)
use the configured forwarded headers for the setup check
instead of always checking against the same header Signed-off-by: Robin Appelman <robin@icewind.nl>
Diffstat (limited to 'apps/settings/tests')
-rw-r--r--apps/settings/tests/Controller/CheckSetupControllerTest.php70
1 files changed, 31 insertions, 39 deletions
diff --git a/apps/settings/tests/Controller/CheckSetupControllerTest.php b/apps/settings/tests/Controller/CheckSetupControllerTest.php
index 426793df606..2020d9f19f9 100644
--- a/apps/settings/tests/Controller/CheckSetupControllerTest.php
+++ b/apps/settings/tests/Controller/CheckSetupControllerTest.php
@@ -329,26 +329,37 @@ class CheckSetupControllerTest extends TestCase {
}
/**
- * @dataProvider dataForwardedForHeadersWorking
+ * @dataProvider dataForwardedForHeaders
*
- * @param array $trustedProxies
+ * @param string[] $trustedProxies
* @param string $remoteAddrNotForwarded
* @param string $remoteAddr
+ * @param string[] $forwardedForHeaders
+ * @param array $requestHeaders
* @param bool $result
*/
- public function testForwardedForHeadersWorking(array $trustedProxies, string $remoteAddrNotForwarded, string $remoteAddr, bool $result) {
- $this->config->expects($this->once())
- ->method('getSystemValue')
- ->with('trusted_proxies', [])
- ->willReturn($trustedProxies);
+ public function testForwardedForHeaders(array $trustedProxies, string $remoteAddrNotForwarded, string $remoteAddr, array $forwardedForHeaders, array $requestHeaders, bool $result) {
+ $this->config->method('getSystemValue')
+ ->willReturnCallback(function($key, $default) use ($forwardedForHeaders, $trustedProxies) {
+ switch ($key) {
+ case 'forwarded_for_headers':
+ return $forwardedForHeaders;
+ case 'trusted_proxies':
+ return $trustedProxies;
+ default:
+ return $default;
+ }
+ });
+ $headers = array_merge(
+ ['REMOTE_ADDR' => $remoteAddrNotForwarded],
+ $requestHeaders
+ );
$this->request->expects($this->atLeastOnce())
->method('getHeader')
- ->willReturnMap([
- ['REMOTE_ADDR', $remoteAddrNotForwarded],
- ['X-Forwarded-Host', '']
- ]);
- $this->request->expects($this->any())
- ->method('getRemoteAddress')
+ ->willReturnCallback(function($header) use ($headers) {
+ return isset($headers[$header]) ? $headers[$header] : '';
+ });
+ $this->request->method('getRemoteAddress')
->willReturn($remoteAddr);
$this->assertEquals(
@@ -357,37 +368,18 @@ class CheckSetupControllerTest extends TestCase {
);
}
- public function dataForwardedForHeadersWorking() {
+ public function dataForwardedForHeaders() {
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],
+ 'no trusted proxies' => [[], '2.2.2.2', '2.2.2.2', ['HTTP_X_FORWARDED_FOR'], [], true],
+ 'trusted proxy, remote addr not trusted proxy' => [['1.1.1.1'], '2.2.2.2', '2.2.2.2', ['HTTP_X_FORWARDED_FOR'], [], true],
+ 'trusted proxy, remote addr is trusted proxy, forwarded header working' => [['1.1.1.1'], '1.1.1.1', '2.2.2.2', ['HTTP_X_FORWARDED_FOR'], [], true],
+ 'trusted proxy, remote addr is trusted proxy, forwarded header not set' => [['1.1.1.1'], '1.1.1.1', '1.1.1.1', ['HTTP_X_FORWARDED_FOR'], [], false],
+ 'no trusted proxies, but header present' => [[], '2.2.2.2', '2.2.2.2', ['HTTP_X_FORWARDED_FOR'], ['HTTP_X_FORWARDED_FOR' => '1.1.1.1'], false],
+ 'no trusted proxies, different header present' => [[], '2.2.2.2', '2.2.2.2', ['HTTP_X_FORWARDED_FOR'], ['FORWARDED' => '1.1.1.1'], true],
];
}
- public function testForwardedHostPresentButTrustedProxiesEmpty() {
- $this->config->expects($this->once())
- ->method('getSystemValue')
- ->with('trusted_proxies', [])
- ->willReturn([]);
- $this->request->expects($this->atLeastOnce())
- ->method('getHeader')
- ->willReturnMap([
- ['REMOTE_ADDR', '1.1.1.1'],
- ['X-Forwarded-Host', 'nextcloud.test']
- ]);
- $this->request->expects($this->any())
- ->method('getRemoteAddress')
- ->willReturn('1.1.1.1');
-
- $this->assertEquals(
- false,
- self::invokePrivate($this->checkSetupController, 'forwardedForHeadersWorking')
- );
- }
-
public function testCheck() {
$this->config->expects($this->at(0))
->method('getAppValue')