Ein neu angelegter Mandant war eine Sackgasse. Er bekam keine Website, also keinen Host, also keine Adresse – und der Host wird im Mandanten-Admin eingetragen, den er ohne Adresse nicht erreicht. „Im Admin öffnen" half nicht: ohne Domain landete es beim Mandanten des aktuellen Hosts. Einsprungsadressen gehören jetzt dem Betreiber, weil Webspace und Hosting ihm gehören und ein Mandant nicht die Adresse eines anderen auf sich zeigen lassen darf. Im Mandanten-Formular: Websites mit ihren Adressen. Beim Anlegen entstehen Website, Host-Einträge und eine leere Startseite – ohne Startseite antwortet die Website mit 404. Im Mandanten-Admin sind die Adressen nur noch sichtbar, nicht änderbar. Die Domain beim Hoster auf das Verzeichnis zu legen bleibt ein Schritt von Hand. Gesperrter Mandant: statt 404 ein Hinweis mit Status 503, Text je Mandant einstellbar. 503 hält die Seiten im Suchindex, weil die Sperre vorübergehend ist. Behoben: `URL::forceRootUrl(APP_URL)` zwang **alle** Links auf einen festen Host. Mit einem Mandanten unsichtbar; mit zwei Domains hätte jeder interne Link der zweiten Website auf die erste gezeigt. Der Ursprung ist jetzt der Host der aufgelösten Website. Neu: systemweite Einstellungen sind im Betreiber-Bereich änderbar (Löschfristen, Bot-Schutz, Flutgrenze, Sicherungen, Portal-Fristen, Versandweg, SMTP, harte Mail-Umleitung, Tokens). Leer heißt: der Wert der .env gilt wieder – und zwar sofort, nicht erst beim nächsten Start. Geheimnisse liegen verschlüsselt. Datenbank-Zugang und APP_KEY bleiben in der .env, weil sie gebraucht werden, um die Datenbank zu öffnen und das Gespeicherte zu entschlüsseln. 253 Feature-Tests grün. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
140 lines
4.9 KiB
PHP
140 lines
4.9 KiB
PHP
<?php
|
||
|
||
namespace Tests\Feature;
|
||
|
||
use App\Actions\SendOffer;
|
||
use App\Filament\Operator\Tenants\Pages\EditTenant;
|
||
use App\Models\Booking;
|
||
use App\Models\Page;
|
||
use App\Models\Property;
|
||
use App\Models\Site;
|
||
use App\Models\Tenant;
|
||
use App\Models\User;
|
||
use Filament\Facades\Filament;
|
||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||
use Livewire\Features\SupportTesting\Testable;
|
||
use Livewire\Livewire;
|
||
use Tests\TestCase;
|
||
|
||
class WebsiteTenancyTest extends TestCase
|
||
{
|
||
use RefreshDatabase;
|
||
|
||
protected function setUp(): void
|
||
{
|
||
parent::setUp();
|
||
|
||
$this->withoutVite();
|
||
}
|
||
|
||
public function test_one_landlord_still_answers_on_any_address(): void
|
||
{
|
||
$site = $this->website('Einzige Wohnung');
|
||
|
||
$this->get('http://fremd.test/')->assertOk()->assertSee('Einzige Wohnung');
|
||
$this->assertSame($site->id, Site::query()->where('is_default', true)->value('id'));
|
||
}
|
||
|
||
public function test_a_second_landlord_is_reached_only_on_their_own_address(): void
|
||
{
|
||
$this->website('Nordhaus', 'nordhaus.test');
|
||
$this->website('Südheim', 'suedheim.test');
|
||
|
||
$this->get('http://nordhaus.test/')->assertOk()->assertSee('Nordhaus')->assertDontSee('Südheim');
|
||
$this->get('http://suedheim.test/')->assertOk()->assertSee('Südheim')->assertDontSee('Nordhaus');
|
||
$this->get('http://unbekannt.test/')->assertNotFound();
|
||
}
|
||
|
||
/**
|
||
* The trap that would take a live site down: as long as there is one landlord every address works, so
|
||
* nobody notices that no host is entered. The second landlord turns every unentered address into a 404 –
|
||
* including "www", which is a host of its own.
|
||
*/
|
||
public function test_a_website_answers_on_every_address_entered_for_it(): void
|
||
{
|
||
$site = $this->website('Nordhaus', 'nordhaus.test');
|
||
$this->website('Südheim', 'suedheim.test');
|
||
|
||
$this->get('http://www.nordhaus.test/')->assertNotFound();
|
||
|
||
$this->editHosts($site, ['www.nordhaus.test', 'https://ALT.nordhaus.test/'])->assertHasNoFormErrors();
|
||
|
||
$this->get('http://nordhaus.test/')->assertOk()->assertSee('Nordhaus');
|
||
$this->get('http://www.nordhaus.test/')->assertOk()->assertSee('Nordhaus');
|
||
$this->get('http://alt.nordhaus.test/')->assertOk()->assertSee('Nordhaus');
|
||
$this->get('http://unbekannt.test/')->assertNotFound();
|
||
|
||
$this->assertSame(
|
||
['alt.nordhaus.test', 'nordhaus.test', 'www.nordhaus.test'],
|
||
$site->domains()->orderBy('host')->pluck('host')->all(),
|
||
);
|
||
}
|
||
|
||
public function test_a_host_of_another_website_cannot_be_taken_over(): void
|
||
{
|
||
$nord = $this->website('Nordhaus', 'nordhaus.test');
|
||
$sued = $this->website('Südheim', 'suedheim.test');
|
||
|
||
$this->editHosts($nord, ['suedheim.test'])->assertHasFormErrors();
|
||
|
||
$this->get('http://suedheim.test/')->assertOk()->assertSee('Südheim')->assertDontSee('Nordhaus');
|
||
$this->assertSame([$sued->id], $sued->domains()->pluck('site_id')->all());
|
||
}
|
||
|
||
public function test_the_offer_link_uses_the_website_address(): void
|
||
{
|
||
$site = $this->website('Nordhaus', 'nordhaus.test');
|
||
$property = Property::factory()->create(['site_id' => $site->id]);
|
||
$booking = Booking::factory()->for($property)->create([
|
||
'hold_expires_at' => now()->addDay(),
|
||
'offer_version' => 1,
|
||
]);
|
||
|
||
$url = app(SendOffer::class)->offerUrl($booking);
|
||
|
||
$this->assertStringStartsWith('https://nordhaus.test/angebot/', $url);
|
||
$this->assertStringContainsString('signature=', $url);
|
||
}
|
||
|
||
/**
|
||
* Enters the addresses the way they are really entered: by the operator, on the landlord. The form's
|
||
* own defences are under test with them.
|
||
*
|
||
* @param list<string> $hosts
|
||
*/
|
||
private function editHosts(Site $site, array $hosts): Testable
|
||
{
|
||
$operator = User::factory()->create();
|
||
$operator->forceFill(['is_operator' => true])->saveQuietly();
|
||
$this->actingAs($operator);
|
||
Filament::setCurrentPanel('operator');
|
||
|
||
return Livewire::test(EditTenant::class, ['record' => $site->tenant->getRouteKey()])
|
||
->fillForm(['websites' => [[
|
||
'id' => $site->id,
|
||
'name' => $site->name,
|
||
'hosts' => [$site->domain, ...$hosts],
|
||
]]])
|
||
->call('save');
|
||
}
|
||
|
||
private function website(string $name, ?string $domain = null): Site
|
||
{
|
||
$tenant = Tenant::factory()->create();
|
||
$site = Site::factory()->create([
|
||
'tenant_id' => $tenant->id,
|
||
'name' => $name,
|
||
'domain' => $domain,
|
||
'is_default' => $domain === null,
|
||
]);
|
||
Page::factory()->create([
|
||
'site_id' => $site->id,
|
||
'slug' => Page::HOME,
|
||
'title' => $name,
|
||
'sections' => [],
|
||
]);
|
||
|
||
return $site;
|
||
}
|
||
}
|