- 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>
140 lines
5.9 KiB
PHP
140 lines
5.9 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature;
|
|
|
|
use App\Actions\AnonymizeGuests;
|
|
use App\Actions\CreateReservation;
|
|
use App\Enums\BookingStatus;
|
|
use App\Enums\PortalEmailStatus;
|
|
use App\Enums\PortalEmailType;
|
|
use App\Models\Booking;
|
|
use App\Models\Channel;
|
|
use App\Models\Guest;
|
|
use App\Models\Photo;
|
|
use App\Models\PortalEmail;
|
|
use App\Models\Property;
|
|
use App\Models\Review;
|
|
use App\Pricing\StayRequest;
|
|
use Carbon\CarbonImmutable;
|
|
use Database\Seeders\PropertySeeder;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Illuminate\Http\UploadedFile;
|
|
use Illuminate\Support\Facades\Mail;
|
|
use Illuminate\Support\Facades\Storage;
|
|
use Tests\TestCase;
|
|
|
|
class PrivacyHardeningTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
|
|
$this->travelTo(CarbonImmutable::parse('2026-10-22 10:00'));
|
|
Mail::fake();
|
|
}
|
|
|
|
public function test_anonymisation_also_removes_notes_attribution_and_review_details(): void
|
|
{
|
|
$booking = Booking::factory()->create(['internal_notes' => 'ruft abends an', 'utm_source' => 'newsletter', 'offer_message' => 'Hallo Frau Muster']);
|
|
$review = Review::factory()->create(['booking_id' => $booking->id, 'display_name' => 'Erika M.', 'private_feedback' => 'Nachbar laut']);
|
|
|
|
$booking->guest->anonymize();
|
|
|
|
$booking->refresh();
|
|
$this->assertSame([null, null, null], [$booking->internal_notes, $booking->utm_source, $booking->offer_message]);
|
|
$this->assertSame(['Gast', null], [$review->fresh()->display_name, $review->fresh()->private_feedback]);
|
|
}
|
|
|
|
public function test_guests_with_only_unbinding_requests_are_anonymised_after_the_inquiry_period(): void
|
|
{
|
|
$inquiry = Booking::factory()->create(['status' => BookingStatus::Expired, 'confirmed_at' => null]);
|
|
$customer = Booking::factory()->create(['status' => BookingStatus::Completed, 'confirmed_at' => now()]);
|
|
Guest::query()->update(['updated_at' => now()]);
|
|
Booking::query()->update(['updated_at' => now()]);
|
|
|
|
$this->travel(7)->months();
|
|
app(AnonymizeGuests::class)->handle();
|
|
|
|
$this->assertNotNull($inquiry->guest->fresh()->anonymized_at);
|
|
$this->assertNull($customer->guest->fresh()->anonymized_at);
|
|
}
|
|
|
|
public function test_portal_mail_excerpts_and_old_attribution_are_removed_after_their_periods(): void
|
|
{
|
|
$mail = PortalEmail::query()->create(['channel_id' => Channel::factory()->create()->id, 'message_id' => 'x@portal', 'from' => 'noreply@portal.example', 'subject' => 'Neue Buchung', 'received_at' => now(), 'type' => PortalEmailType::Booking, 'status' => PortalEmailStatus::Blocked, 'excerpt' => 'Gast: Erika Musterfrau']);
|
|
$booking = Booking::factory()->create(['utm_source' => 'instagram', 'referral_source' => null]);
|
|
|
|
$this->travel(100)->days();
|
|
app(AnonymizeGuests::class)->handle();
|
|
$this->assertNull($mail->fresh()->excerpt);
|
|
$this->assertSame('instagram', $booking->fresh()->utm_source);
|
|
|
|
$this->travel(2)->years();
|
|
app(AnonymizeGuests::class)->handle();
|
|
$this->assertNull($booking->fresh()->utm_source);
|
|
}
|
|
|
|
public function test_request_with_a_known_email_does_not_overwrite_the_guest_file(): void
|
|
{
|
|
$this->seed(PropertySeeder::class);
|
|
$guest = Guest::factory()->create(['email' => 'erika@example.com', 'first_name' => 'Erika', 'last_name' => 'Muster', 'city' => 'Rostock', 'phone' => null]);
|
|
|
|
$booking = app(CreateReservation::class)->handle(
|
|
Property::sole(),
|
|
new StayRequest(CarbonImmutable::parse('2026-11-07'), CarbonImmutable::parse('2026-11-10'), 2),
|
|
['first_name' => 'Erika', 'last_name' => 'Muster', 'email' => 'Erika@Example.com', 'city' => 'Berlin', 'phone' => '0170 1'],
|
|
sendMails: false,
|
|
);
|
|
|
|
$guest->refresh();
|
|
$this->assertSame($guest->id, $booking->guest_id);
|
|
$this->assertSame(['Rostock', '0170 1'], [$guest->city, $guest->phone], 'existing data stays, empty fields are completed');
|
|
$this->assertStringContainsString('Ort: Berlin (Kartei: Rostock)', $booking->internal_notes);
|
|
}
|
|
|
|
public function test_automation_tokens_are_accepted_as_bearer_header(): void
|
|
{
|
|
config(['fewo.scheduler_token' => 'geheim']);
|
|
|
|
$this->get('/automation/scheduler', ['Authorization' => 'Bearer geheim'])->assertOk();
|
|
$this->get('/automation/scheduler', ['Authorization' => 'Bearer falsch'])->assertNotFound();
|
|
}
|
|
|
|
public function test_responses_carry_security_headers(): void
|
|
{
|
|
$this->get('/up')
|
|
->assertHeader('X-Content-Type-Options', 'nosniff')
|
|
->assertHeader('X-Frame-Options', 'SAMEORIGIN')
|
|
->assertHeader('Referrer-Policy', 'strict-origin-when-cross-origin');
|
|
}
|
|
|
|
public function test_uploaded_photo_originals_are_stripped_of_metadata(): void
|
|
{
|
|
Storage::fake('public');
|
|
$photo = Photo::factory()->create();
|
|
|
|
$media = $photo->addMedia(UploadedFile::fake()->image('drohne.jpg', 1200, 800))->toMediaCollection(Photo::COLLECTION);
|
|
|
|
$this->assertTrue($media->fresh()->getCustomProperty('metadata_stripped'));
|
|
$this->artisan('photos:strip-metadata')->expectsOutputToContain('0 Original-Foto(s) bereinigt.')->assertSuccessful();
|
|
}
|
|
|
|
public function test_database_backup_is_written_and_rotated(): void
|
|
{
|
|
Storage::fake('local');
|
|
Guest::factory()->create(['last_name' => "O'Brien"]);
|
|
|
|
$this->artisan('backup:database', ['--keep' => 1])->assertSuccessful();
|
|
$this->travel(1)->minutes();
|
|
$this->artisan('backup:database', ['--keep' => 1])->assertSuccessful();
|
|
|
|
$files = Storage::disk('local')->files('backups');
|
|
$this->assertCount(1, $files);
|
|
$dump = gzdecode(Storage::disk('local')->get($files[0]));
|
|
$this->assertStringContainsString('CREATE TABLE "guests"', $dump);
|
|
$this->assertStringContainsString("O''Brien", $dump);
|
|
}
|
|
}
|