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('stops checking the password after 5 wrong ones a minute', function () { $component = Livewire::test('users::pin'); foreach (range(1, 5) as $attempt) { $component->set('currentPassword', 'väärä')->call('remove')->assertHasErrors(['currentPassword' => __('users.pin.errors.password')]); } $this->user->forceFill(['pin_hash' => Hash::make('2468')])->save(); $component->set('currentPassword', 'Salasana-123!') ->call('remove') ->assertHasErrors('currentPassword') ->assertSet('message', ''); expect($this->user->fresh()->pin_hash)->not->toBeNull(); $this->travel(61)->seconds(); $component->set('currentPassword', 'Salasana-123!') ->call('remove') ->assertSet('message', __('users.pin.removed')); }); it('is not offered to subcontractors', function () { $this->actingAs(User::factory()->subcontractor()->create()); $this->get(route('profile.pin'))->assertForbidden(); });