The console under console/ has its own session cookie and console guard (UseConsoleSession), so signing out or changing user there leaves the normal interface alone. Links open it in a new window through a one-time handoff key; a signed-out console asks for a PIN code or password on its own login page. Users set their 4-6 digit PIN on the profile's PIN page, and the console's change user dialog takes it on a keypad; five wrong PINs lock PIN sign-in for 15 minutes. Machine counters are cumulative: users record how much a job used and it is added to the latest reading. A maintenance record restarts the whole counter interval from the reading at the record. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
61 lines
1.9 KiB
PHP
61 lines
1.9 KiB
PHP
<?php
|
|
|
|
use App\Models\User;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Illuminate\Support\Facades\Hash;
|
|
use Livewire\Livewire;
|
|
|
|
uses(RefreshDatabase::class);
|
|
|
|
beforeEach(function () {
|
|
$this->user = User::factory()->employee()->create(['password' => 'Salasana-123!']);
|
|
$this->actingAs($this->user);
|
|
});
|
|
|
|
it('sets the console PIN code with the user\'s password and stores only its hash', function () {
|
|
$this->get(route('profile.pin'))->assertOk()->assertSee(__('users.pin.not_set'));
|
|
|
|
Livewire::test('users::pin')
|
|
->set('currentPassword', 'väärä')
|
|
->set('pin', '2468')
|
|
->set('pinConfirmation', '2468')
|
|
->call('save')
|
|
->assertHasErrors('currentPassword')
|
|
->set('currentPassword', 'Salasana-123!')
|
|
->set('pin', '24a8')
|
|
->set('pinConfirmation', '24a8')
|
|
->call('save')
|
|
->assertHasErrors('pin')
|
|
->set('pin', '2468')
|
|
->set('pinConfirmation', '2469')
|
|
->call('save')
|
|
->assertHasErrors('pinConfirmation')
|
|
->set('pinConfirmation', '2468')
|
|
->call('save')
|
|
->assertHasNoErrors()
|
|
->assertSet('message', __('users.pin.saved'));
|
|
|
|
$hash = $this->user->fresh()->pin_hash;
|
|
|
|
expect($hash)->not->toBe('2468')
|
|
->and(Hash::check('2468', $hash))->toBeTrue()
|
|
->and($this->user->fresh()->toArray())->not->toHaveKey('pin_hash');
|
|
});
|
|
|
|
it('removes the PIN code with the user\'s password', function () {
|
|
$this->user->forceFill(['pin_hash' => Hash::make('2468')])->save();
|
|
|
|
Livewire::test('users::pin')
|
|
->set('currentPassword', 'Salasana-123!')
|
|
->call('remove')
|
|
->assertSet('message', __('users.pin.removed'));
|
|
|
|
expect($this->user->fresh()->pin_hash)->toBeNull();
|
|
});
|
|
|
|
it('is not offered to subcontractors', function () {
|
|
$this->actingAs(User::factory()->subcontractor()->create());
|
|
|
|
$this->get(route('profile.pin'))->assertForbidden();
|
|
});
|