mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Refactor tests and code to handle new 2FA methods.
This commit is contained in:
@@ -102,19 +102,10 @@ class UserControllerTest extends TestCase
|
||||
*/
|
||||
public function testIndex(): void
|
||||
{
|
||||
die('this test references old 2FA code.');
|
||||
$repository = $this->mock(UserRepositoryInterface::class);
|
||||
$repository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->times(3)->andReturn(true);
|
||||
$user = $this->user();
|
||||
$repository->shouldReceive('all')->andReturn(new Collection([$user]));
|
||||
|
||||
Preferences::shouldReceive('getArrayForUser')->atLeast()->once()->andReturn(
|
||||
[
|
||||
'twoFactorAuthEnabled' => false,
|
||||
'twoFactorAuthSecret' => null,
|
||||
]
|
||||
);
|
||||
|
||||
$this->mockDefaultSession();
|
||||
|
||||
$this->be($user);
|
||||
|
@@ -42,114 +42,18 @@ class TwoFactorControllerTest extends TestCase
|
||||
Log::info(sprintf('Now in %s.', get_class($this)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Auth\TwoFactorController
|
||||
*/
|
||||
public function testIndex(): void
|
||||
{
|
||||
die('this test references old 2FA code.');
|
||||
$this->mockDefaultConfiguration();
|
||||
$this->be($this->user());
|
||||
|
||||
|
||||
$truePref = new Preference;
|
||||
$truePref->data = true;
|
||||
$secretPreference = new Preference;
|
||||
$secretPreference->data = 'JZMES376Z6YXY4QZ';
|
||||
$langPreference = new Preference;
|
||||
$langPreference->data = 'en_US';
|
||||
|
||||
Preferences::shouldReceive('get')->withArgs(['twoFactorAuthEnabled', false])->andReturn($truePref)->twice();
|
||||
Preferences::shouldReceive('get')->withArgs(['twoFactorAuthSecret', null])->andReturn($secretPreference)->once();
|
||||
Preferences::shouldReceive('get')->withArgs(['twoFactorAuthSecret'])->andReturn($secretPreference)->once();
|
||||
Preferences::shouldReceive('get')->withArgs(['language', 'en_US'])->andReturn($langPreference);
|
||||
|
||||
$response = $this->get(route('two-factor.index'));
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Auth\TwoFactorController
|
||||
*/
|
||||
public function testIndexNo2FA(): void
|
||||
{
|
||||
die('this test references old 2FA code.');
|
||||
$this->be($this->user());
|
||||
|
||||
$falsePreference = new Preference;
|
||||
$falsePreference->data = false;
|
||||
$langPreference = new Preference;
|
||||
$langPreference->data = 'en_US';
|
||||
|
||||
Preferences::shouldReceive('get')->withArgs(['twoFactorAuthEnabled', false])->andReturn($falsePreference)->twice();
|
||||
Preferences::shouldReceive('get')->withArgs(['twoFactorAuthSecret', null])->andReturn(null)->once();
|
||||
Preferences::shouldReceive('get')->withArgs(['twoFactorAuthSecret'])->andReturn(null)->once();
|
||||
Preferences::shouldReceive('get')->withArgs(['language', 'en_US'])->andReturn($langPreference);
|
||||
|
||||
$response = $this->get(route('two-factor.index'));
|
||||
$response->assertStatus(302);
|
||||
$response->assertRedirect(route('index'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Auth\TwoFactorController
|
||||
*/
|
||||
public function testIndexNoSecret(): void
|
||||
{
|
||||
die('this test references old 2FA code.');
|
||||
$this->be($this->user());
|
||||
|
||||
$truePref = new Preference;
|
||||
$truePref->data = true;
|
||||
$secretPreference = new Preference;
|
||||
$secretPreference->data = '';
|
||||
$langPreference = new Preference;
|
||||
$langPreference->data = 'en_US';
|
||||
|
||||
Preferences::shouldReceive('get')->withArgs(['twoFactorAuthEnabled', false])->andReturn($truePref)->twice();
|
||||
Preferences::shouldReceive('get')->withArgs(['twoFactorAuthSecret', null])->andReturn($secretPreference)->once();
|
||||
Preferences::shouldReceive('get')->withArgs(['twoFactorAuthSecret'])->andReturn($secretPreference)->once();
|
||||
Preferences::shouldReceive('get')->withArgs(['language', 'en_US'])->andReturn($langPreference);
|
||||
|
||||
$response = $this->get(route('two-factor.index'));
|
||||
$response->assertStatus(500);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Auth\TwoFactorController
|
||||
*/
|
||||
public function testLostTwoFactor(): void
|
||||
{
|
||||
die('this test references old 2FA code.');
|
||||
$this->be($this->user());
|
||||
|
||||
$truePreference = new Preference;
|
||||
$truePreference->data = true;
|
||||
$secretPreference = new Preference;
|
||||
$secretPreference->data = 'JZMES376Z6YXY4QZ';
|
||||
$langPreference = new Preference;
|
||||
$langPreference->data = 'en_US';
|
||||
|
||||
Preferences::shouldReceive('get')->withArgs(['twoFactorAuthEnabled', false])->andReturn($truePreference);
|
||||
Preferences::shouldReceive('get')->withArgs(['twoFactorAuthSecret', null])->andReturn($secretPreference);
|
||||
Preferences::shouldReceive('get')->withArgs(['twoFactorAuthSecret'])->andReturn($secretPreference);
|
||||
Preferences::shouldReceive('get')->withArgs(['language', 'en_US'])->andReturn($langPreference);
|
||||
|
||||
$response = $this->get(route('two-factor.lost'));
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Auth\TwoFactorController
|
||||
*/
|
||||
public function testPostIndex(): void
|
||||
{
|
||||
$data = ['code' => '123456'];
|
||||
Google2FA::shouldReceive('verifyKey')->andReturn(true)->once();
|
||||
$this->session(['remember_login' => true]);
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->post(route('two-factor.post'), $data);
|
||||
$response->assertStatus(302);
|
||||
}
|
||||
}
|
||||
|
@@ -167,14 +167,7 @@ class ProfileControllerTest extends TestCase
|
||||
$this->mockDefaultSession();
|
||||
// mock stuff
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->atLeast()->once()->andReturn(false);
|
||||
|
||||
die('the references in this test to 2FA preferences must be refactored.');
|
||||
Preferences::shouldReceive('delete')->withArgs(['twoFactorAuthEnabled'])->atLeast()->once();
|
||||
Preferences::shouldReceive('delete')->withArgs(['twoFactorAuthSecret'])->atLeast()->once();
|
||||
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('profile.delete-code'));
|
||||
$response->assertStatus(302);
|
||||
@@ -211,17 +204,6 @@ class ProfileControllerTest extends TestCase
|
||||
$repository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->times(1)->andReturn(false);
|
||||
|
||||
Preferences::shouldReceive('set')->once()->withArgs(['twoFactorAuthEnabled', 1]);
|
||||
//Preferences::shouldReceive('lastActivity')->once();
|
||||
|
||||
die('the references in this test to 2FA preferences must be refactored.');
|
||||
$pref = new Preference;
|
||||
$pref->data = false;
|
||||
Preferences::shouldReceive('get')->withArgs(['twoFactorAuthEnabled', false])->atLeast()->once()->andReturn($pref);
|
||||
|
||||
$pref = new Preference;
|
||||
$pref->data = 'super-secret';
|
||||
Preferences::shouldReceive('get')->withArgs(['twoFactorAuthSecret'])->atLeast()->once()->andReturn($pref);
|
||||
|
||||
|
||||
$view = new Preference;
|
||||
$view->data = '1M';
|
||||
@@ -231,10 +213,6 @@ class ProfileControllerTest extends TestCase
|
||||
$lang->data = 'en_US';
|
||||
Preferences::shouldReceive('get')->withArgs(['language', 'en_US'])->andReturn($lang)->atLeast()->once();
|
||||
|
||||
// $pref = new Preference;
|
||||
// $pref->data = 'EUR';
|
||||
// Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'currencyPreference', 'EUR'])->atLeast()->once()->andReturn($pref);
|
||||
|
||||
$list = new Preference;
|
||||
$list->data = 50;
|
||||
Preferences::shouldReceive('get')->withArgs(['list-length', 10])->andReturn($list)->atLeast()->once();
|
||||
@@ -439,6 +417,7 @@ class ProfileControllerTest extends TestCase
|
||||
*/
|
||||
public function testPostCode(): void
|
||||
{
|
||||
$this->mock(UserRepositoryInterface::class);
|
||||
Log::info(sprintf('Now in test %s.', __METHOD__));
|
||||
$this->mockDefaultSession();
|
||||
|
||||
@@ -449,11 +428,7 @@ class ProfileControllerTest extends TestCase
|
||||
$this->withoutMiddleware();
|
||||
$this->session(['two-factor-secret' => $secret]);
|
||||
|
||||
die('the references in this test to 2FA preferences must be refactored.');
|
||||
Preferences::shouldReceive('set')->withArgs(['twoFactorAuthEnabled', 1])->once();
|
||||
Preferences::shouldReceive('set')->withArgs(['twoFactorAuthSecret', $secret])->once();
|
||||
Preferences::shouldReceive('mark')->once();
|
||||
|
||||
Google2FA::shouldReceive('verifyKey')->withArgs([$secret, $key])->andReturn(true);
|
||||
|
||||
$data = [
|
||||
|
Reference in New Issue
Block a user