Target db tables using config helper rather than hard coded strings

This commit is contained in:
Bubka 2024-01-26 18:16:55 +01:00
parent 8b397750e8
commit 6fe00585e5
5 changed files with 33 additions and 17 deletions

View File

@ -60,12 +60,12 @@ trait ResetTrait
protected function flushDB() : void
{
// Reset the db
DB::table('password_resets')->delete();
DB::table(config('auth.passwords.users.table'))->delete();
DB::table('oauth_access_tokens')->delete();
DB::table('oauth_personal_access_clients')->delete();
DB::table('oauth_refresh_tokens')->delete();
DB::table('webauthn_credentials')->delete();
DB::table('webauthn_recoveries')->delete();
DB::table(config('auth.passwords.webauthn.table'))->delete();
DB::table('twofaccounts')->delete();
DB::table('groups')->delete();
DB::table('users')->delete();

View File

@ -72,9 +72,9 @@ class UserController extends Controller
DB::table('twofaccounts')->where('user_id', $user->id)->delete();
DB::table('groups')->where('user_id', $user->id)->delete();
DB::table('webauthn_credentials')->where('authenticatable_id', $user->id)->delete();
DB::table('webauthn_recoveries')->where('email', $user->email)->delete();
DB::table(config('auth.passwords.webauthn.table'))->where('email', $user->email)->delete();
DB::table('oauth_access_tokens')->where('user_id', $user->id)->delete();
DB::table('password_resets')->where('email', $user->email)->delete();
DB::table(config('auth.passwords.users.table'))->where('email', $user->email)->delete();
DB::table('users')->where('id', $user->id)->delete();
});
}

View File

@ -81,7 +81,7 @@ class ForgotPasswordControllerTest extends FeatureTestCase
$response->assertStatus(200);
$token = \Illuminate\Support\Facades\DB::table('password_resets')->first();
$token = \Illuminate\Support\Facades\DB::table(config('auth.passwords.users.table'))->first();
$this->assertNotNull($token);
Notification::assertSentTo($this->user, ResetPassword::class, function ($notification, $channels) use ($token) {

View File

@ -58,7 +58,7 @@ class WebAuthnDeviceLostControllerTest extends FeatureTestCase
'message',
]);
$this->assertDatabaseHas('webauthn_recoveries', [
$this->assertDatabaseHas(config('auth.passwords.webauthn.table'), [
'email' => $this->user->email,
]);
}
@ -119,7 +119,7 @@ class WebAuthnDeviceLostControllerTest extends FeatureTestCase
'email',
]);
$this->assertDatabaseMissing('webauthn_recoveries', [
$this->assertDatabaseMissing(config('auth.passwords.webauthn.table'), [
'email' => 'bad@email.com',
]);
}
@ -142,7 +142,7 @@ class WebAuthnDeviceLostControllerTest extends FeatureTestCase
'email',
]);
$this->assertDatabaseMissing('webauthn_recoveries', [
$this->assertDatabaseMissing(config('auth.passwords.webauthn.table'), [
'email' => 'bad@email.com',
]);
}
@ -188,7 +188,7 @@ class WebAuthnDeviceLostControllerTest extends FeatureTestCase
'message',
]);
$this->assertDatabaseHas('webauthn_recoveries', [
$this->assertDatabaseHas(config('auth.passwords.webauthn.table'), [
'email' => $this->user->email,
]);

View File

@ -46,7 +46,7 @@ class WebAuthnRecoveryControllerTest extends FeatureTestCase
Date::setTestNow($this->now = Date::create(2022, 11, 16, 9, 4));
DB::table('webauthn_recoveries')->insert([
DB::table(config('auth.passwords.webauthn.table'))->insert([
'email' => $this->user->email,
'token' => self::STORED_TOKEN_VALUE,
'created_at' => $this->now->toDateTimeString(),
@ -58,7 +58,7 @@ class WebAuthnRecoveryControllerTest extends FeatureTestCase
*/
public function test_recover_fails_if_no_recovery_is_set()
{
DB::table('webauthn_recoveries')->delete();
DB::table(config('auth.passwords.webauthn.table'))->delete();
$this->json('POST', '/webauthn/recover', [
'token' => self::ACTUAL_TOKEN_VALUE,
@ -91,8 +91,8 @@ class WebAuthnRecoveryControllerTest extends FeatureTestCase
{
Date::setTestNow($now = Date::create(2020, 01, 01, 16, 30));
DB::table('webauthn_recoveries')->delete();
DB::table('webauthn_recoveries')->insert([
DB::table(config('auth.passwords.webauthn.table'))->delete();
DB::table(config('auth.passwords.webauthn.table'))->insert([
'token' => self::STORED_TOKEN_VALUE,
'email' => $this->user->email,
'created_at' => $now->clone()->subHour()->subSecond()->toDateTimeString(),
@ -148,13 +148,29 @@ class WebAuthnRecoveryControllerTest extends FeatureTestCase
])
->assertStatus(200);
$this->assertDatabaseMissing('webauthn_recoveries', [
$this->assertDatabaseMissing(config('auth.passwords.webauthn.table'), [
'token' => self::STORED_TOKEN_VALUE,
]);
}
$this->assertDatabaseMissing('options', [
'key' => 'useWebauthnOnly',
]);
/**
* @test
*/
public function test_recover_resets_useWebauthnOnly_user_preference()
{
$this->user['preferences->useWebauthnOnly'] = true;
$this->user->save();
$response = $this->json('POST', '/webauthn/recover', [
'token' => self::ACTUAL_TOKEN_VALUE,
'email' => $this->user->email,
'password' => UserFactory::USER_PASSWORD,
])
->assertStatus(200);
$this->user->refresh();
$this->assertFalse($this->user->preferences['useWebauthnOnly']);
}
/**