Make the reset-testing command create multi-user test data

This commit is contained in:
Bubka 2023-02-25 22:29:55 +01:00
parent e6e49ef829
commit fe9eb19825
2 changed files with 97 additions and 66 deletions

View File

@ -60,7 +60,6 @@ trait ResetTrait
protected function flushDB() : void protected function flushDB() : void
{ {
// Reset the db // Reset the db
DB::table('users')->delete();
DB::table('password_resets')->delete(); DB::table('password_resets')->delete();
DB::table('oauth_access_tokens')->delete(); DB::table('oauth_access_tokens')->delete();
DB::table('oauth_personal_access_clients')->delete(); DB::table('oauth_personal_access_clients')->delete();
@ -68,8 +67,9 @@ trait ResetTrait
DB::table('webauthn_credentials')->delete(); DB::table('webauthn_credentials')->delete();
DB::table('webauthn_recoveries')->delete(); DB::table('webauthn_recoveries')->delete();
DB::table('twofaccounts')->delete(); DB::table('twofaccounts')->delete();
DB::table('options')->delete();
DB::table('groups')->delete(); DB::table('groups')->delete();
DB::table('users')->delete();
DB::table('options')->delete();
$this->line('Database cleaned'); $this->line('Database cleaned');
} }

View File

@ -16,19 +16,20 @@ class TestingSeeder extends Seeder
*/ */
public function run() public function run()
{ {
User::create([ $admin = User::create([
'name' => 'Tester', 'name' => 'Tester_admin',
'email' => 'testing@2fauth.app', 'email' => 'testingAdmin@2fauth.app',
'password' => bcrypt('password'), 'password' => bcrypt('password'),
'is_admin' => 1, 'is_admin' => 1,
]); ]);
$groupSocialNetwork = Group::create([ $groupSocialNetwork = $admin->groups()->create([
'name' => 'Social Networks', 'name' => 'Social Networks (admin)',
]); ]);
$groupSocialNetwork->twofaccounts()->createMany([ $admin->twofaccounts()->createMany([
[ [
'group_id' => $groupSocialNetwork->id,
'otp_type' => 'totp', 'otp_type' => 'totp',
'account' => 'johndoe@facebook.com', 'account' => 'johndoe@facebook.com',
'service' => 'Facebook', 'service' => 'Facebook',
@ -40,6 +41,7 @@ class TestingSeeder extends Seeder
'legacy_uri' => 'otpauth://totp/Facebook:johndoe@facebook.com?secret=A4GRFTVVRBGY7UIW', 'legacy_uri' => 'otpauth://totp/Facebook:johndoe@facebook.com?secret=A4GRFTVVRBGY7UIW',
], ],
[ [
'group_id' => $groupSocialNetwork->id,
'otp_type' => 'totp', 'otp_type' => 'totp',
'service' => 'Twitter', 'service' => 'Twitter',
'account' => '@john', 'account' => '@john',
@ -51,6 +53,7 @@ class TestingSeeder extends Seeder
'legacy_uri' => 'otpauth://totp/Twitter:@john?secret=A2GRFTVVRBGY7UIW', 'legacy_uri' => 'otpauth://totp/Twitter:@john?secret=A2GRFTVVRBGY7UIW',
], ],
[ [
'group_id' => $groupSocialNetwork->id,
'otp_type' => 'totp', 'otp_type' => 'totp',
'service' => 'Instagram', 'service' => 'Instagram',
'account' => '@johndoe', 'account' => '@johndoe',
@ -60,8 +63,67 @@ class TestingSeeder extends Seeder
'period' => 30, 'period' => 30,
'icon' => 'instagram.png', 'icon' => 'instagram.png',
'legacy_uri' => 'otpauth://totp/Instagram:@johndoe?secret=A6GRFTVVRBGY7UIW', 'legacy_uri' => 'otpauth://totp/Instagram:@johndoe?secret=A6GRFTVVRBGY7UIW',
]
]);
$groupCloud = $admin->groups()->create([
'name' => 'Cloud',
]);
$admin->twofaccounts()->createMany([
[
'group_id' => $groupCloud->id,
'otp_type' => 'totp',
'account' => 'john.doe',
'service' => 'Dropbox',
'secret' => 'A3GRFTVVRBGY7UIW',
'algorithm' => 'sha1',
'digits' => 6,
'period' => 30,
'icon' => 'dropbox.png',
'legacy_uri' => 'otpauth://totp/Dropbox:john.doe?secret=A3GRFTVVRBGY7UIW',
]
]);
$admin->twofaccounts()->createMany([
[
'otp_type' => 'totp',
'account' => 'johndoe',
'service' => 'Amazon',
'secret' => 'A7GRFTVVRBGY7UIW',
'algorithm' => 'sha1',
'digits' => 6,
'period' => 30,
'icon' => 'amazon.png',
'legacy_uri' => 'otpauth://totp/Amazon:johndoe?secret=A7GRFTVVRBGY7UIW',
], ],
[ [
'otp_type' => 'totp',
'account' => 'john.doe@icloud.com',
'service' => 'Apple',
'secret' => 'A2GRFTVVRBGY7UIW',
'algorithm' => 'sha1',
'digits' => 6,
'period' => 30,
'icon' => 'apple.png',
'legacy_uri' => 'otpauth://totp/Apple:john.doe@icloud.com?secret=A2GRFTVVRBGY7UIW',
]
]);
$user = User::create([
'name' => 'Tester_user',
'email' => 'testingUser@2fauth.app',
'password' => bcrypt('password'),
'is_admin' => 0,
]);
$groupSocialNetworkUser = $user->groups()->create([
'name' => 'Social Networks (user)',
]);
$user->twofaccounts()->createMany([
[
'group_id' => $groupSocialNetworkUser->id,
'otp_type' => 'totp', 'otp_type' => 'totp',
'service' => 'LinkedIn', 'service' => 'LinkedIn',
'account' => '@johndoe', 'account' => '@johndoe',
@ -74,68 +136,37 @@ class TestingSeeder extends Seeder
] ]
]); ]);
$groupECommerce = Group::create([ $groupGafam = $user->groups()->create([
'name' => 'eCommerce', 'name' => 'GAFAM',
]); ]);
$groupECommerce->twofaccounts()->create([ $user->twofaccounts()->createMany([
'otp_type' => 'totp', [
'account' => 'johndoe', 'group_id' => $groupGafam->id,
'service' => 'Amazon', 'otp_type' => 'totp',
'secret' => 'A7GRFTVVRBGY7UIW', 'service' => 'Google',
'algorithm' => 'sha1', 'account' => 'john.doe@gmail.com',
'digits' => 6, 'secret' => 'A5GRFTVVRBGY7UIW',
'period' => 30, 'algorithm' => 'sha1',
'icon' => 'amazon.png', 'digits' => 6,
'legacy_uri' => 'otpauth://totp/Amazon:johndoe?secret=A7GRFTVVRBGY7UIW', 'period' => 30,
'icon' => 'google.png',
'legacy_uri' => 'otpauth://totp/Google:john.doe@gmail.com?secret=A5GRFTVVRBGY7UIW',
]
]); ]);
TwoFAccount::create([ $user->twofaccounts()->createMany([
'otp_type' => 'totp', [
'account' => 'john.doe@icloud.com', 'otp_type' => 'totp',
'service' => 'Apple', 'account' => '@john',
'secret' => 'A2GRFTVVRBGY7UIW', 'service' => 'Github',
'algorithm' => 'sha1', 'secret' => 'A2GRFTVVRBGY7UIW',
'digits' => 6, 'algorithm' => 'sha1',
'period' => 30, 'digits' => 6,
'icon' => 'apple.png', 'period' => 30,
'legacy_uri' => 'otpauth://totp/Apple:john.doe@icloud.com?secret=A2GRFTVVRBGY7UIW', 'icon' => 'github.png',
]); 'legacy_uri' => 'otpauth://totp/Github:@john?secret=A2GRFTVVRBGY7UIW',
],
TwoFAccount::create([
'otp_type' => 'totp',
'account' => 'john.doe',
'service' => 'Dropbox',
'secret' => 'A3GRFTVVRBGY7UIW',
'algorithm' => 'sha1',
'digits' => 6,
'period' => 30,
'icon' => 'dropbox.png',
'legacy_uri' => 'otpauth://totp/Dropbox:john.doe?secret=A3GRFTVVRBGY7UIW',
]);
TwoFAccount::create([
'otp_type' => 'totp',
'account' => '@john',
'service' => 'Github',
'secret' => 'A2GRFTVVRBGY7UIW',
'algorithm' => 'sha1',
'digits' => 6,
'period' => 30,
'icon' => 'github.png',
'legacy_uri' => 'otpauth://totp/Github:@john?secret=A2GRFTVVRBGY7UIW',
]);
TwoFAccount::create([
'otp_type' => 'totp',
'service' => 'Google',
'account' => 'john.doe@gmail.com',
'secret' => 'A5GRFTVVRBGY7UIW',
'algorithm' => 'sha1',
'digits' => 6,
'period' => 30,
'icon' => 'google.png',
'legacy_uri' => 'otpauth://totp/Google:john.doe@gmail.com?secret=A5GRFTVVRBGY7UIW',
]); ]);
} }
} }