aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorDaniel Calviño Sánchez <danxuliu@gmail.com>2024-10-28 10:15:16 +0100
committerbackportbot[bot] <backportbot[bot]@users.noreply.github.com>2024-11-05 10:48:33 +0000
commitb39c5d8393fb155a490a2dba1709235dd828d377 (patch)
treeb05cb83dff0492365aa40847f3b6e91f0b81b22d /tests
parent56fc4341fb33984c797b16d1d937a57819731731 (diff)
downloadnextcloud-server-b39c5d8393fb155a490a2dba1709235dd828d377.tar.gz
nextcloud-server-b39c5d8393fb155a490a2dba1709235dd828d377.zip
fix: Handle exception when clearing previously removed two factor tokensbackport/48933/stable28
If a token was already removed from the database but not from the configuration clearing the tokens will try to remove it again from the database, which caused a DoesNotExistException to be thrown. Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/Authentication/TwoFactorAuth/ManagerTest.php32
1 files changed, 32 insertions, 0 deletions
diff --git a/tests/lib/Authentication/TwoFactorAuth/ManagerTest.php b/tests/lib/Authentication/TwoFactorAuth/ManagerTest.php
index c741ff068ac..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;
@@ -741,4 +742,35 @@ class ManagerTest extends TestCase {
$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');
+ }
}