diff options
author | Roeland Jago Douma <roeland@famdouma.nl> | 2018-09-29 20:56:23 +0200 |
---|---|---|
committer | Roeland Jago Douma <roeland@famdouma.nl> | 2018-10-01 15:35:25 +0200 |
commit | 956fe1b86769c1a8a380a61ba72441f0e334e36a (patch) | |
tree | 5aa810228ca324dfe2d12a1f94f213d9ab657345 /tests | |
parent | a95154642dd6535ebddebef4e6562e777f2094a4 (diff) | |
download | nextcloud-server-956fe1b86769c1a8a380a61ba72441f0e334e36a.tar.gz nextcloud-server-956fe1b86769c1a8a380a61ba72441f0e334e36a.zip |
Generate backups code notification if not enable but 2fa is
Generate a notification to generate backup codes if you enable an other
2FA provider but backup codes are not yet generated.
* Add event listner
* Insert background job
* Background job tests and emits notification every 2 weeks
* If the backup codes are generated the next run will remove the job
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lib/Authentication/TwoFactorAuth/RegistryTest.php | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/tests/lib/Authentication/TwoFactorAuth/RegistryTest.php b/tests/lib/Authentication/TwoFactorAuth/RegistryTest.php index 3d2941e009a..08498738fa1 100644 --- a/tests/lib/Authentication/TwoFactorAuth/RegistryTest.php +++ b/tests/lib/Authentication/TwoFactorAuth/RegistryTest.php @@ -27,8 +27,11 @@ namespace Test\Authentication\TwoFactorAuth; use OC\Authentication\TwoFactorAuth\Db\ProviderUserAssignmentDao; use OC\Authentication\TwoFactorAuth\Registry; use OCP\Authentication\TwoFactorAuth\IProvider; +use OCP\Authentication\TwoFactorAuth\IRegistry; +use OCP\Authentication\TwoFactorAuth\RegistryEvent; use OCP\IUser; use PHPUnit_Framework_MockObject_MockObject; +use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Test\TestCase; class RegistryTest extends TestCase { @@ -39,12 +42,16 @@ class RegistryTest extends TestCase { /** @var Registry */ private $registry; + /** @var EventDispatcherInterface|\PHPUnit_Framework_MockObject_MockObject */ + private $dispatcher; + protected function setUp() { parent::setUp(); $this->dao = $this->createMock(ProviderUserAssignmentDao::class); + $this->dispatcher = $this->createMock(EventDispatcherInterface::class); - $this->registry = new Registry($this->dao); + $this->registry = new Registry($this->dao, $this->dispatcher); } public function testGetProviderStates() { @@ -68,6 +75,15 @@ class RegistryTest extends TestCase { $this->dao->expects($this->once())->method('persist')->with('p1', 'user123', true); + $this->dispatcher->expects($this->once()) + ->method('dispatch') + ->with( + $this->equalTo(IRegistry::EVENT_PROVIDER_ENABLED), + $this->callback(function(RegistryEvent $e) use ($user, $provider) { + return $e->getUser() === $user && $e->getProvider() === $provider; + }) + ); + $this->registry->enableProviderFor($provider, $user); } @@ -79,6 +95,16 @@ class RegistryTest extends TestCase { $this->dao->expects($this->once())->method('persist')->with('p1', 'user123', false); + + $this->dispatcher->expects($this->once()) + ->method('dispatch') + ->with( + $this->equalTo(IRegistry::EVENT_PROVIDER_DISABLED), + $this->callback(function(RegistryEvent $e) use ($user, $provider) { + return $e->getUser() === $user && $e->getProvider() === $provider; + }) + ); + $this->registry->disableProviderFor($provider, $user); } |