From 68794ebc9292cdedaa6a52d190e41e58f6edb1ba Mon Sep 17 00:00:00 2001 From: Christoph Wurst Date: Tue, 9 Jun 2020 14:33:06 +0200 Subject: Emit an event for every disabled 2FA provider during cleanup Signed-off-by: Christoph Wurst --- .../Db/ProviderUserAssignmentDaoTest.php | 25 +++++++++++++++++----- .../Authentication/TwoFactorAuth/RegistryTest.php | 11 +++++++++- 2 files changed, 30 insertions(+), 6 deletions(-) (limited to 'tests') diff --git a/tests/lib/Authentication/TwoFactorAuth/Db/ProviderUserAssignmentDaoTest.php b/tests/lib/Authentication/TwoFactorAuth/Db/ProviderUserAssignmentDaoTest.php index 1a21ee047df..7975108c59b 100644 --- a/tests/lib/Authentication/TwoFactorAuth/Db/ProviderUserAssignmentDaoTest.php +++ b/tests/lib/Authentication/TwoFactorAuth/Db/ProviderUserAssignmentDaoTest.php @@ -136,14 +136,29 @@ class ProviderUserAssignmentDaoTest extends TestCase { $this->dao->persist('twofactor_fail', 'user1', 1); $this->dao->persist('twofactor_u2f', 'user1', 1); $this->dao->persist('twofactor_fail', 'user2', 0); - $this->dao->persist('twofactor_u2f', 'user1', 0); - - $this->dao->deleteByUser('user1'); - + $this->dao->persist('twofactor_u2f', 'user2', 0); + + $deleted = $this->dao->deleteByUser('user1'); + + $this->assertEquals( + [ + [ + 'uid' => 'user1', + 'provider_id' => 'twofactor_fail', + 'enabled' => true, + ], + [ + 'uid' => 'user1', + 'provider_id' => 'twofactor_u2f', + 'enabled' => true, + ], + ], + $deleted + ); $statesUser1 = $this->dao->getState('user1'); $statesUser2 = $this->dao->getState('user2'); $this->assertCount(0, $statesUser1); - $this->assertCount(1, $statesUser2); + $this->assertCount(2, $statesUser2); } public function testDeleteAll() { diff --git a/tests/lib/Authentication/TwoFactorAuth/RegistryTest.php b/tests/lib/Authentication/TwoFactorAuth/RegistryTest.php index 49f4eaa7020..b0d0ef8efef 100644 --- a/tests/lib/Authentication/TwoFactorAuth/RegistryTest.php +++ b/tests/lib/Authentication/TwoFactorAuth/RegistryTest.php @@ -31,6 +31,7 @@ use OC\Authentication\TwoFactorAuth\Registry; use OCP\Authentication\TwoFactorAuth\IProvider; use OCP\Authentication\TwoFactorAuth\IRegistry; use OCP\Authentication\TwoFactorAuth\RegistryEvent; +use OCP\Authentication\TwoFactorAuth\TwoFactorProviderDisabled; use OCP\EventDispatcher\IEventDispatcher; use OCP\IUser; use PHPUnit\Framework\MockObject\MockObject; @@ -115,7 +116,15 @@ class RegistryTest extends TestCase { $user->expects($this->once())->method('getUID')->willReturn('user123'); $this->dao->expects($this->once()) ->method('deleteByUser') - ->with('user123'); + ->with('user123') + ->willReturn([ + [ + 'provider_id' => 'twofactor_u2f', + ] + ]); + $this->dispatcher->expects($this->once()) + ->method('dispatchTyped') + ->with(new TwoFactorProviderDisabled('twofactor_u2f')); $this->registry->deleteUserData($user); } -- cgit v1.2.3