create(); $token = $user->createToken('Handy')->plainTextToken; $rememberBefore = $user->fresh()->remember_token; $this->actingAs($user)->get('/')->assertOk(); $user->update(['is_active' => false]); $this->get('/neuigkeiten')->assertRedirect('/login'); $this->assertGuest(); $this->assertSame(0, $user->tokens()->count()); $this->assertNotSame($rememberBefore, $user->fresh()->remember_token); $this->app['auth']->forgetGuards(); $this->withToken($token)->getJson('/api/v1/me')->assertUnauthorized(); } public function test_password_reset_is_neutral_and_not_for_sso_only_accounts(): void { Notification::fake(); $local = User::factory()->create(['email' => 'lokal@example.org']); $sso = User::factory()->create(['email' => 'sso@example.org', 'password' => null]); $provider = IdentityProvider::query()->create(['type' => 'entra', 'name' => 'Entra', 'slug' => 'entra', 'enabled' => true, 'config' => []]); UserIdentity::query()->create(['user_id' => $sso->id, 'identity_provider_id' => $provider->id, 'subject' => 'abc']); $unknown = $this->post('/forgot-password', ['email' => 'gibtsnicht@example.org'])->assertSessionHasNoErrors()->assertSessionHas('status')->baseResponse->getSession()->get('status'); $this->post('/forgot-password', ['email' => 'lokal@example.org'])->assertSessionHasNoErrors()->assertSessionHas('status', $unknown); $this->post('/forgot-password', ['email' => 'sso@example.org'])->assertSessionHasNoErrors()->assertSessionHas('status', $unknown); Notification::assertSentTo($local, ResetPassword::class); Notification::assertNotSentTo($sso, ResetPassword::class); } public function test_password_change_revokes_other_sessions_and_tokens(): void { $user = User::factory()->create(['password' => 'alt-Passwort-123']); $user->createToken('Handy'); DB::table('sessions')->insert(['id' => 'fremdes-geraet', 'user_id' => $user->id, 'payload' => '', 'last_activity' => time()]); $this->actingAs($user)->put('/user/password', [ 'current_password' => 'alt-Passwort-123', 'password' => 'Neues-Passwort-456!', 'password_confirmation' => 'Neues-Passwort-456!', ])->assertSessionHasNoErrors(); $this->assertSame(0, $user->tokens()->count()); $this->assertFalse(DB::table('sessions')->where('id', 'fremdes-geraet')->exists()); } public function test_api_token_login_is_limited_per_address(): void { User::factory()->create(['email' => 'ada@example.org', 'password' => 'geheim-123']); foreach (range(1, 5) as $i) { $this->postJson('/api/v1/token', ['email' => 'ada@example.org', 'password' => 'falsch', 'device_name' => 'x'], ['REMOTE_ADDR' => "10.0.0.{$i}"])->assertUnprocessable(); } $this->postJson('/api/v1/token', ['email' => 'ada@example.org', 'password' => 'geheim-123', 'device_name' => 'x'], ['REMOTE_ADDR' => '10.0.0.9']) ->assertUnprocessable()->assertJsonPath('errors.email.0', 'Zu viele Versuche. Bitte in einigen Minuten erneut versuchen.'); } }