93 lines
3.2 KiB
PHP
93 lines
3.2 KiB
PHP
<?php
|
|
|
|
use App\Livewire\Auth\OperatorLogin;
|
|
use App\Models\Operator;
|
|
use App\Models\User;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Livewire\Livewire;
|
|
|
|
it('offers no way to register — an operator account is not self-served', function () {
|
|
$this->get(route('admin.login'))->assertOk()
|
|
->assertDontSee(route('register'))
|
|
->assertDontSee(__('auth.sign_up'));
|
|
});
|
|
|
|
it('signs an operator in on the operator guard', function () {
|
|
$operator = Operator::factory()->role('Owner')->create(['password' => 'richtig-langes-pw']);
|
|
|
|
Livewire::test(OperatorLogin::class)
|
|
->set('email', $operator->email)
|
|
->set('password', 'richtig-langes-pw')
|
|
->call('authenticate')
|
|
->assertRedirect(App\Support\AdminArea::home());
|
|
|
|
expect(Auth::guard('operator')->check())->toBeTrue()
|
|
->and(Auth::guard('web')->check())->toBeFalse();
|
|
});
|
|
|
|
it('refuses a portal account at the console door', function () {
|
|
$user = User::factory()->create(['email' => 'kunde@clupilot.test', 'password' => 'kunden-passwort']);
|
|
|
|
Livewire::test(OperatorLogin::class)
|
|
->set('email', 'kunde@clupilot.test')
|
|
->set('password', 'kunden-passwort')
|
|
->call('authenticate')
|
|
->assertHasErrors('email');
|
|
|
|
expect(Auth::guard('operator')->check())->toBeFalse();
|
|
});
|
|
|
|
it('refuses a disabled operator', function () {
|
|
$operator = Operator::factory()->role('Owner')->create([
|
|
'password' => 'richtig-langes-pw', 'disabled_at' => now(),
|
|
]);
|
|
|
|
Livewire::test(OperatorLogin::class)
|
|
->set('email', $operator->email)
|
|
->set('password', 'richtig-langes-pw')
|
|
->call('authenticate')
|
|
->assertHasErrors('email');
|
|
|
|
expect(Auth::guard('operator')->check())->toBeFalse();
|
|
});
|
|
|
|
it('sends an operator with confirmed two-factor to the challenge instead of the console', function () {
|
|
$operator = Operator::factory()->role('Owner')->create([
|
|
'password' => 'richtig-langes-pw',
|
|
'two_factor_secret' => encrypt('JBSWY3DPEHPK3PXP'),
|
|
'two_factor_confirmed_at' => now(),
|
|
]);
|
|
|
|
Livewire::test(OperatorLogin::class)
|
|
->set('email', $operator->email)
|
|
->set('password', 'richtig-langes-pw')
|
|
->call('authenticate')
|
|
->assertRedirect(route('admin.two-factor'));
|
|
|
|
// Not signed in yet — the challenge is not decoration.
|
|
expect(Auth::guard('operator')->check())->toBeFalse();
|
|
});
|
|
|
|
it('throttles repeated failures', function () {
|
|
$operator = Operator::factory()->role('Owner')->create(['password' => 'richtig-langes-pw']);
|
|
|
|
$component = Livewire::test(OperatorLogin::class)->set('email', $operator->email)->set('password', 'falsch');
|
|
|
|
foreach (range(1, 5) as $ignored) {
|
|
$component->call('authenticate');
|
|
}
|
|
|
|
$component->call('authenticate')->assertHasErrors('email');
|
|
expect(session()->has('login.id'))->toBeFalse();
|
|
});
|
|
|
|
it('records when the operator last signed in', function () {
|
|
$operator = Operator::factory()->role('Owner')->create(['password' => 'richtig-langes-pw']);
|
|
|
|
Livewire::test(OperatorLogin::class)
|
|
->set('email', $operator->email)->set('password', 'richtig-langes-pw')
|
|
->call('authenticate');
|
|
|
|
expect($operator->fresh()->last_login_at)->not->toBeNull();
|
|
});
|