mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-08-02 01:04:41 +02:00
Added possibility to show backup codes in user settings.
This commit is contained in:
parent
fba5f9794f
commit
604ebe420d
13 changed files with 288 additions and 6 deletions
69
tests/Services/TFA/BackupCodeManagerTest.php
Normal file
69
tests/Services/TFA/BackupCodeManagerTest.php
Normal file
|
@ -0,0 +1,69 @@
|
|||
<?php
|
||||
|
||||
namespace App\Tests\Services\TFA;
|
||||
|
||||
use App\Entity\UserSystem\U2FKey;
|
||||
use App\Entity\UserSystem\User;
|
||||
use App\Services\TFA\BackupCodeManager;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||
|
||||
class BackupCodeManagerTest extends WebTestCase
|
||||
{
|
||||
/**
|
||||
* @var BackupCodeManager $service
|
||||
*/
|
||||
protected $service;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
self::bootKernel();
|
||||
$this->service = self::$container->get(BackupCodeManager::class);
|
||||
}
|
||||
|
||||
public function testRegenerateBackupCodes()
|
||||
{
|
||||
$user = new User();
|
||||
$old_codes = ['aaaa', 'bbbb'];
|
||||
$user->setBackupCodes($old_codes);
|
||||
$this->service->regenerateBackupCodes($user);
|
||||
$this->assertNotEquals($old_codes, $user->getBackupCodes());
|
||||
}
|
||||
|
||||
public function testEnableBackupCodes()
|
||||
{
|
||||
$user = new User();
|
||||
//Check that nothing is changed, if there are already backup codes
|
||||
|
||||
$old_codes = ['aaaa', 'bbbb'];
|
||||
$user->setBackupCodes($old_codes);
|
||||
$this->service->enableBackupCodes($user);
|
||||
$this->assertEquals($old_codes, $user->getBackupCodes());
|
||||
|
||||
//When no old codes are existing, it should generate a set
|
||||
$user->setBackupCodes([]);
|
||||
$this->service->enableBackupCodes($user);
|
||||
$this->assertNotEmpty($user->getBackupCodes());
|
||||
}
|
||||
|
||||
public function testDisableBackupCodesIfUnused()
|
||||
{
|
||||
$user = new User();
|
||||
|
||||
//By default nothing other 2FA is activated, so the backup codes should be disabled
|
||||
$codes = ['aaaa', 'bbbb'];
|
||||
$user->setBackupCodes($codes);
|
||||
$this->service->disableBackupCodesIfUnused($user);
|
||||
$this->assertEmpty($user->getBackupCodes());
|
||||
|
||||
$user->setBackupCodes($codes);
|
||||
|
||||
$user->setGoogleAuthenticatorSecret('jskf');
|
||||
$this->service->disableBackupCodesIfUnused($user);
|
||||
$this->assertEquals($codes, $user->getBackupCodes());
|
||||
|
||||
$user->setGoogleAuthenticatorSecret('');
|
||||
$user->addU2FKey(new U2FKey());
|
||||
$this->service->disableBackupCodesIfUnused($user);
|
||||
$this->assertEquals($codes, $user->getBackupCodes());
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue