Files
fewo-stommer/tests/Feature/TwoFactorAuthenticationTest.php
Lars StommerandClaude Opus 5.5 4f69b426a4 Booking path 1 (offer + guest acceptance), 2FA for all, privacy hardening, brand graphics in theme
- Offer workflow: "Angebot senden" in the admin (dates, guests, promo code, manual price adjustment,
  validity from the property's hold time, message, guest data for the contract) with live price;
  contract draft PDF; signed, versioned offer page for the guest to accept (acceptance record without
  IP) or decline; expiry job, landlord notifications, editable offer texts, wording on the website.
- 2FA is mandatory for every admin account.
- Privacy: complete anonymisation (notes, attribution, review names, offer messages), shorter
  periods for unbinding requests, portal mail excerpts and attribution (configurable proposals),
  iCal summary not stored, known e-mail no longer overwrites guest data, security headers, bearer
  tokens for automations, metadata stripped from photo originals, review link throttled.
- Daily database backup (backup:database) and scripts/backup-pull.sh for the NAS.
- Theme: brand mark in header/footer, favicon/touch icon, wave divider, icons, illustration as
  image placeholder; navy follows the text colour for dark appearances.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-22 21:38:22 +02:00

74 lines
2.7 KiB
PHP

<?php
namespace Tests\Feature;
use App\Enums\UserRole;
use App\Filament\Resources\Bookings\BookingResource;
use App\Models\User;
use Filament\Facades\Filament;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Hash;
use Tests\TestCase;
class TwoFactorAuthenticationTest extends TestCase
{
use RefreshDatabase;
public function test_admin_without_two_factor_must_set_it_up_first(): void
{
$this->actingAs(User::factory()->withoutTwoFactor()->create());
$setUpUrl = Filament::getPanel('admin')->getSetUpRequiredMultiFactorAuthenticationUrl();
$this->get(BookingResource::getUrl('index'))->assertRedirect($setUpUrl);
$this->get($setUpUrl)->assertOk()->assertSee('Authenticator', false);
}
public function test_admin_with_two_factor_enters_the_admin(): void
{
$this->actingAs(User::factory()->create());
$this->get(BookingResource::getUrl('index'))->assertOk();
}
public function test_every_role_must_set_up_two_factor(): void
{
$this->actingAs(User::factory()->role(UserRole::Rentals)->withoutTwoFactor()->create());
$this->get(BookingResource::getUrl('index'))
->assertRedirect(Filament::getPanel('admin')->getSetUpRequiredMultiFactorAuthenticationUrl());
}
public function test_two_factor_secret_is_stored_encrypted(): void
{
$user = User::factory()->create();
$this->assertNotSame('JBSWY3DPEHPK3PXP', $user->getRawOriginal('app_authentication_secret'));
$this->assertSame('JBSWY3DPEHPK3PXP', $user->fresh()->getAppAuthenticationSecret());
}
public function test_command_creates_an_admin_with_interactively_entered_password(): void
{
$this->artisan('users:create', ['email' => 'Lars@Example.com', '--name' => 'Lars', '--role' => 'admin'])
->expectsQuestion('Passwort (mind. 12 Zeichen)', 'ein-sicheres-passwort')
->expectsQuestion('Passwort wiederholen', 'ein-sicheres-passwort')
->assertSuccessful();
$user = User::firstWhere('email', 'lars@example.com');
$this->assertSame(UserRole::Admin, $user->role);
$this->assertTrue(Hash::check('ein-sicheres-passwort', $user->password));
$this->assertNull($user->getAppAuthenticationSecret());
}
public function test_command_rejects_mismatching_passwords(): void
{
$this->artisan('users:create', ['email' => 'lars@example.com', '--name' => 'Lars', '--role' => 'admin'])
->expectsQuestion('Passwort (mind. 12 Zeichen)', 'ein-sicheres-passwort')
->expectsQuestion('Passwort wiederholen', 'etwas-anderes-passwort')
->assertFailed();
$this->assertDatabaseCount('users', 0);
}
}