mirror of
https://github.com/nextcloud/server.git
synced 2026-06-18 21:21:48 -04:00
chore(tests): Avoid deprecation in PublicKeyTokenProvider
Also cleaned up the test a bit. Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com> Signed-off-by: Benjamin Gaussorgues <benjamin.gaussorgues@nextcloud.com>
This commit is contained in:
parent
73506e8486
commit
b4f86c032c
2 changed files with 25 additions and 31 deletions
|
|
@ -531,16 +531,18 @@ class PublicKeyTokenProvider implements IProvider {
|
|||
$hashNeedsUpdate = [];
|
||||
|
||||
foreach ($tokens as $t) {
|
||||
if (!isset($hashNeedsUpdate[$t->getPasswordHash()])) {
|
||||
if ($t->getPasswordHash() === null) {
|
||||
$hashNeedsUpdate[$t->getPasswordHash() ?: ''] = true;
|
||||
} elseif (!$this->hasher->verify(sha1($password) . $password, $t->getPasswordHash())) {
|
||||
$hashNeedsUpdate[$t->getPasswordHash() ?: ''] = true;
|
||||
$passwordHash = $t->getPasswordHash();
|
||||
if ($passwordHash === null) {
|
||||
$hashNeedsUpdate[''] = true;
|
||||
$needsUpdating = true;
|
||||
} elseif (!isset($hashNeedsUpdate[$passwordHash])) {
|
||||
if (!$this->hasher->verify(sha1($password) . $password, $passwordHash)) {
|
||||
$hashNeedsUpdate[$passwordHash] = true;
|
||||
} else {
|
||||
$hashNeedsUpdate[$t->getPasswordHash() ?: ''] = false;
|
||||
$hashNeedsUpdate[$passwordHash] = false;
|
||||
}
|
||||
$needsUpdating = $hashNeedsUpdate[$passwordHash] ?? true;
|
||||
}
|
||||
$needsUpdating = $hashNeedsUpdate[$t->getPasswordHash() ?: ''] ?? true;
|
||||
|
||||
if ($needsUpdating) {
|
||||
if ($newPasswordHash === null) {
|
||||
|
|
|
|||
|
|
@ -30,36 +30,25 @@ use Psr\Log\LoggerInterface;
|
|||
use Test\TestCase;
|
||||
|
||||
class PublicKeyTokenProviderTest extends TestCase {
|
||||
/** @var PublicKeyTokenProvider|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $tokenProvider;
|
||||
/** @var PublicKeyTokenMapper|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $mapper;
|
||||
/** @var IHasher|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $hasher;
|
||||
/** @var ICrypto */
|
||||
private $crypto;
|
||||
/** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $config;
|
||||
/** @var IDBConnection|MockObject */
|
||||
private IDBConnection $db;
|
||||
/** @var LoggerInterface|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $logger;
|
||||
/** @var ITimeFactory|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $timeFactory;
|
||||
/** @var ICacheFactory|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $cacheFactory;
|
||||
/** @var int */
|
||||
private $time;
|
||||
/** @var IEventDispatcher */
|
||||
private $eventDispatcher;
|
||||
private PublicKeyTokenProvider $tokenProvider;
|
||||
|
||||
private PublicKeyTokenMapper&MockObject $mapper;
|
||||
private IConfig&MockObject $config;
|
||||
private IDBConnection&MockObject $db;
|
||||
private LoggerInterface&MockObject $logger;
|
||||
private ITimeFactory&MockObject $timeFactory;
|
||||
private ICacheFactory&MockObject $cacheFactory;
|
||||
|
||||
private int $time;
|
||||
private IHasher $hasher;
|
||||
private ICrypto $crypto;
|
||||
private IEventDispatcher $eventDispatcher;
|
||||
|
||||
#[\Override]
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
|
||||
$this->mapper = $this->createMock(PublicKeyTokenMapper::class);
|
||||
$this->hasher = Server::get(IHasher::class);
|
||||
$this->crypto = Server::get(ICrypto::class);
|
||||
$this->config = $this->createMock(IConfig::class);
|
||||
$this->config->method('getSystemValue')
|
||||
->willReturnMap([
|
||||
|
|
@ -76,6 +65,9 @@ class PublicKeyTokenProviderTest extends TestCase {
|
|||
$this->timeFactory->method('getTime')
|
||||
->willReturn($this->time);
|
||||
$this->cacheFactory = $this->createMock(ICacheFactory::class);
|
||||
|
||||
$this->hasher = Server::get(IHasher::class);
|
||||
$this->crypto = Server::get(ICrypto::class);
|
||||
$this->eventDispatcher = Server::get(IEventDispatcher::class);
|
||||
|
||||
$this->tokenProvider = new PublicKeyTokenProvider(
|
||||
|
|
|
|||
Loading…
Reference in a new issue