From 21625f0d66bc3bfa1d5dc00c9ee9b4a571ed9701 Mon Sep 17 00:00:00 2001 From: Pavel Kryl Date: Thu, 13 Jan 2022 18:51:24 +0100 Subject: [PATCH 1/3] fixing bug #6914: Config Param 'overwritecondaddr' not working - just ignoring/removing extra parameter 'protocol' as suggested by blizzz Signed-off-by: Pavel Kryl --- lib/private/AppFramework/Http/Request.php | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/lib/private/AppFramework/Http/Request.php b/lib/private/AppFramework/Http/Request.php index b09737a6fc67b..cd1f51097492c 100644 --- a/lib/private/AppFramework/Http/Request.php +++ b/lib/private/AppFramework/Http/Request.php @@ -294,7 +294,7 @@ public function __unset($id) { * @return string */ public function getHeader(string $name): string { - $name = strtoupper(str_replace('-', '_', $name)); + $name = strtoupper(str_replace('-', '_',$name)); if (isset($this->server['HTTP_' . $name])) { return $this->server['HTTP_' . $name]; } @@ -622,14 +622,12 @@ public function getRemoteAddress(): string { /** * Check overwrite condition - * @param string $type * @return bool */ - private function isOverwriteCondition(string $type = ''): bool { + private function isOverwriteCondition(): bool { $regex = '/' . $this->config->getSystemValueString('overwritecondaddr', '') . '/'; $remoteAddr = isset($this->server['REMOTE_ADDR']) ? $this->server['REMOTE_ADDR'] : ''; - return $regex === '//' || preg_match($regex, $remoteAddr) === 1 - || $type !== 'protocol'; + return $regex === '//' || preg_match($regex, $remoteAddr) === 1; } /** @@ -639,7 +637,7 @@ private function isOverwriteCondition(string $type = ''): bool { */ public function getServerProtocol(): string { if ($this->config->getSystemValueString('overwriteprotocol') !== '' - && $this->isOverwriteCondition('protocol')) { + && $this->isOverwriteCondition()) { return $this->config->getSystemValueString('overwriteprotocol'); } From 8442ed014d10fa20f6cf7bc2070bd56fe1f2e60e Mon Sep 17 00:00:00 2001 From: Pavel Kryl Date: Thu, 13 Jan 2022 20:44:59 +0100 Subject: [PATCH 2/3] code style: ommited space, reverted [code review] --- lib/private/AppFramework/Http/Request.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/private/AppFramework/Http/Request.php b/lib/private/AppFramework/Http/Request.php index cd1f51097492c..07ca08391f4c9 100644 --- a/lib/private/AppFramework/Http/Request.php +++ b/lib/private/AppFramework/Http/Request.php @@ -294,7 +294,7 @@ public function __unset($id) { * @return string */ public function getHeader(string $name): string { - $name = strtoupper(str_replace('-', '_',$name)); + $name = strtoupper(str_replace('-', '_', $name)); if (isset($this->server['HTTP_' . $name])) { return $this->server['HTTP_' . $name]; } From d7b8f586d486860ccde9efc38ed81b7bec2ec4b4 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Fri, 26 Jan 2024 13:11:29 +0100 Subject: [PATCH 3/3] test(unit): fix RequestTest Signed-off-by: Arthur Schiwon --- tests/lib/AppFramework/Http/RequestTest.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/lib/AppFramework/Http/RequestTest.php b/tests/lib/AppFramework/Http/RequestTest.php index 4f53b3d8d5ca5..25b3a88f3007f 100644 --- a/tests/lib/AppFramework/Http/RequestTest.php +++ b/tests/lib/AppFramework/Http/RequestTest.php @@ -1822,14 +1822,14 @@ public function testGetRequestUriWithoutOverwrite() { public function providesGetRequestUriWithOverwriteData() { return [ ['/scriptname.php/some/PathInfo', '/owncloud/', ''], - ['/scriptname.php/some/PathInfo', '/owncloud/', '123'], + ['/scriptname.php/some/PathInfo', '/owncloud/', '123', '123.123.123.123'], ]; } /** * @dataProvider providesGetRequestUriWithOverwriteData */ - public function testGetRequestUriWithOverwrite($expectedUri, $overwriteWebRoot, $overwriteCondAddr) { + public function testGetRequestUriWithOverwrite($expectedUri, $overwriteWebRoot, $overwriteCondAddr, $remoteAddr = '') { $this->config ->expects($this->exactly(2)) ->method('getSystemValueString') @@ -1838,13 +1838,14 @@ public function testGetRequestUriWithOverwrite($expectedUri, $overwriteWebRoot, ['overwritecondaddr', '', $overwriteCondAddr], ]); - $request = $this->getMockBuilder('\OC\AppFramework\Http\Request') + $request = $this->getMockBuilder(Request::class) ->setMethods(['getScriptName']) ->setConstructorArgs([ [ 'server' => [ 'REQUEST_URI' => '/test.php/some/PathInfo', 'SCRIPT_NAME' => '/test.php', + 'REMOTE_ADDR' => $remoteAddr ] ], $this->requestId,