]> source.dussan.org Git - nextcloud-server.git/commitdiff
fix: Clear pending two factor tokens also from configuration
authorDaniel Calviño Sánchez <danxuliu@gmail.com>
Mon, 28 Oct 2024 09:14:29 +0000 (10:14 +0100)
committerbackportbot[bot] <backportbot[bot]@users.noreply.github.com>
Tue, 5 Nov 2024 10:49:31 +0000 (10:49 +0000)
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>
lib/private/Authentication/TwoFactorAuth/Manager.php
tests/lib/Authentication/TwoFactorAuth/ManagerTest.php

index 3722b4506812cf39cc7604b43cdf303cf22781c9..209b32d46a328beddfe624d8820c080d0b3ec93a 100644 (file)
@@ -385,6 +385,8 @@ class Manager {
                $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);
                }
        }
index a2655f58649e550a088db4ee11dcce18342ad509..c741ff068ac59bfb46c29aa9117f4743da9be7ca 100644 (file)
@@ -715,4 +715,30 @@ 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');
+       }
 }