Skip to content

Commit 40a4e6f

Browse files
Merge pull request #58013 from nextcloud/backport/58009/stable32
[stable32] fix(federation): Don't ask the database for an empty url
2 parents 1c0c124 + 61b6d3a commit 40a4e6f

File tree

2 files changed

+18
-19
lines changed

2 files changed

+18
-19
lines changed

apps/federation/lib/Controller/OCSAuthAPIController.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,10 @@ public function getSharedSecret(string $url, string $token): DataResponse {
163163
}
164164

165165
protected function isValidToken(string $url, string $token): bool {
166+
if ($url === '' || $token === '') {
167+
return false;
168+
}
166169
$storedToken = $this->dbHandler->getToken($url);
167-
return hash_equals($storedToken, $token);
170+
return $storedToken !== '' && hash_equals($storedToken, $token);
168171
}
169172
}

apps/federation/tests/Controller/OCSAuthAPIControllerTest.php

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -110,28 +110,24 @@ public function testGetSharedSecret(bool $isTrustedServer, bool $isValidToken, b
110110
$token = 'token';
111111

112112
/** @var OCSAuthAPIController&MockObject $ocsAuthApi */
113-
$ocsAuthApi = $this->getMockBuilder(OCSAuthAPIController::class)
114-
->setConstructorArgs(
115-
[
116-
'federation',
117-
$this->request,
118-
$this->secureRandom,
119-
$this->jobList,
120-
$this->trustedServers,
121-
$this->dbHandler,
122-
$this->logger,
123-
$this->timeFactory,
124-
$this->throttler
125-
]
126-
)
127-
->onlyMethods(['isValidToken'])
128-
->getMock();
113+
$ocsAuthApi = new OCSAuthAPIController(
114+
'federation',
115+
$this->request,
116+
$this->secureRandom,
117+
$this->jobList,
118+
$this->trustedServers,
119+
$this->dbHandler,
120+
$this->logger,
121+
$this->timeFactory,
122+
$this->throttler,
123+
);
129124

130125
$this->trustedServers
131126
->expects($this->any())
132127
->method('isTrustedServer')->with($url)->willReturn($isTrustedServer);
133-
$ocsAuthApi->expects($this->any())
134-
->method('isValidToken')->with($url, $token)->willReturn($isValidToken);
128+
$this->dbHandler->method('getToken')
129+
->with($url)
130+
->willReturn($isValidToken ? $token : 'not $token');
135131

136132
if ($ok) {
137133
$this->secureRandom->expects($this->once())->method('generate')->with(32)

0 commit comments

Comments
 (0)