Skip to content

Commit

Permalink
Merge pull request nextcloud#28421 from nextcloud/enhancement/2fa-bac…
Browse files Browse the repository at this point in the history
…kup-codes-disable-admin

Allow admins to disable 2FA backup codes via occ
  • Loading branch information
LukasReschke committed Aug 25, 2021
2 parents 48b3a6b + d0d903c commit 97ff0c9
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@
use OC\App\AppManager;
use OCA\TwoFactorBackupCodes\Service\BackupCodeStorage;
use OCA\TwoFactorBackupCodes\Settings\Personal;
use OCP\Authentication\TwoFactorAuth\IDeactivatableByAdmin;
use OCP\Authentication\TwoFactorAuth\IPersonalProviderSettings;
use OCP\Authentication\TwoFactorAuth\IProvider;
use OCP\Authentication\TwoFactorAuth\IProvidesPersonalSettings;
use OCP\IInitialStateService;
use OCP\IL10N;
use OCP\IUser;
use OCP\Template;

class BackupCodesProvider implements IProvider, IProvidesPersonalSettings {
class BackupCodesProvider implements IDeactivatableByAdmin, IProvidesPersonalSettings {

/** @var string */
private $appName;
Expand Down Expand Up @@ -164,4 +164,8 @@ public function getPersonalSettings(IUser $user): IPersonalProviderSettings {
$this->initialStateService->provideInitialState($this->appName, 'state', $state);
return new Personal();
}

public function disableFor(IUser $user) {
$this->storage->deleteCodes($user);
}
}
4 changes: 4 additions & 0 deletions apps/twofactor_backupcodes/lib/Service/BackupCodeStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,8 @@ public function validateCode(IUser $user, string $code): bool {
}
return false;
}

public function deleteCodes(IUser $user): void {
$this->mapper->deleteCodes($user);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -159,4 +159,13 @@ public function testIsActiveWithProviders() {

$this->assertTrue($this->provider->isActive($user));
}

public function testDisable(): void {
$user = $this->getMockBuilder(IUser::class)->getMock();
$this->storage->expects(self::once())
->method('deleteCodes')
->with($user);

$this->provider->disableFor($user);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -236,4 +236,13 @@ public function testValidateCodeWithWrongHash() {

$this->assertFalse($this->storage->validateCode($user, 'CHALLENGE'));
}

public function testDeleteCodes(): void {
$user = $this->createMock(IUser::class);
$this->mapper->expects($this->once())
->method('deleteCodes')
->with($user);

$this->storage->deleteCodes($user);
}
}

0 comments on commit 97ff0c9

Please sign in to comment.