2022-01-31 21:43:41 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\Commands;
|
|
|
|
|
2023-05-17 18:56:55 +02:00
|
|
|
use BookStack\Users\Models\User;
|
2022-01-31 21:43:41 +01:00
|
|
|
use Illuminate\Support\Facades\Auth;
|
|
|
|
use Tests\TestCase;
|
|
|
|
|
|
|
|
class CreateAdminCommandTest extends TestCase
|
|
|
|
{
|
|
|
|
public function test_standard_command_usage()
|
|
|
|
{
|
|
|
|
$this->artisan('bookstack:create-admin', [
|
2022-02-01 12:49:30 +01:00
|
|
|
'--email' => 'admintest@example.com',
|
|
|
|
'--name' => 'Admin Test',
|
2022-01-31 21:43:41 +01:00
|
|
|
'--password' => 'testing-4',
|
|
|
|
])->assertExitCode(0);
|
|
|
|
|
|
|
|
$this->assertDatabaseHas('users', [
|
|
|
|
'email' => 'admintest@example.com',
|
2022-02-01 12:49:30 +01:00
|
|
|
'name' => 'Admin Test',
|
2022-01-31 21:43:41 +01:00
|
|
|
]);
|
|
|
|
|
|
|
|
/** @var User $user */
|
|
|
|
$user = User::query()->where('email', '=', 'admintest@example.com')->first();
|
|
|
|
$this->assertTrue($user->hasSystemRole('admin'));
|
|
|
|
$this->assertTrue(Auth::attempt(['email' => 'admintest@example.com', 'password' => 'testing-4']));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function test_providing_external_auth_id()
|
|
|
|
{
|
|
|
|
$this->artisan('bookstack:create-admin', [
|
2022-02-01 12:49:30 +01:00
|
|
|
'--email' => 'admintest@example.com',
|
|
|
|
'--name' => 'Admin Test',
|
2022-01-31 21:43:41 +01:00
|
|
|
'--external-auth-id' => 'xX_admin_Xx',
|
|
|
|
])->assertExitCode(0);
|
|
|
|
|
|
|
|
$this->assertDatabaseHas('users', [
|
2022-02-01 12:49:30 +01:00
|
|
|
'email' => 'admintest@example.com',
|
|
|
|
'name' => 'Admin Test',
|
2022-01-31 21:43:41 +01:00
|
|
|
'external_auth_id' => 'xX_admin_Xx',
|
|
|
|
]);
|
|
|
|
|
|
|
|
/** @var User $user */
|
|
|
|
$user = User::query()->where('email', '=', 'admintest@example.com')->first();
|
|
|
|
$this->assertNotEmpty($user->password);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function test_password_required_if_external_auth_id_not_given()
|
|
|
|
{
|
|
|
|
$this->artisan('bookstack:create-admin', [
|
|
|
|
'--email' => 'admintest@example.com',
|
2022-02-01 12:49:30 +01:00
|
|
|
'--name' => 'Admin Test',
|
2022-01-31 21:43:41 +01:00
|
|
|
])->expectsQuestion('Please specify a password for the new admin user (8 characters min)', 'hunter2000')
|
|
|
|
->assertExitCode(0);
|
|
|
|
|
|
|
|
$this->assertDatabaseHas('users', [
|
|
|
|
'email' => 'admintest@example.com',
|
2022-02-01 12:49:30 +01:00
|
|
|
'name' => 'Admin Test',
|
2022-01-31 21:43:41 +01:00
|
|
|
]);
|
|
|
|
$this->assertTrue(Auth::attempt(['email' => 'admintest@example.com', 'password' => 'hunter2000']));
|
|
|
|
}
|
|
|
|
}
|