diff options
author | Richard Steinmetz <richard@steinmetz.cloud> | 2024-11-13 10:46:59 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-11-13 10:46:59 +0100 |
commit | 1b0926ee7696d420ed81a62d43dd8b26f4e5092e (patch) | |
tree | bde9abb2454f0e35f396ff7dce8ab58acdb34f62 /tests | |
parent | 79006830a1360949f29abdb41aa8ad64ef38d9e3 (diff) | |
parent | b39c5d8393fb155a490a2dba1709235dd828d377 (diff) | |
download | nextcloud-server-1b0926ee7696d420ed81a62d43dd8b26f4e5092e.tar.gz nextcloud-server-1b0926ee7696d420ed81a62d43dd8b26f4e5092e.zip |
Merge pull request #49096 from nextcloud/backport/48933/stable28
[stable28] Clear pending two factor tokens also from configuration
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lib/Authentication/TwoFactorAuth/ManagerTest.php | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/tests/lib/Authentication/TwoFactorAuth/ManagerTest.php b/tests/lib/Authentication/TwoFactorAuth/ManagerTest.php index a2655f58649..23ae5d93fdd 100644 --- a/tests/lib/Authentication/TwoFactorAuth/ManagerTest.php +++ b/tests/lib/Authentication/TwoFactorAuth/ManagerTest.php @@ -29,6 +29,7 @@ use OC\Authentication\TwoFactorAuth\MandatoryTwoFactor; use OC\Authentication\TwoFactorAuth\ProviderLoader; use OCP\Activity\IEvent; use OCP\Activity\IManager; +use OCP\AppFramework\Db\DoesNotExistException; use OCP\AppFramework\Utility\ITimeFactory; use OCP\Authentication\TwoFactorAuth\IActivatableAtLogin; use OCP\Authentication\TwoFactorAuth\IProvider; @@ -715,4 +716,61 @@ class ManagerTest extends TestCase { $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'); + } + + public function testClearTwoFactorPendingTokenDoesNotExist() { + $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], + ) + ->willReturnCallback(function ($user, $tokenId) { + if ($tokenId === 43) { + throw new DoesNotExistException('token does not exist'); + } + }); + + $this->manager->clearTwoFactorPending('theUserId'); + } } |