Allow admins to disable 2FA backup codes via occ

Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
This commit is contained in:
Christoph Wurst 2021-08-13 15:28:56 +02:00
parent 7ab39effd3
commit d0d903c0f1
No known key found for this signature in database
GPG key ID: CC42AC2A7F0E56D8
4 changed files with 28 additions and 2 deletions

View file

@ -30,15 +30,15 @@ namespace OCA\TwoFactorBackupCodes\Provider;
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;
@ -164,4 +164,8 @@ class BackupCodesProvider implements IProvider, IProvidesPersonalSettings {
$this->initialStateService->provideInitialState($this->appName, 'state', $state);
return new Personal();
}
public function disableFor(IUser $user) {
$this->storage->deleteCodes($user);
}
}

View file

@ -136,4 +136,8 @@ class BackupCodeStorage {
}
return false;
}
public function deleteCodes(IUser $user): void {
$this->mapper->deleteCodes($user);
}
}

View file

@ -159,4 +159,13 @@ class BackupCodesProviderTest extends TestCase {
$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);
}
}

View file

@ -236,4 +236,13 @@ class BackupCodeStorageTest extends TestCase {
$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);
}
}