Benenne den Authenticator und merke denselben Browser für 30 Tage.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
cd79fb99d7
commit
b374335b3a
10 files changed
+241
-4
No files matched your search
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Auth\StaffAuthenticatorName;
|
||||
use App\Auth\TrustedStaffDevice;
|
||||
use App\Domain\Identity\AccountStatus;
|
||||
use App\Domain\Identity\StaffRole;
|
||||
use App\Filament\Auth\TrustedDeviceChallenge;
|
||||
use App\Filament\Resources\Users\UserResource;
|
||||
use App\Models\User;
|
||||
use Filament\Auth\MultiFactor\App\AppAuthentication;
|
||||
use Filament\Facades\Filament;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Tests\TestCase;
|
||||
|
||||
class StaffAuthenticationTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_authenticator_name_distinguishes_production_from_development(): void
|
||||
{
|
||||
$this->assertSame('Lara&Felix (dev)', StaffAuthenticatorName::current());
|
||||
|
||||
$provider = Filament::getPanel('verwaltung')->getMultiFactorAuthenticationProviders()['app'] ?? null;
|
||||
$this->assertInstanceOf(AppAuthentication::class, $provider);
|
||||
$this->assertSame('Lara&Felix (dev)', $provider->getBrandName());
|
||||
|
||||
$this->app['env'] = 'production';
|
||||
|
||||
$this->assertSame('Lara&Felix', StaffAuthenticatorName::current());
|
||||
}
|
||||
|
||||
public function test_a_trusted_device_skips_the_code_until_the_secret_changes(): void
|
||||
{
|
||||
$user = User::factory()->systemverwalter()->create();
|
||||
$user->saveAppAuthenticationSecret('JBSWY3DPEHPK3PXP');
|
||||
$device = app(TrustedStaffDevice::class);
|
||||
$request = Request::create('/verwaltung/login', 'POST', cookies: [
|
||||
TrustedStaffDevice::COOKIE => $device->token($user),
|
||||
]);
|
||||
$this->app->instance('request', $request);
|
||||
|
||||
$this->assertTrue($device->isTrusted($user, $request));
|
||||
$this->assertNull(TrustedDeviceChallenge::make()->getFirstEnabledProvider($user));
|
||||
|
||||
$user->saveAppAuthenticationSecret('KRSXG5CTMVRXEZLU');
|
||||
|
||||
$this->assertFalse($device->isTrusted($user, $request));
|
||||
$this->assertInstanceOf(AppAuthentication::class, TrustedDeviceChallenge::make()->getFirstEnabledProvider($user));
|
||||
}
|
||||
|
||||
public function test_changing_the_own_password_keeps_the_staff_session_hash(): void
|
||||
{
|
||||
$admin = User::factory()->systemverwalter()->create();
|
||||
$this->actingAs($admin, 'staff');
|
||||
session()->put(['password_hash_staff' => $admin->getAuthPassword()]);
|
||||
|
||||
UserResource::persist($admin, [
|
||||
'name' => $admin->name,
|
||||
'email' => $admin->email,
|
||||
'password' => 'neues-passwort-1',
|
||||
'status' => AccountStatus::Aktiv->value,
|
||||
'roles' => [StaffRole::Systemverwalter->value],
|
||||
], false);
|
||||
|
||||
$admin->refresh();
|
||||
|
||||
$this->assertTrue(Hash::check('neues-passwort-1', $admin->password));
|
||||
$this->assertSame($admin->getAuthPassword(), session('password_hash_staff'));
|
||||
$this->assertAuthenticatedAs($admin, 'staff');
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user