E-Mail-Verifizierung (Entscheidung 15.06.): - User implementiert MustVerifyEmail; Registrierung legt inaktives, rollenloses Konto an und leitet auf die Danke-/Notice-Seite; Registered-Event versendet die Verifizierungsmail. Bestätigter Link aktiviert das Konto + vergibt customer-Rolle (ActivateUserAfterVerification). Backfill-Migration setzt email_verified_at für alle Bestands-User (sonst würde die verified-Middleware ~59k aktive Legacy-User aussperren). Seeder-User verifiziert. Auth-Flow-Korrekturen: - Magic-Link-Consume: rollensicherer Redirect ohne intended() (Customer landete sonst per stale intended=/dashboard im 403-Admin-Bereich). - Guest-Redirect (bootstrap/app.php) rollen-/verifizierungsbewusst statt fix /dashboard – schließt die 403-Sackgasse auf /login und /register. - Logout auf der Notice-Seite via echtes POST-Formular statt Livewire-Action (behebt 419 beim Session-Invalidate). - Magic-Link-Anforderung über eigenes Modal mit separater E-Mail-Eingabe. - Unverifizierte Login-Versuche landen auf der Notice-Seite. Sicherheitsfix Legacy-Rollen: - UserImporter mappte Alt-Gruppe 2 (Self-Publisher) auf editor (= Admin-Zugriff). Mapping auf customer korrigiert; Daten-Migration stuft die 65.950 fälschlichen Legacy-Editoren auf customer herab. Echte admin/api-only bleiben unberührt. Tests: Registration, EmailVerification, Authentication (Guest-Redirect), MagicLinkLogin (Modal/Redirect/Regression), Legacy-Import (Gruppen-Mapping). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
54 lines
1.7 KiB
PHP
54 lines
1.7 KiB
PHP
<?php
|
|
|
|
use App\Models\User;
|
|
use Illuminate\Auth\Notifications\VerifyEmail;
|
|
use Illuminate\Support\Facades\Notification;
|
|
use Livewire\Volt\Volt;
|
|
use Tests\TestCase;
|
|
|
|
test('registration screen can be rendered', function () {
|
|
/** @var TestCase $this */
|
|
$response = $this->get('/register');
|
|
|
|
$response->assertStatus(200);
|
|
});
|
|
|
|
test('new users register inactive and are sent to the verification notice', function () {
|
|
/** @var TestCase $this */
|
|
Notification::fake();
|
|
|
|
Volt::test('auth.register')
|
|
->set('name', 'Test User')
|
|
->set('email', 'test@example.com')
|
|
->set('password', 'password')
|
|
->set('password_confirmation', 'password')
|
|
->set('terms_accepted', true)
|
|
->call('register')
|
|
->assertHasNoErrors()
|
|
->assertRedirect(route('verification.notice', absolute: false));
|
|
|
|
$this->assertAuthenticated();
|
|
|
|
$user = User::where('email', 'test@example.com')->firstOrFail();
|
|
|
|
// Konto bleibt bis zur Verifizierung inaktiv, rollenlos und unverifiziert.
|
|
expect($user->is_active)->toBeFalse();
|
|
expect($user->hasVerifiedEmail())->toBeFalse();
|
|
expect($user->roles()->count())->toBe(0);
|
|
|
|
Notification::assertSentTo($user, VerifyEmail::class);
|
|
});
|
|
|
|
test('registration requires accepting the terms', function () {
|
|
/** @var TestCase $this */
|
|
Volt::test('auth.register')
|
|
->set('name', 'Test User')
|
|
->set('email', 'terms@example.com')
|
|
->set('password', 'password')
|
|
->set('password_confirmation', 'password')
|
|
->set('terms_accepted', false)
|
|
->call('register')
|
|
->assertHasErrors(['terms_accepted']);
|
|
|
|
expect(User::where('email', 'terms@example.com')->exists())->toBeFalse();
|
|
});
|