Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix: Clear pending two factor tokens also from configuration
Otherwise as the tokens were removed from the database but not from the
configuration the next time that the tokens were cleared the previous
tokens were still got from the configuration, and trying to remove them
again from the database ended in a DoesNotExistException being thrown.

Signed-off-by: Daniel Calviño Sánchez <[email protected]>
  • Loading branch information
danxuliu authored and backportbot[bot] committed Nov 5, 2024
commit 56fc4341fb33984c797b16d1d937a57819731731
2 changes: 2 additions & 0 deletions lib/private/Authentication/TwoFactorAuth/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,8 @@ public function clearTwoFactorPending(string $userId) {
$tokensNeeding2FA = $this->config->getUserKeys($userId, 'login_token_2fa');

foreach ($tokensNeeding2FA as $tokenId) {
$this->config->deleteUserValue($userId, 'login_token_2fa', $tokenId);

$this->tokenProvider->invalidateTokenById($userId, (int)$tokenId);
}
}
Expand Down
26 changes: 26 additions & 0 deletions tests/lib/Authentication/TwoFactorAuth/ManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -715,4 +715,30 @@ public function testNeedsSecondFactorAppPassword() {

$this->assertFalse($this->manager->needsSecondFactor($user));
}

public function testClearTwoFactorPending() {
$this->config->method('getUserKeys')
->with('theUserId', 'login_token_2fa')
->willReturn([
'42', '43', '44'
]);

$this->config->expects($this->exactly(3))
->method('deleteUserValue')
->withConsecutive(
['theUserId', 'login_token_2fa', '42'],
['theUserId', 'login_token_2fa', '43'],
['theUserId', 'login_token_2fa', '44'],
);

$this->tokenProvider->expects($this->exactly(3))
->method('invalidateTokenById')
->withConsecutive(
['theUserId', 42],
['theUserId', 43],
['theUserId', 44],
);

$this->manager->clearTwoFactorPending('theUserId');
}
}