Loheide-eu-mitarbeiterplatt.../tests/Feature/Admin/MailSettingsTest.php
Friederich Loheide f1202bea08
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 7m50s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 7m34s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 5m45s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 5m30s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 7m7s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 7m9s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 6m8s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 6m5s
CI / Bekannte Sicherheitslücken in Paketen (pull_request) Successful in 48s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m5s
Sicherheitsupdate nach Audit (0.29.0)
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-27 11:34:54 +00:00

50 lines
2.2 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace Tests\Feature\Admin;
use App\Filament\Pages\MailSettingsPage;
use App\Models\User;
use App\Support\MailSettings;
use App\Support\Settings;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Livewire\Livewire;
use Tests\TestCase;
class MailSettingsTest extends TestCase
{
use RefreshDatabase;
public function test_smtp_settings_are_stored_encrypted_and_applied(): void
{
$this->actingAs(User::factory()->admin()->create());
Livewire::test(MailSettingsPage::class)
->fillForm([
'mailer' => 'smtp', 'host' => 'smtp.office365.com', 'port' => 587, 'encryption' => 'tls',
'username' => 'intranet@firma.de', 'password' => 'geheim123', 'from_address' => 'intranet@firma.de', 'from_name' => 'Intranet',
])
->call('save')
->assertHasNoFormErrors();
$this->assertNotSame('geheim123', app(Settings::class)->get('mail.password'));
$this->assertSame('smtp', config('mail.default'));
$this->assertSame('smtp.office365.com', config('mail.mailers.smtp.host'));
$this->assertSame('geheim123', config('mail.mailers.smtp.password'));
$this->assertSame('intranet@firma.de', config('mail.from.address'));
// Leeres Passwort behält das gespeicherte – solange der Server gleich bleibt.
Livewire::test(MailSettingsPage::class)->assertFormSet(['password' => null])->fillForm(['from_name' => 'Portal'])->call('save')->assertHasNoFormErrors();
config(['mail.mailers.smtp.password' => null]);
app(MailSettings::class)->apply();
$this->assertSame('geheim123', config('mail.mailers.smtp.password'));
// Anderer Server: Passwort muss neu eingegeben werden (sonst ginge es an den neuen Server)
Livewire::test(MailSettingsPage::class)->fillForm(['host' => 'mail.angreifer.example'])->call('save')->assertHasFormErrors(['password']);
$this->assertSame('smtp.office365.com', app(Settings::class)->get('mail.host'));
}
public function test_only_permitted_people_open_the_page(): void
{
$this->actingAs(User::factory()->create())->get('/admin/e-mail')->assertForbidden();
}
}