From 5d4173d6127293133bfc19ee6d15c07d333efe0c 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 | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/private/AppFramework/Http/Request.php b/lib/private/AppFramework/Http/Request.php index a503978819701..76e1d89c1a975 100644 --- a/lib/private/AppFramework/Http/Request.php +++ b/lib/private/AppFramework/Http/Request.php @@ -298,7 +298,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]; } @@ -626,14 +626,12 @@ public function getRemoteAddress(): string { /** * Check overwrite condition - * @param string $type * @return bool */ private function isOverwriteCondition(string $type = ''): bool { $regex = '/' . $this->config->getSystemValue('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; } /** From 80b4e95212d717f7070352ec1c13ae0e4d47604e 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 76e1d89c1a975..66a4f57b7d265 100644 --- a/lib/private/AppFramework/Http/Request.php +++ b/lib/private/AppFramework/Http/Request.php @@ -298,7 +298,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 e3453792cd21c4b72627c307c53cbef65ffcdec3 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 [skip ci] --- 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 cc44e2a07bcdf..aae5df736f521 100644 --- a/tests/lib/AppFramework/Http/RequestTest.php +++ b/tests/lib/AppFramework/Http/RequestTest.php @@ -1765,14 +1765,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('getSystemValue') @@ -1781,13 +1781,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,