Skip to content

Firefly III: a personal finances manager

remove "twoFactorAuthEnabled" from preferences. Kill switches for all code that references them (easier for refactor)

James Cole7f1bd19e45a4
diff --git a/app/Api/V1/Controllers/PreferenceController.php b/app/Api/V1/Controllers/PreferenceController.php
index 7811875b1a..1dc807e410 100644
--- a/app/Api/V1/Controllers/PreferenceController.php
+++ b/app/Api/V1/Controllers/PreferenceController.php
@@ -88,7 +88,7 @@ class PreferenceController extends Controller
$available = [
'language', 'customFiscalYear', 'fiscalYearStart', 'currencyPreference',
'transaction_journal_optional_fields', 'frontPageAccounts', 'viewRange',
- 'listPageSize, twoFactorAuthEnabled',
+ 'listPageSize',
];
$preferences = new Collection;
@@ -166,7 +166,6 @@ class PreferenceController extends Controller
$newValue = (int)$data['data'];
break;
case 'customFiscalYear':
- case 'twoFactorAuthEnabled':
$newValue = 1 === (int)$data['data'];
break;
}
diff --git a/app/Http/Controllers/Admin/UserController.php b/app/Http/Controllers/Admin/UserController.php
index 328c3aeec7..9634556cd8 100644
--- a/app/Http/Controllers/Admin/UserController.php
+++ b/app/Http/Controllers/Admin/UserController.php
@@ -125,6 +125,7 @@ class UserController extends Controller
$users = $this->repository->all();
// add meta stuff.
+ die('the 2FA references here should be refactored.');
$users->each(
function (User $user) {
$list = ['twoFactorAuthEnabled', 'twoFactorAuthSecret'];
diff --git a/app/Http/Controllers/Auth/TwoFactorController.php b/app/Http/Controllers/Auth/TwoFactorController.php
index d6db6d5e34..8509d96c5e 100644
--- a/app/Http/Controllers/Auth/TwoFactorController.php
+++ b/app/Http/Controllers/Auth/TwoFactorController.php
@@ -47,6 +47,7 @@ class TwoFactorController extends Controller
*/
public function index(Request $request)
{
+ die('this auth controller must be refactored.');
$user = auth()->user();
// to make sure the validator in the next step gets the secret, we push it in session
diff --git a/app/Http/Controllers/ProfileController.php b/app/Http/Controllers/ProfileController.php
index 88a1dc6269..9d328a642a 100644
--- a/app/Http/Controllers/ProfileController.php
+++ b/app/Http/Controllers/ProfileController.php
@@ -218,6 +218,7 @@ class ProfileController extends Controller
*/
public function deleteCode()
{
+ die('this method is deprecated.');
app('preferences')->delete('twoFactorAuthEnabled');
app('preferences')->delete('twoFactorAuthSecret');
session()->flash('success', (string)trans('firefly.pref_two_factor_auth_disabled'));
@@ -233,6 +234,7 @@ class ProfileController extends Controller
*/
public function enable2FA()
{
+ die('this method is deprecated.');
$hasSecret = (null !== app('preferences')->get('twoFactorAuthSecret'));
// if we don't have a valid secret yet, redirect to the code page to get one.
@@ -255,6 +257,7 @@ class ProfileController extends Controller
*/
public function index()
{
+ die('remove or refactor references to 2FA before continuing.');
$loginProvider = config('firefly.login_provider');
// check if client token thing exists (default one)
$count = DB::table('oauth_clients')
@@ -388,6 +391,7 @@ class ProfileController extends Controller
*/
public function postCode(TokenFormRequest $request)
{
+ die('this method is deprecated');
app('preferences')->set('twoFactorAuthEnabled', 1);
app('preferences')->set('twoFactorAuthSecret', session()->get('two-factor-secret'));
diff --git a/app/Http/Middleware/AuthenticateTwoFactor.php b/app/Http/Middleware/AuthenticateTwoFactor.php
index 1b2e62b728..c2a5064e2f 100644
--- a/app/Http/Middleware/AuthenticateTwoFactor.php
+++ b/app/Http/Middleware/AuthenticateTwoFactor.php
@@ -66,6 +66,7 @@ class AuthenticateTwoFactor
*/
public function handle($request, Closure $next)
{
+ die('this middleware is deprecated.');
/** @noinspection PhpUndefinedMethodInspection */
if ($this->auth->guest()) {
return response()->redirectTo(route('login'));
diff --git a/app/Http/Middleware/RedirectIfTwoFactorAuthenticated.php b/app/Http/Middleware/RedirectIfTwoFactorAuthenticated.php
index f6bcefab69..8f971e12b8 100644
--- a/app/Http/Middleware/RedirectIfTwoFactorAuthenticated.php
+++ b/app/Http/Middleware/RedirectIfTwoFactorAuthenticated.php
@@ -43,6 +43,7 @@ class RedirectIfTwoFactorAuthenticated
*/
public function handle($request, Closure $next, $guard = null)
{
+ die('this middleware is deprecated.');
if (Auth::guard($guard)->check()) {
$is2faEnabled = app('preferences')->get('twoFactorAuthEnabled', false)->data;
$has2faSecret = null !== app('preferences')->get('twoFactorAuthSecret');
diff --git a/app/Repositories/User/UserRepository.php b/app/Repositories/User/UserRepository.php
index 471545a298..b599ad9857 100644
--- a/app/Repositories/User/UserRepository.php
+++ b/app/Repositories/User/UserRepository.php
@@ -245,6 +245,7 @@ class UserRepository implements UserRepositoryInterface
$return = [];
// two factor:
+ die('this method references 2FA and must be refactored.');
$is2faEnabled = app('preferences')->getForUser($user, 'twoFactorAuthEnabled', false)->data;
$has2faSecret = null !== app('preferences')->getForUser($user, 'twoFactorAuthSecret');
$return['has_2fa'] = false;
diff --git a/tests/Feature/Controllers/Admin/UserControllerTest.php b/tests/Feature/Controllers/Admin/UserControllerTest.php
index 8a0bf70364..f7cc0fe571 100644
--- a/tests/Feature/Controllers/Admin/UserControllerTest.php
+++ b/tests/Feature/Controllers/Admin/UserControllerTest.php
@@ -102,6 +102,7 @@ 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();
diff --git a/tests/Feature/Controllers/Auth/TwoFactorControllerTest.php b/tests/Feature/Controllers/Auth/TwoFactorControllerTest.php
index 6967e08f4b..a75c9ed4f0 100644
--- a/tests/Feature/Controllers/Auth/TwoFactorControllerTest.php
+++ b/tests/Feature/Controllers/Auth/TwoFactorControllerTest.php
@@ -47,6 +47,7 @@ class TwoFactorControllerTest extends TestCase
*/
public function testIndex(): void
{
+ die('this test references old 2FA code.');
$this->mockDefaultConfiguration();
$this->be($this->user());
@@ -72,6 +73,7 @@ class TwoFactorControllerTest extends TestCase
*/
public function testIndexNo2FA(): void
{
+ die('this test references old 2FA code.');
$this->be($this->user());
$falsePreference = new Preference;
@@ -94,6 +96,7 @@ class TwoFactorControllerTest extends TestCase
*/
public function testIndexNoSecret(): void
{
+ die('this test references old 2FA code.');
$this->be($this->user());
$truePref = new Preference;
@@ -117,6 +120,7 @@ class TwoFactorControllerTest extends TestCase
*/
public function testLostTwoFactor(): void
{
+ die('this test references old 2FA code.');
$this->be($this->user());
$truePreference = new Preference;
diff --git a/tests/Feature/Controllers/ProfileControllerTest.php b/tests/Feature/Controllers/ProfileControllerTest.php
index a24643f39d..c38d6dff58 100644
--- a/tests/Feature/Controllers/ProfileControllerTest.php
+++ b/tests/Feature/Controllers/ProfileControllerTest.php
@@ -170,6 +170,7 @@ class ProfileControllerTest extends TestCase
$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();
@@ -212,6 +213,7 @@ class ProfileControllerTest extends TestCase
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);
@@ -220,6 +222,7 @@ class ProfileControllerTest extends TestCase
$pref->data = 'super-secret';
Preferences::shouldReceive('get')->withArgs(['twoFactorAuthSecret'])->atLeast()->once()->andReturn($pref);
+
$view = new Preference;
$view->data = '1M';
Preferences::shouldReceive('get')->withArgs(['viewRange', Mockery::any()])->andReturn($view)->atLeast()->once();
@@ -446,6 +449,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();
diff --git a/tests/TestCase.php b/tests/TestCase.php
index aa222715f6..b0eee779ff 100644
--- a/tests/TestCase.php
+++ b/tests/TestCase.php
@@ -451,6 +451,7 @@ abstract class TestCase extends BaseTestCase
$list = new Preference;
$list->data = 50;
+ die('the references in this test to 2FA preferences must be refactored.');
Preferences::shouldReceive('get')->withArgs(['twoFactorAuthEnabled', false])->andReturn($false);
Preferences::shouldReceive('get')->withArgs(['twoFactorAuthSecret'])->andReturnNull();
Preferences::shouldReceive('get')->withArgs(['viewRange', Mockery::any()])->andReturn($view);
diff --git a/tests/Unit/Middleware/AuthenticateTwoFactorTest.php b/tests/Unit/Middleware/AuthenticateTwoFactorTest.php
index d75a6458e0..18d14781dc 100644
--- a/tests/Unit/Middleware/AuthenticateTwoFactorTest.php
+++ b/tests/Unit/Middleware/AuthenticateTwoFactorTest.php
@@ -73,6 +73,7 @@ class AuthenticateTwoFactorTest extends TestCase
*/
public function testMiddlewareNoTwoFA(): void
{
+ die('this test references old 2FA code.');
$this->withoutExceptionHandling();
$user = $this->user();
$user->blocked = 0;
@@ -104,6 +105,7 @@ class AuthenticateTwoFactorTest extends TestCase
*/
public function testMiddlewareTwoFAAuthed(): void
{
+ die('this test references old 2FA code.');
$this->withoutExceptionHandling();
$user = $this->user();
$user->blocked = 0;
@@ -137,6 +139,7 @@ class AuthenticateTwoFactorTest extends TestCase
*/
public function testMiddlewareTwoFANoSecret(): void
{
+ die('this test references old 2FA code.');
$this->withoutExceptionHandling();
$user = $this->user();
$user->blocked = 0;
@@ -168,6 +171,7 @@ class AuthenticateTwoFactorTest extends TestCase
*/
public function testMiddlewareTwoFASecret(): void
{
+ die('this test references old 2FA code.');
$this->withoutExceptionHandling();
$user = $this->user();
$user->blocked = 0;
diff --git a/tests/Unit/Middleware/RedirectIf2FAAuthenticatedTest.php b/tests/Unit/Middleware/RedirectIf2FAAuthenticatedTest.php
index cc1b1b8fac..c8bb097646 100644
--- a/tests/Unit/Middleware/RedirectIf2FAAuthenticatedTest.php
+++ b/tests/Unit/Middleware/RedirectIf2FAAuthenticatedTest.php
@@ -64,6 +64,7 @@ class RedirectIf2FAAuthenticatedTest extends TestCase
*/
public function testMiddlewareAuthenticated(): void
{
+ die('this test references old 2FA code.');
// pref for has 2fa is true
$preference = new Preference;
$preference->data = true;