Mehrere Adressen je Website, damit ein zweiter Mandant niemanden abschaltet
Bisher schrieb das Feld „Domain" genau einen Host nach `site_domains` und löschte den vorherigen. Solange es einen Mandanten gibt, fällt das nicht auf: jede Adresse liefert die Standard-Website. Ab dem zweiten Mandanten bekommt jede nicht eingetragene Adresse 404 – und „www.beispiel.de" ist eine eigene Adresse. stommer.info hätte einen zweiten Mandanten nicht überlebt. Das Formular hat jetzt „Hauptadresse" (steht in Gästelinks) und „Weitere Adressen". Eingaben werden normalisiert, „https://WWW.Beispiel.de/" wird zu „www.beispiel.de". Eine Adresse, die schon zu einer anderen Website gehört, wird abgelehnt. Ohne diese Sperre könnte ein Mandant die Besucher eines anderen auf seine eigene Seite ziehen, indem er dessen Adresse einträgt. 242 Feature-Tests grün. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
fd2a7f7ded
commit
2e3f2ca938
8 files changed
+236
-3
No files matched your search
@@ -3,12 +3,18 @@
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Actions\SendOffer;
|
||||
use App\Enums\UserRole;
|
||||
use App\Filament\Resources\Sites\Pages\EditSite;
|
||||
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 App\Tenancy\TenantContext;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Livewire\Features\SupportTesting\Testable;
|
||||
use Livewire\Livewire;
|
||||
use Tests\TestCase;
|
||||
|
||||
class WebsiteTenancyTest extends TestCase
|
||||
@@ -40,6 +46,42 @@ public function test_a_second_landlord_is_reached_only_on_their_own_address(): v
|
||||
$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');
|
||||
@@ -55,6 +97,21 @@ public function test_the_offer_link_uses_the_website_address(): void
|
||||
$this->assertStringContainsString('signature=', $url);
|
||||
}
|
||||
|
||||
/**
|
||||
* Enters the further addresses through the real admin form, so the form's own defences are under test.
|
||||
*
|
||||
* @param list<string> $hosts
|
||||
*/
|
||||
private function editHosts(Site $site, array $hosts): Testable
|
||||
{
|
||||
app(TenantContext::class)->set($site->tenant);
|
||||
$this->actingAs(User::factory()->role(UserRole::Admin)->create());
|
||||
|
||||
return Livewire::test(EditSite::class, ['record' => $site->getRouteKey()])
|
||||
->fillForm(['extra_hosts' => $hosts])
|
||||
->call('save');
|
||||
}
|
||||
|
||||
private function website(string $name, ?string $domain = null): Site
|
||||
{
|
||||
$tenant = Tenant::factory()->create();
|
||||
|
||||
Reference in new issue
Block a user