3 namespace Tests\Commands;
5 use BookStack\Access\Mfa\MfaValue;
6 use BookStack\Users\Models\User;
9 class ResetMfaCommandTest extends TestCase
11 public function test_command_requires_email_or_id_option()
13 $this->artisan('bookstack:reset-mfa')
14 ->expectsOutput('Either a --id=<number> or --email=<email> option must be provided.')
18 public function test_command_runs_with_provided_email()
20 /** @var User $user */
21 $user = User::query()->first();
22 MfaValue::upsertWithValue($user, MfaValue::METHOD_TOTP, 'test');
24 $this->assertEquals(1, $user->mfaValues()->count());
25 $this->artisan("bookstack:reset-mfa --email={$user->email}")
26 ->expectsQuestion('Are you sure you want to proceed?', true)
27 ->expectsOutput('User MFA methods have been reset.')
29 $this->assertEquals(0, $user->mfaValues()->count());
32 public function test_command_runs_with_provided_id()
34 /** @var User $user */
35 $user = User::query()->first();
36 MfaValue::upsertWithValue($user, MfaValue::METHOD_TOTP, 'test');
38 $this->assertEquals(1, $user->mfaValues()->count());
39 $this->artisan("bookstack:reset-mfa --id={$user->id}")
40 ->expectsQuestion('Are you sure you want to proceed?', true)
41 ->expectsOutput('User MFA methods have been reset.')
43 $this->assertEquals(0, $user->mfaValues()->count());
46 public function test_saying_no_to_confirmation_does_not_reset_mfa()
48 /** @var User $user */
49 $user = User::query()->first();
50 MfaValue::upsertWithValue($user, MfaValue::METHOD_TOTP, 'test');
52 $this->assertEquals(1, $user->mfaValues()->count());
53 $this->artisan("bookstack:reset-mfa --id={$user->id}")
54 ->expectsQuestion('Are you sure you want to proceed?', false)
56 $this->assertEquals(1, $user->mfaValues()->count());
59 public function test_giving_non_existing_user_shows_error_message()