Skip to content

Commit

Permalink
Merge pull request #43181 from nextcloud/backport/42930/stable28
Browse files Browse the repository at this point in the history
[stable28] Fix: config param 'overwritecondaddr' not working
  • Loading branch information
susnux committed Feb 3, 2024
2 parents e0f96bc + d7b8f58 commit 933ad5e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
8 changes: 3 additions & 5 deletions lib/private/AppFramework/Http/Request.php
Expand Up @@ -629,14 +629,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;
}

/**
Expand All @@ -646,7 +644,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');
}

Expand Down
7 changes: 4 additions & 3 deletions tests/lib/AppFramework/Http/RequestTest.php
Expand Up @@ -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')
Expand All @@ -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,
Expand Down

0 comments on commit 933ad5e

Please sign in to comment.