Skip to content

Commit c721b4e

Browse files
fixup! Run session token renewals in a database transaction
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
1 parent e512af9 commit c721b4e

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

lib/private/Authentication/Token/PublicKeyTokenProvider.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ public function getTokenById(int $tokenId): IToken {
167167
public function renewSessionToken(string $oldSessionId, string $sessionId): IToken {
168168
$this->cache->clear();
169169

170-
$this->atomic(function() use ($oldSessionId, $sessionId) {
170+
return $this->atomic(function() use ($oldSessionId, $sessionId) {
171171
$token = $this->getToken($oldSessionId);
172172

173173
if (!($token instanceof PublicKeyToken)) {
@@ -179,7 +179,6 @@ public function renewSessionToken(string $oldSessionId, string $sessionId): ITok
179179
$privateKey = $this->decrypt($token->getPrivateKey(), $oldSessionId);
180180
$password = $this->decryptPassword($token->getPassword(), $privateKey);
181181
}
182-
183182
$newToken = $this->generateToken(
184183
$sessionId,
185184
$token->getUID(),

tests/lib/Authentication/Token/PublicKeyTokenProviderTest.php

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
<?php
2+
3+
declare(strict_types=1);
4+
25
/**
36
* @copyright Copyright (c) 2018 Roeland Jago Douma <roeland@famdouma.nl>
47
*
@@ -34,6 +37,7 @@
3437
use OCP\AppFramework\Utility\ITimeFactory;
3538
use OCP\IConfig;
3639
use OCP\Security\ICrypto;
40+
use PHPUnit\Framework\MockObject\MockObject;
3741
use Psr\Log\LoggerInterface;
3842
use Test\TestCase;
3943

@@ -46,6 +50,8 @@ class PublicKeyTokenProviderTest extends TestCase {
4650
private $crypto;
4751
/** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */
4852
private $config;
53+
/** @var IDBConnection|IDBConnection|MockObject */
54+
private IDBConnection $db;
4955
/** @var LoggerInterface|\PHPUnit\Framework\MockObject\MockObject */
5056
private $logger;
5157
/** @var ITimeFactory|\PHPUnit\Framework\MockObject\MockObject */
@@ -66,14 +72,24 @@ protected function setUp(): void {
6672
['secret', '', '1f4h9s'],
6773
['openssl', [], []],
6874
]);
75+
$this->db = $this->createMock(IDBConnection::class);
76+
$this->db->method('atomic')->willReturnCallback(function($cb) {
77+
return $cb();
78+
});
6979
$this->logger = $this->createMock(LoggerInterface::class);
7080
$this->timeFactory = $this->createMock(ITimeFactory::class);
7181
$this->time = 1313131;
7282
$this->timeFactory->method('getTime')
7383
->willReturn($this->time);
7484

75-
$this->tokenProvider = new PublicKeyTokenProvider($this->mapper, $this->crypto, $this->config, $this->logger,
76-
$this->timeFactory);
85+
$this->tokenProvider = new PublicKeyTokenProvider(
86+
$this->mapper,
87+
$this->crypto,
88+
$this->config,
89+
$this->db,
90+
$this->logger,
91+
$this->timeFactory,
92+
);
7793
}
7894

7995
public function testGenerateToken() {

0 commit comments

Comments
 (0)