mirror of
https://github.com/nextcloud/server.git
synced 2026-02-03 20:41:22 -05:00
fix(federation): Don't ask the database for an empty url
Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
parent
366864b08a
commit
c69bf87172
2 changed files with 18 additions and 18 deletions
|
|
@ -165,7 +165,10 @@ class OCSAuthAPIController extends OCSController {
|
|||
}
|
||||
|
||||
protected function isValidToken(string $url, string $token): bool {
|
||||
if ($url === '' || $token === '') {
|
||||
return false;
|
||||
}
|
||||
$storedToken = $this->dbHandler->getToken($url);
|
||||
return hash_equals($storedToken, $token);
|
||||
return $storedToken !== '' && hash_equals($storedToken, $token);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -126,27 +126,24 @@ class OCSAuthAPIControllerTest extends TestCase {
|
|||
$url = 'url';
|
||||
$token = 'token';
|
||||
|
||||
/** @var OCSAuthAPIController | \PHPUnit\Framework\MockObject\MockObject $ocsAuthApi */
|
||||
$ocsAuthApi = $this->getMockBuilder('OCA\Federation\Controller\OCSAuthAPIController')
|
||||
->setConstructorArgs(
|
||||
[
|
||||
'federation',
|
||||
$this->request,
|
||||
$this->secureRandom,
|
||||
$this->jobList,
|
||||
$this->trustedServers,
|
||||
$this->dbHandler,
|
||||
$this->logger,
|
||||
$this->timeFactory,
|
||||
$this->throttler
|
||||
]
|
||||
)->setMethods(['isValidToken'])->getMock();
|
||||
$ocsAuthApi = new OCSAuthAPIController(
|
||||
'federation',
|
||||
$this->request,
|
||||
$this->secureRandom,
|
||||
$this->jobList,
|
||||
$this->trustedServers,
|
||||
$this->dbHandler,
|
||||
$this->logger,
|
||||
$this->timeFactory,
|
||||
$this->throttler,
|
||||
);
|
||||
|
||||
$this->trustedServers
|
||||
->expects($this->any())
|
||||
->method('isTrustedServer')->with($url)->willReturn($isTrustedServer);
|
||||
$ocsAuthApi->expects($this->any())
|
||||
->method('isValidToken')->with($url, $token)->willReturn($isValidToken);
|
||||
$this->dbHandler->method('getToken')
|
||||
->with($url)
|
||||
->willReturn($isValidToken ? $token : 'not $token');
|
||||
|
||||
if ($ok) {
|
||||
$this->secureRandom->expects($this->once())->method('generate')->with(32)
|
||||
|
|
|
|||
Loading…
Reference in a new issue