From 55991f93c2fae9a31f0a43b4d6a078ffb9cef5e1 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 fdc475bd16558..db568717b39cd 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 { + 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; } /** @@ -643,7 +641,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 6c9f968888344cef11681a3b2ebf087f89680849 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 db568717b39cd..69847fb49fe9f 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 6490e50bb9ce4e3e5525b2fc1fbf30b4893d90d0 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 e042d9338712a..030f16f15c4ab 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('getSystemValueString') @@ -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,