summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorBenjamin Gaussorgues <benjamin.gaussorgues@nextcloud.com>2024-04-17 10:06:14 +0200
committerGitHub <noreply@github.com>2024-04-17 10:06:14 +0200
commit2981694fc9f0dcc49b6309fc7e4ea5102c2bc085 (patch)
tree5d55381f5f64bc9d28803240811eacd0255412f3 /tests
parent2001e14157ca3904aa1814722188dc7a448c285b (diff)
parentdb00cd54bae6d045b0a6c58eb6698ccefb733957 (diff)
downloadnextcloud-server-2981694fc9f0dcc49b6309fc7e4ea5102c2bc085.tar.gz
nextcloud-server-2981694fc9f0dcc49b6309fc7e4ea5102c2bc085.zip
Merge pull request #44446 from nextcloud/backport/43057/stable28
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/Authentication/Token/PublicKeyTokenMapperTest.php17
-rw-r--r--tests/lib/Authentication/Token/PublicKeyTokenProviderTest.php13
2 files changed, 13 insertions, 17 deletions
diff --git a/tests/lib/Authentication/Token/PublicKeyTokenMapperTest.php b/tests/lib/Authentication/Token/PublicKeyTokenMapperTest.php
index 68962b26931..08ae62f3a05 100644
--- a/tests/lib/Authentication/Token/PublicKeyTokenMapperTest.php
+++ b/tests/lib/Authentication/Token/PublicKeyTokenMapperTest.php
@@ -26,9 +26,9 @@ declare(strict_types=1);
namespace Test\Authentication\Token;
use OC;
-use OC\Authentication\Token\IToken;
use OC\Authentication\Token\PublicKeyToken;
use OC\Authentication\Token\PublicKeyTokenMapper;
+use OCP\Authentication\Token\IToken;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IDBConnection;
use OCP\IUser;
@@ -249,7 +249,7 @@ class PublicKeyTokenMapperTest extends TestCase {
$this->assertCount(0, $this->mapper->getTokenByUser('user1000'));
}
- public function testDeleteById() {
+ public function testGetById() {
/** @var IUser|\PHPUnit\Framework\MockObject\MockObject $user */
$user = $this->createMock(IUser::class);
$qb = $this->dbConnection->getQueryBuilder();
@@ -259,17 +259,8 @@ class PublicKeyTokenMapperTest extends TestCase {
$result = $qb->execute();
$id = $result->fetch()['id'];
- $this->mapper->deleteById('user1', (int)$id);
- $this->assertEquals(4, $this->getNumberOfTokens());
- }
-
- public function testDeleteByIdWrongUser() {
- /** @var IUser|\PHPUnit\Framework\MockObject\MockObject $user */
- $user = $this->createMock(IUser::class);
- $id = 33;
-
- $this->mapper->deleteById('user1000', $id);
- $this->assertEquals(5, $this->getNumberOfTokens());
+ $token = $this->mapper->getTokenById((int)$id);
+ $this->assertEquals('user1', $token->getUID());
}
public function testDeleteByName() {
diff --git a/tests/lib/Authentication/Token/PublicKeyTokenProviderTest.php b/tests/lib/Authentication/Token/PublicKeyTokenProviderTest.php
index b3f5241877e..69894f14855 100644
--- a/tests/lib/Authentication/Token/PublicKeyTokenProviderTest.php
+++ b/tests/lib/Authentication/Token/PublicKeyTokenProviderTest.php
@@ -29,12 +29,13 @@ namespace Test\Authentication\Token;
use OC\Authentication\Exceptions\ExpiredTokenException;
use OC\Authentication\Exceptions\InvalidTokenException;
use OC\Authentication\Exceptions\PasswordlessTokenException;
-use OC\Authentication\Token\IToken;
use OC\Authentication\Token\PublicKeyToken;
use OC\Authentication\Token\PublicKeyTokenMapper;
use OC\Authentication\Token\PublicKeyTokenProvider;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Utility\ITimeFactory;
+use OCP\Authentication\Token\IToken;
+use OCP\ICacheFactory;
use OCP\IConfig;
use OCP\IDBConnection;
use OCP\Security\ICrypto;
@@ -60,6 +61,8 @@ class PublicKeyTokenProviderTest extends TestCase {
private $logger;
/** @var ITimeFactory|\PHPUnit\Framework\MockObject\MockObject */
private $timeFactory;
+ /** @var ICacheFactory|\PHPUnit\Framework\MockObject\MockObject */
+ private $cacheFactory;
/** @var int */
private $time;
@@ -90,6 +93,7 @@ class PublicKeyTokenProviderTest extends TestCase {
$this->time = 1313131;
$this->timeFactory->method('getTime')
->willReturn($this->time);
+ $this->cacheFactory = $this->createMock(ICacheFactory::class);
$this->tokenProvider = new PublicKeyTokenProvider(
$this->mapper,
@@ -99,6 +103,7 @@ class PublicKeyTokenProviderTest extends TestCase {
$this->logger,
$this->timeFactory,
$this->hasher,
+ $this->cacheFactory,
);
}
@@ -332,12 +337,12 @@ class PublicKeyTokenProviderTest extends TestCase {
$this->tokenProvider->invalidateToken('token7');
}
- public function testInvaildateTokenById() {
+ public function testInvalidateTokenById() {
$id = 123;
$this->mapper->expects($this->once())
- ->method('deleteById')
- ->with('uid', $id);
+ ->method('getTokenById')
+ ->with($id);
$this->tokenProvider->invalidateTokenById('uid', $id);
}