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>
118 lines
4.3 KiB
PHP
118 lines
4.3 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature;
|
|
|
|
use App\Filament\Operator\Pages\SystemSettingsPage;
|
|
use App\Models\SystemSetting;
|
|
use App\Models\Tenant;
|
|
use App\Models\User;
|
|
use App\Support\Settings;
|
|
use App\Support\SystemSettings;
|
|
use App\Tenancy\TenantConfig;
|
|
use App\Tenancy\TenantContext;
|
|
use Filament\Facades\Filament;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Livewire\Livewire;
|
|
use Tests\TestCase;
|
|
|
|
/**
|
|
* Settings of the whole installation, owned by the operator. They are the baseline a landlord may tighten
|
|
* but not exceed, so they have to win over the .env and lose to nobody's landlord.
|
|
*/
|
|
class SystemSettingsTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
|
|
SystemSettings::forget();
|
|
}
|
|
|
|
public function test_a_stored_value_wins_over_the_env_and_an_empty_one_gives_it_back(): void
|
|
{
|
|
config(['fewo.spam.total_per_hour' => 30]);
|
|
|
|
SystemSettings::save(['fewo.spam.total_per_hour' => '120']);
|
|
$this->assertSame(120, config('fewo.spam.total_per_hour'));
|
|
$this->assertSame(120, SystemSettings::get('fewo.spam.total_per_hour'));
|
|
|
|
SystemSettings::save(['fewo.spam.total_per_hour' => '']);
|
|
config(['fewo.spam.total_per_hour' => 30]);
|
|
SystemSettings::apply();
|
|
|
|
$this->assertSame(30, config('fewo.spam.total_per_hour'), 'Leer = der Wert der .env gilt wieder.');
|
|
$this->assertSame(0, SystemSetting::query()->count());
|
|
}
|
|
|
|
public function test_a_secret_is_stored_encrypted(): void
|
|
{
|
|
SystemSettings::save(['mail.mailers.smtp.password' => 'geheim']);
|
|
|
|
$stored = DB::table('system_settings')->where('key', 'mail.mailers.smtp.password')->first();
|
|
|
|
$this->assertNotSame('geheim', $stored?->value);
|
|
$this->assertTrue((bool) $stored?->is_secret);
|
|
$this->assertSame('geheim', SystemSettings::get('mail.mailers.smtp.password'));
|
|
}
|
|
|
|
/**
|
|
* The whole point of the ceiling: what the operator sets here binds every landlord.
|
|
*/
|
|
public function test_the_stored_limit_becomes_the_ceiling_for_a_landlord(): void
|
|
{
|
|
config(['fewo.guest_retention_years' => 10]);
|
|
SystemSettings::save(['fewo.guest_retention_years' => '4']);
|
|
|
|
$tenant = Tenant::factory()->create(['guest_retention_years' => 9]);
|
|
app(TenantContext::class)->set($tenant);
|
|
app(TenantConfig::class)->refresh();
|
|
|
|
$this->assertSame(4, config('fewo.guest_retention_years'), 'Der Mandant darf die Obergrenze nicht überschreiten.');
|
|
}
|
|
|
|
public function test_the_operator_edits_the_settings_and_a_landlords_administrator_cannot_reach_the_page(): void
|
|
{
|
|
$tenant = Tenant::factory()->create();
|
|
app(TenantContext::class)->set($tenant);
|
|
|
|
$admin = User::factory()->create();
|
|
$this->actingAs($admin)->get('/betreiber/einstellungen')->assertForbidden();
|
|
|
|
$admin->forceFill(['is_operator' => true])->saveQuietly();
|
|
$this->actingAs($admin);
|
|
Filament::setCurrentPanel('operator');
|
|
|
|
$this->get('/betreiber/einstellungen')->assertOk()->assertSee('Systemweite Einstellungen');
|
|
|
|
Livewire::test(SystemSettingsPage::class)
|
|
->set('data.fewo__spam__total_per_hour', '77')
|
|
->set('data.fewo__mail_redirect_to', 'auffang@example.com')
|
|
->call('save')
|
|
->assertHasNoErrors();
|
|
|
|
$this->assertSame(77, SystemSettings::get('fewo.spam.total_per_hour'));
|
|
$this->assertSame('auffang@example.com', config('fewo.mail_redirect_to'));
|
|
}
|
|
|
|
/**
|
|
* The hard redirect is the net that keeps a test server from writing to real guests. It is editable on
|
|
* purpose, so it must be obvious that emptying it hands the decision back to each landlord.
|
|
*/
|
|
public function test_emptying_the_hard_redirect_leaves_only_the_landlords_own_test_mode(): void
|
|
{
|
|
SystemSettings::save(['fewo.mail_redirect_to' => 'auffang@example.com']);
|
|
|
|
$live = Tenant::factory()->create(['operating_mode' => 'live', 'notification_emails' => 'wirt@example.com']);
|
|
app(TenantContext::class)->set($live);
|
|
|
|
$this->assertSame('auffang@example.com', Settings::mailRedirect());
|
|
|
|
SystemSettings::save(['fewo.mail_redirect_to' => '']);
|
|
|
|
$this->assertNull(Settings::mailRedirect(), 'Ohne harte Umleitung entscheidet der Mandant allein.');
|
|
}
|
|
}
|