Skip to content

Commit bdb105f

Browse files
committed
fix: Add token getType
Signed-off-by: Carl Schwan <carl@carlschwan.eu>
1 parent 4f1c694 commit bdb105f

3 files changed

Lines changed: 29 additions & 29 deletions

File tree

lib/private/Authentication/Token/PublicKeyToken.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,4 +234,9 @@ public function setPasswordInvalid(bool $invalid) {
234234
public function wipe(): void {
235235
parent::setType(IToken::WIPE_TOKEN);
236236
}
237+
238+
#[\Override]
239+
public function getType(): int {
240+
return $this->getter('type');
241+
}
237242
}

lib/public/Authentication/Token/IToken.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,4 +130,10 @@ public function setPassword(string $password): void;
130130
* @since 28.0.0
131131
*/
132132
public function setExpires(?int $expires): void;
133+
134+
/**
135+
* Get the type of the token
136+
* @since 32.0.0
137+
*/
138+
public function getType(): int;
133139
}

tests/lib/Authentication/Token/PublicKeyTokenProviderTest.php

Lines changed: 18 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?php
1+
et?php
22

33
declare(strict_types=1);
44

@@ -30,36 +30,25 @@
3030
use Test\TestCase;
3131

3232
class PublicKeyTokenProviderTest extends TestCase {
33-
/** @var PublicKeyTokenProvider|\PHPUnit\Framework\MockObject\MockObject */
34-
private $tokenProvider;
35-
/** @var PublicKeyTokenMapper|\PHPUnit\Framework\MockObject\MockObject */
36-
private $mapper;
37-
/** @var IHasher|\PHPUnit\Framework\MockObject\MockObject */
38-
private $hasher;
39-
/** @var ICrypto */
40-
private $crypto;
41-
/** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */
42-
private $config;
43-
/** @var IDBConnection|MockObject */
44-
private IDBConnection $db;
45-
/** @var LoggerInterface|\PHPUnit\Framework\MockObject\MockObject */
46-
private $logger;
47-
/** @var ITimeFactory|\PHPUnit\Framework\MockObject\MockObject */
48-
private $timeFactory;
49-
/** @var ICacheFactory|\PHPUnit\Framework\MockObject\MockObject */
50-
private $cacheFactory;
51-
/** @var int */
52-
private $time;
53-
/** @var IEventDispatcher */
54-
private $eventDispatcher;
33+
private PublicKeyTokenProvider $tokenProvider;
34+
35+
private PublicKeyTokenMapper&MockObject $mapper;
36+
private IConfig&MockObject $config;
37+
private IDBConnection&MockObject $db;
38+
private LoggerInterface&MockObject $logger;
39+
private ITimeFactory&MockObject $timeFactory;
40+
private ICacheFactory&MockObject $cacheFactory;
41+
42+
private int $time;
43+
private IHasher $hasher;
44+
private ICrypto $crypto;
45+
private IEventDispatcher $eventDispatcher;
5546

5647
#[\Override]
5748
protected function setUp(): void {
5849
parent::setUp();
5950

6051
$this->mapper = $this->createMock(PublicKeyTokenMapper::class);
61-
$this->hasher = Server::get(IHasher::class);
62-
$this->crypto = Server::get(ICrypto::class);
6352
$this->config = $this->createMock(IConfig::class);
6453
$this->config->method('getSystemValue')
6554
->willReturnMap([
@@ -76,6 +65,9 @@ protected function setUp(): void {
7665
$this->timeFactory->method('getTime')
7766
->willReturn($this->time);
7867
$this->cacheFactory = $this->createMock(ICacheFactory::class);
68+
69+
$this->hasher = Server::get(IHasher::class);
70+
$this->crypto = Server::get(ICrypto::class);
7971
$this->eventDispatcher = Server::get(IEventDispatcher::class);
8072

8173
$this->tokenProvider = new PublicKeyTokenProvider(
@@ -237,7 +229,6 @@ public function testGetPassword(): void {
237229
$this->assertSame($password, $this->tokenProvider->getPassword($actual, $token));
238230
}
239231

240-
241232
public function testGetPasswordPasswordLessToken(): void {
242233
$this->expectException(PasswordlessTokenException::class);
243234

@@ -248,7 +239,6 @@ public function testGetPasswordPasswordLessToken(): void {
248239
$this->tokenProvider->getPassword($tk, $token);
249240
}
250241

251-
252242
public function testGetPasswordInvalidToken(): void {
253243
$this->expectException(InvalidTokenException::class);
254244

@@ -293,13 +283,11 @@ public function testSetPassword(): void {
293283
return $newpass === $this->tokenProvider->getPassword($token, 'tokentokentokentokentoken');
294284
}));
295285

296-
297286
$this->tokenProvider->setPassword($actual, $token, $newpass);
298287

299288
$this->assertSame($newpass, $this->tokenProvider->getPassword($actual, 'tokentokentokentokentoken'));
300289
}
301290

302-
303291
public function testSetPasswordInvalidToken(): void {
304292
$this->expectException(InvalidTokenException::class);
305293

@@ -452,6 +440,7 @@ public function testRenewSessionTokenWithPassword(): void {
452440

453441
public function testGetToken(): void {
454442
$token = new PublicKeyToken();
443+
$token->setType(IToken::TEMPORARY_TOKEN);
455444

456445
$this->config->method('getSystemValue')
457446
->with('secret')

0 commit comments

Comments
 (0)