Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 7m50s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 7m34s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 5m45s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 5m30s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 7m7s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 7m9s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 6m8s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 6m5s
CI / Bekannte Sicherheitslücken in Paketen (pull_request) Successful in 48s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m5s
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
77 lines
3.6 KiB
PHP
77 lines
3.6 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature\Auth;
|
|
|
|
use App\Models\IdentityProvider;
|
|
use App\Models\User;
|
|
use App\Models\UserIdentity;
|
|
use Illuminate\Auth\Notifications\ResetPassword;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Facades\Notification;
|
|
use Tests\TestCase;
|
|
|
|
class AccountSecurityTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
public function test_deactivated_people_are_logged_out_and_lose_all_access(): void
|
|
{
|
|
$user = User::factory()->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.');
|
|
}
|
|
}
|