Skip to content

Commit 44ed719

Browse files
danxuliubackportbot[bot]
authored andcommitted
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 <danxuliu@gmail.com>
1 parent 424668d commit 44ed719

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

lib/private/Authentication/TwoFactorAuth/Manager.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,8 @@ public function clearTwoFactorPending(string $userId) {
385385
$tokensNeeding2FA = $this->config->getUserKeys($userId, 'login_token_2fa');
386386

387387
foreach ($tokensNeeding2FA as $tokenId) {
388+
$this->config->deleteUserValue($userId, 'login_token_2fa', $tokenId);
389+
388390
$this->tokenProvider->invalidateTokenById($userId, (int)$tokenId);
389391
}
390392
}

tests/lib/Authentication/TwoFactorAuth/ManagerTest.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -715,4 +715,30 @@ public function testNeedsSecondFactorAppPassword() {
715715

716716
$this->assertFalse($this->manager->needsSecondFactor($user));
717717
}
718+
719+
public function testClearTwoFactorPending() {
720+
$this->config->method('getUserKeys')
721+
->with('theUserId', 'login_token_2fa')
722+
->willReturn([
723+
'42', '43', '44'
724+
]);
725+
726+
$this->config->expects($this->exactly(3))
727+
->method('deleteUserValue')
728+
->withConsecutive(
729+
['theUserId', 'login_token_2fa', '42'],
730+
['theUserId', 'login_token_2fa', '43'],
731+
['theUserId', 'login_token_2fa', '44'],
732+
);
733+
734+
$this->tokenProvider->expects($this->exactly(3))
735+
->method('invalidateTokenById')
736+
->withConsecutive(
737+
['theUserId', 42],
738+
['theUserId', 43],
739+
['theUserId', 44],
740+
);
741+
742+
$this->manager->clearTwoFactorPending('theUserId');
743+
}
718744
}

0 commit comments

Comments
 (0)