Add structured specification and show set-password links to admins
The customer answered the open questions in määrittely.txt. Collect the answers into docs/maarittely.md: roles and permission table, money visibility, customer job fields and enum keys, Kanban, tasks, time entries, expenses, pricing, Fennoa billing export, data model, revised phases with phase 1 in detail, and remaining open questions. CLAUDE.md now points to it. Apply the answers that change the Users module: - Passwords need 12+ characters with mixed case, a number and a symbol, with a Finnish message for each rule. - When an admin creates a user or asks for a new link, the set-password link is emailed and also shown to the admin to copy, even if the email fails. The link lives only in the page state. users:create-admin prints it too. Self-service "forgot password" stays as it was. - The copy field uses x-input + x-button with a status message, because x-clipboard has an unlabelled input and a changing button name. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
@@ -54,6 +54,18 @@ it('has no accessibility issues on the user admin pages', function (string $page
|
||||
->assertNoAccessibilityIssues(level: 2);
|
||||
})->with(['list', 'create', 'edit intern'])->with($devicesAndSchemes);
|
||||
|
||||
it('shows a new set-password link to copy without accessibility issues', function (string $device, string $colorScheme) {
|
||||
$this->actingAs(User::factory()->admin()->create());
|
||||
$user = User::factory()->create();
|
||||
|
||||
onDeviceAndScheme(visit(route('users.edit', $user->id)), $device, $colorScheme)
|
||||
->press('Luo salasanan asetuslinkki')
|
||||
->assertSee('Uusi linkki luotu')
|
||||
->assertSourceHas('/reset-password/')
|
||||
->assertNoJavaScriptErrors()
|
||||
->assertNoAccessibilityIssues(level: 2);
|
||||
})->with($devicesAndSchemes);
|
||||
|
||||
it('shows a login error without accessibility issues', function (string $colorScheme) {
|
||||
$page = onDeviceAndScheme(visit(route('login')), 'desktop', $colorScheme);
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace Tests\Fakes;
|
||||
|
||||
use App\Modules\Users\Application\Contracts\PasswordLinkSender;
|
||||
use App\Modules\Users\Application\DTOs\IssuedSetupLink;
|
||||
use App\Modules\Users\Domain\ValueObjects\EmailAddress;
|
||||
|
||||
class FakePasswordLinkSender implements PasswordLinkSender
|
||||
@@ -18,4 +19,11 @@ class FakePasswordLinkSender implements PasswordLinkSender
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function issueSetupLink(EmailAddress $email): IssuedSetupLink
|
||||
{
|
||||
$this->sentTo[] = $email->value;
|
||||
|
||||
return new IssuedSetupLink('https://example.test/reset-password/token?email='.urlencode($email->value), true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,10 +8,11 @@ use Illuminate\Support\Facades\Notification;
|
||||
|
||||
uses(RefreshDatabase::class);
|
||||
|
||||
it('creates an admin and emails a set-password link', function () {
|
||||
it('creates an admin, emails a set-password link and prints it', function () {
|
||||
Notification::fake();
|
||||
|
||||
$this->artisan('users:create-admin', ['name' => 'Anna Admin', 'email' => '[email protected]'])
|
||||
->expectsOutputToContain('/reset-password/')
|
||||
->assertSuccessful();
|
||||
|
||||
$admin = User::query()->sole();
|
||||
|
||||
@@ -20,17 +20,17 @@ beforeEach(function () {
|
||||
Exceptions::fake();
|
||||
});
|
||||
|
||||
it('creates the user and asks for a resend when the email cannot be sent', function () {
|
||||
Livewire::actingAs(User::factory()->admin()->create())
|
||||
it('creates the user and shows the link to copy when the email cannot be sent', function () {
|
||||
$component = Livewire::actingAs(User::factory()->admin()->create())
|
||||
->test('users::form')
|
||||
->set('form.name', 'Maija Meikäläinen')
|
||||
->set('form.email', '[email protected]')
|
||||
->call('save')
|
||||
->assertHasNoErrors()
|
||||
->assertRedirect(route('users.index'));
|
||||
->assertSee('linkin lähetys sähköpostiin epäonnistui');
|
||||
|
||||
expect(User::query()->where('email', '[email protected]')->exists())->toBeTrue()
|
||||
->and(session('status'))->toContain('salasanan asetuslinkin lähetys epäonnistui');
|
||||
->and($component->get('setupLink'))->toContain('/reset-password/');
|
||||
|
||||
Exceptions::assertReported(TransportException::class);
|
||||
});
|
||||
@@ -41,12 +41,14 @@ it('tells the admin when a resend fails', function () {
|
||||
Livewire::actingAs(User::factory()->admin()->create())
|
||||
->test('users::form', ['user' => $user->id])
|
||||
->call('sendPasswordLink')
|
||||
->assertSee('Linkkiä ei voitu lähettää');
|
||||
->assertSee('Uusi linkki luotu, mutta sen lähetys sähköpostiin epäonnistui.')
|
||||
->assertSee('/reset-password/');
|
||||
});
|
||||
|
||||
it('still creates the first admin from the command', function () {
|
||||
$this->artisan('users:create-admin', ['name' => 'Anna Admin', 'email' => '[email protected]'])
|
||||
->expectsOutputToContain('could not be sent')
|
||||
->expectsOutputToContain('/reset-password/')
|
||||
->assertSuccessful();
|
||||
|
||||
expect(User::query()->where('email', '[email protected]')->exists())->toBeTrue();
|
||||
|
||||
@@ -79,15 +79,33 @@ it('sets a new password with a valid link', function () {
|
||||
|
||||
Livewire::test('users::reset-password', ['token' => $token])
|
||||
->set('email', '[email protected]')
|
||||
->set('password', 'uusi-salasana-123')
|
||||
->set('password_confirmation', 'uusi-salasana-123')
|
||||
->set('password', 'Uusi-salasana-123')
|
||||
->set('password_confirmation', 'Uusi-salasana-123')
|
||||
->call('resetPassword')
|
||||
->assertHasNoErrors()
|
||||
->assertRedirect(route('login'));
|
||||
|
||||
expect(Hash::check('uusi-salasana-123', $user->fresh()->password))->toBeTrue();
|
||||
expect(Hash::check('Uusi-salasana-123', $user->fresh()->password))->toBeTrue();
|
||||
});
|
||||
|
||||
it('rejects a password that breaks a rule', function (string $password, string $message) {
|
||||
$user = User::factory()->create(['email' => '[email protected]']);
|
||||
|
||||
Livewire::test('users::reset-password', ['token' => Password::createToken($user)])
|
||||
->set('email', '[email protected]')
|
||||
->set('password', $password)
|
||||
->set('password_confirmation', $password)
|
||||
->call('resetPassword')
|
||||
->assertHasErrors(['password'])
|
||||
->assertSee($message);
|
||||
|
||||
expect(Hash::check('password', $user->fresh()->password))->toBeTrue();
|
||||
})->with([
|
||||
'no upper case' => ['uusi-salasana-123', 'sekä isoja että pieniä kirjaimia'],
|
||||
'no number' => ['Uusi-salasana-abc', 'vähintään yksi numero'],
|
||||
'no symbol' => ['Uusisalasana123', 'vähintään yksi erikoismerkki'],
|
||||
]);
|
||||
|
||||
it('rejects a short password and an invalid link', function () {
|
||||
$user = User::factory()->create(['email' => '[email protected]']);
|
||||
|
||||
@@ -97,8 +115,8 @@ it('rejects a short password and an invalid link', function () {
|
||||
->set('password_confirmation', 'lyhyt')
|
||||
->call('resetPassword')
|
||||
->assertHasErrors(['password'])
|
||||
->set('password', 'uusi-salasana-123')
|
||||
->set('password_confirmation', 'uusi-salasana-123')
|
||||
->set('password', 'Uusi-salasana-123')
|
||||
->set('password_confirmation', 'Uusi-salasana-123')
|
||||
->call('resetPassword')
|
||||
->assertHasErrors(['email'])
|
||||
->assertSee('Linkki on vanhentunut tai virheellinen.');
|
||||
|
||||
@@ -5,6 +5,8 @@ use App\Modules\Users\Domain\Enums\Role;
|
||||
use Illuminate\Auth\Notifications\ResetPassword;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Notification;
|
||||
use Illuminate\Support\Facades\Password;
|
||||
use Illuminate\Support\Str;
|
||||
use Livewire\Features\SupportLockedProperties\CannotUpdateLockedPropertyException;
|
||||
use Livewire\Livewire;
|
||||
|
||||
@@ -42,10 +44,10 @@ it('lists users with their role and status', function () {
|
||||
->assertSee('Ei käytössä');
|
||||
});
|
||||
|
||||
it('creates an intern and emails a set-password link', function () {
|
||||
it('creates an intern, emails a set-password link and shows it to copy', function () {
|
||||
$supervisor = User::factory()->create();
|
||||
|
||||
Livewire::actingAs($this->admin)
|
||||
$component = Livewire::actingAs($this->admin)
|
||||
->test('users::form')
|
||||
->set('form.name', 'Ida Harjoittelija')
|
||||
->set('form.email', '[email protected]')
|
||||
@@ -54,15 +56,21 @@ it('creates an intern and emails a set-password link', function () {
|
||||
->set('form.supervisor_id', (string) $supervisor->id)
|
||||
->call('save')
|
||||
->assertHasNoErrors()
|
||||
->assertRedirect(route('users.index'));
|
||||
->assertNoRedirect()
|
||||
->assertSee('Käyttäjä Ida Harjoittelija lisätty.')
|
||||
->assertSee('Salasanan asetuslinkki');
|
||||
|
||||
$intern = User::query()->where('email', '[email protected]')->sole();
|
||||
|
||||
expect($component->get('userId'))->toBe($intern->id);
|
||||
|
||||
expect($intern->role)->toBe(Role::Intern)
|
||||
->and($intern->employment_ends_on?->toDateString())->toBe('2027-05-31')
|
||||
->and($intern->supervisor_id)->toBe($supervisor->id);
|
||||
|
||||
Notification::assertSentTo($intern, ResetPassword::class);
|
||||
Notification::assertSentTo($intern, ResetPassword::class, function (ResetPassword $notification) use ($component) {
|
||||
return str_contains($component->get('setupLink'), '/reset-password/'.$notification->token);
|
||||
});
|
||||
});
|
||||
|
||||
it('requires an end date and a supervisor for an intern', function () {
|
||||
@@ -135,17 +143,27 @@ it('does not let the last admin deactivate themselves', function () {
|
||||
expect($this->admin->fresh()->is_active)->toBeTrue();
|
||||
});
|
||||
|
||||
it('sends a set-password link from the edit page', function () {
|
||||
it('makes a new set-password link on the edit page, also right after an earlier one', function () {
|
||||
$user = User::factory()->create(['email' => '[email protected]']);
|
||||
|
||||
Livewire::actingAs($this->admin)
|
||||
$component = Livewire::actingAs($this->admin)
|
||||
->test('users::form', ['user' => $user->id])
|
||||
->call('sendPasswordLink')
|
||||
->assertSee('Lähetimme linkin salasanan asettamiseen osoitteeseen [email protected].');
|
||||
->call('sendPasswordLink')
|
||||
->assertSee('Uusi linkki luotu ja lähetetty osoitteeseen [email protected].');
|
||||
|
||||
Notification::assertSentTo($user, ResetPassword::class);
|
||||
$token = Str::between($component->get('setupLink'), '/reset-password/', '?');
|
||||
|
||||
Notification::assertSentToTimes($user, ResetPassword::class, 2);
|
||||
expect(Password::tokenExists($user, $token))->toBeTrue();
|
||||
});
|
||||
|
||||
it('does not let the set-password link be changed in the browser', function () {
|
||||
Livewire::actingAs($this->admin)
|
||||
->test('users::form')
|
||||
->set('setupLink', 'https://evil.example/');
|
||||
})->throws(CannotUpdateLockedPropertyException::class);
|
||||
|
||||
it('does not let the user id be changed in the browser', function () {
|
||||
Livewire::actingAs($this->admin)
|
||||
->test('users::form')
|
||||
|
||||
@@ -33,11 +33,12 @@ beforeEach(function () {
|
||||
$this->employeeId = $this->users->save(UserAccount::register(new PersonName('Eero Työntekijä'), new EmailAddress('[email protected]'), Role::Employee))->id();
|
||||
});
|
||||
|
||||
it('creates a user and sends a link for setting the password', function () {
|
||||
$userId = $this->createUser->execute(new UserAccountData('Maija Meikäläinen', '[email protected]', Role::Employee))->userId;
|
||||
it('creates a user and returns the emailed link for setting the password', function () {
|
||||
$created = $this->createUser->execute(new UserAccountData('Maija Meikäläinen', '[email protected]', Role::Employee));
|
||||
|
||||
expect($this->users->findById($userId)?->email()->value)->toBe('[email protected]')
|
||||
->and($this->passwordLinks->sentTo)->toBe(['[email protected]']);
|
||||
expect($this->users->findById($created->userId)?->email()->value)->toBe('[email protected]')
|
||||
->and($this->passwordLinks->sentTo)->toBe(['[email protected]'])
|
||||
->and($created->setupLink->url)->toContain('maija%40example.test');
|
||||
});
|
||||
|
||||
it('creates an intern with an end date and a supervisor', function () {
|
||||
@@ -103,9 +104,10 @@ it('fails to update an unknown user', function () {
|
||||
})->throws(UserAccountNotFound::class);
|
||||
|
||||
it('sends a password link to a stored user', function () {
|
||||
(new SendPasswordSetupLink($this->users, $this->passwordLinks))->execute($this->employeeId);
|
||||
$link = (new SendPasswordSetupLink($this->users, $this->passwordLinks))->execute($this->employeeId);
|
||||
|
||||
expect($this->passwordLinks->sentTo)->toBe(['[email protected]']);
|
||||
expect($this->passwordLinks->sentTo)->toBe(['[email protected]'])
|
||||
->and($link->url)->toContain('eero%40example.test');
|
||||
});
|
||||
|
||||
it('checks whether a user may log in today', function () {
|
||||
|
||||
Reference in New Issue
Block a user