aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorRichard Steinmetz <richard@steinmetz.cloud>2024-11-13 10:47:20 +0100
committerGitHub <noreply@github.com>2024-11-13 10:47:20 +0100
commit442d036ac9867b7de7d7ec2d441489d7df7920d6 (patch)
treeea1f04d1c7b737668de3988c28281946d4505038 /tests
parent56ce5d03bd181966a5987488c0f30bc59daf9de3 (diff)
parentfcefd37a5f7e24208a115214660d419cbdeae7f3 (diff)
downloadnextcloud-server-442d036ac9867b7de7d7ec2d441489d7df7920d6.tar.gz
nextcloud-server-442d036ac9867b7de7d7ec2d441489d7df7920d6.zip
Merge pull request #49098 from nextcloud/backport/48933/stable30
[stable30] Clear pending two factor tokens also from configuration
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/Authentication/TwoFactorAuth/ManagerTest.php58
1 files changed, 58 insertions, 0 deletions
diff --git a/tests/lib/Authentication/TwoFactorAuth/ManagerTest.php b/tests/lib/Authentication/TwoFactorAuth/ManagerTest.php
index a89b07f7716..a574299642a 100644
--- a/tests/lib/Authentication/TwoFactorAuth/ManagerTest.php
+++ b/tests/lib/Authentication/TwoFactorAuth/ManagerTest.php
@@ -15,6 +15,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;
@@ -701,4 +702,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');
+ }
}