2021-07-14 21:50:36 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\Commands;
|
|
|
|
|
2023-05-17 18:56:55 +02:00
|
|
|
use BookStack\Access\Mfa\MfaValue;
|
|
|
|
use BookStack\Users\Models\User;
|
2021-07-14 21:50:36 +02:00
|
|
|
use Tests\TestCase;
|
|
|
|
|
|
|
|
class ResetMfaCommandTest extends TestCase
|
|
|
|
{
|
|
|
|
public function test_command_requires_email_or_id_option()
|
|
|
|
{
|
|
|
|
$this->artisan('bookstack:reset-mfa')
|
2023-09-23 14:41:10 +02:00
|
|
|
->expectsOutputToContain('Either a --id=<number> or --email=<email> option must be provided.')
|
2021-07-14 21:50:36 +02:00
|
|
|
->assertExitCode(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function test_command_runs_with_provided_email()
|
|
|
|
{
|
|
|
|
/** @var User $user */
|
|
|
|
$user = User::query()->first();
|
|
|
|
MfaValue::upsertWithValue($user, MfaValue::METHOD_TOTP, 'test');
|
|
|
|
|
|
|
|
$this->assertEquals(1, $user->mfaValues()->count());
|
|
|
|
$this->artisan("bookstack:reset-mfa --email={$user->email}")
|
|
|
|
->expectsQuestion('Are you sure you want to proceed?', true)
|
|
|
|
->expectsOutput('User MFA methods have been reset.')
|
|
|
|
->assertExitCode(0);
|
|
|
|
$this->assertEquals(0, $user->mfaValues()->count());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function test_command_runs_with_provided_id()
|
|
|
|
{
|
|
|
|
/** @var User $user */
|
|
|
|
$user = User::query()->first();
|
|
|
|
MfaValue::upsertWithValue($user, MfaValue::METHOD_TOTP, 'test');
|
|
|
|
|
|
|
|
$this->assertEquals(1, $user->mfaValues()->count());
|
|
|
|
$this->artisan("bookstack:reset-mfa --id={$user->id}")
|
|
|
|
->expectsQuestion('Are you sure you want to proceed?', true)
|
|
|
|
->expectsOutput('User MFA methods have been reset.')
|
|
|
|
->assertExitCode(0);
|
|
|
|
$this->assertEquals(0, $user->mfaValues()->count());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function test_saying_no_to_confirmation_does_not_reset_mfa()
|
|
|
|
{
|
|
|
|
/** @var User $user */
|
|
|
|
$user = User::query()->first();
|
|
|
|
MfaValue::upsertWithValue($user, MfaValue::METHOD_TOTP, 'test');
|
|
|
|
|
|
|
|
$this->assertEquals(1, $user->mfaValues()->count());
|
|
|
|
$this->artisan("bookstack:reset-mfa --id={$user->id}")
|
|
|
|
->expectsQuestion('Are you sure you want to proceed?', false)
|
|
|
|
->assertExitCode(1);
|
|
|
|
$this->assertEquals(1, $user->mfaValues()->count());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function test_giving_non_existing_user_shows_error_message()
|
|
|
|
{
|
2021-08-21 16:49:40 +02:00
|
|
|
$this->artisan('bookstack:reset-mfa --email=donkeys@example.com')
|
2021-07-14 21:50:36 +02:00
|
|
|
->expectsOutput('A user where email=donkeys@example.com could not be found.')
|
|
|
|
->assertExitCode(1);
|
|
|
|
}
|
|
|
|
}
|