Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Do not send notification if no active 2fa
If the job is still present we should also not fire it off if there is
not a single active 2FA provider.

Signed-off-by: Roeland Jago Douma <[email protected]>
  • Loading branch information
rullzer authored and Backportbot committed Mar 6, 2019
commit 390917a9e5bace3d4e8f709b30bb52aef80744cd
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,15 @@ protected function run($argument) {
}

$providers = $this->registry->getProviderStates($user);
if (isset($providers['backup_codes']) && $providers['backup_codes'] === true) {
$state2fa = array_reduce($providers, function(bool $carry, bool $state) {
return $carry || $state;
}, false);

/*
* If no provider is active or if the backup codes are already generate
* we can remove the job
*/
if ($state2fa === false || (isset($providers['backup_codes']) && $providers['backup_codes'] === true)) {
// Backup codes already generated lets remove this job
$this->jobList->remove(self::class, $argument);
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,34 @@ public function testBackupCodesGenerated() {
$this->invokePrivate($this->job, 'run', [['uid' => 'validUID']]);
}

public function testNoActiveProvider() {
$user = $this->createMock(IUser::class);
$user->method('getUID')
->willReturn('validUID');
$this->userManager->method('get')
->with('validUID')
->willReturn($user);

$this->registry->method('getProviderStates')
->with($user)
->willReturn([
'backup_codes' => false,
'foo' => false,
]);

$this->jobList->expects($this->once())
->method('remove')
->with(
RememberBackupCodesJob::class,
['uid' => 'validUID']
);

$this->notificationManager->expects($this->never())
->method($this->anything());

$this->invokePrivate($this->job, 'run', [['uid' => 'validUID']]);
}

public function testNotificationSend() {
$user = $this->createMock(IUser::class);
$user->method('getUID')
Expand All @@ -125,7 +153,8 @@ public function testNotificationSend() {
$this->registry->method('getProviderStates')
->with($user)
->willReturn([
'backup_codes' => false
'backup_codes' => false,
'foo' => true,
]);

$this->jobList->expects($this->never())
Expand Down