presseportale/tests/Feature/PlausibleEmailDomainTest.php
Kevin Adametz f581e1eb3a mail: Kontakterreichbarkeit - Formpruefung, Domainpruefung, Einlieferer-Bericht
Vier Punkte aus kontakterreichbarkeit-mx-bounces-2026-09-15.md, ohne
Veroeffentlichungssperre:

- PlausibleEmailDomain: Domain ohne Endung oder mit Tippfehler-TLD ist
  ein 422 an der Legacy-API, deterministisch ohne DNS.
- email_domain_checks + MailDomainChecker ueber DnsResolver-Schnittstelle
  (RFC 5321 impliziter MX, RFC 7505 Null MX, Unresolved ist kein Befund),
  Observer an Company/Contact, Job nach Commit, taeglicher Refresh,
  mail:check-domains fuer den Bestand. Nie eine Adresssperre aus DNS.
- Admin > Reports > Einlieferer-Bericht: tote Adressen aus Sperrliste
  und Domainbefund, automatisch abgelehnte Meldungen mit Grund,
  Text zum Kopieren und CSV. Versendet nichts.
- EmailBounceKind::Policy: 5.7.x wird protokolliert, zaehlt aber nicht
  auf den Schwellwert. Statuscode entscheidet vor Diagnosetext.

Messung vorab: 6 von 877 API-Domains ohne Zustellweg, eine davon fuer
66 der 151 Ruecklaeufer verantwortlich.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-16 09:22:39 +00:00

69 lines
2.8 KiB
PHP

<?php
use App\Enums\Portal;
use App\Models\User;
use App\Rules\PlausibleEmailDomain;
use Database\Seeders\RolesAndPermissionsSeeder;
use Illuminate\Support\Facades\Queue;
use Illuminate\Support\Facades\Validator;
use Laravel\Sanctum\Sanctum;
use Tests\TestCase;
/**
* Formprüfung der Domain beim Einreichen (Kontakterreichbarkeit, 5.1) —
* deterministisch, ohne Netz.
*/
function passesPlausibility(string $email): bool
{
return Validator::make(['email' => $email], ['email' => ['nullable', 'email', new PlausibleEmailDomain]])->passes();
}
test('addresses without a real domain ending are rejected', function () {
/** @var TestCase $this */
// Alle drei stammen aus dem Bestand vom 15.09.2026 und bestehen
// Laravels `email`-Regel anstandslos.
expect(passesPlausibility('info@hoerwelt-basel'))->toBeFalse()
->and(passesPlausibility('kontakt@hoerex'))->toBeFalse()
->and(passesPlausibility('cks@kaeser-stroebelde'))->toBeFalse()
->and(passesPlausibility('info@urbanbnb.ded'))->toBeFalse();
});
test('ordinary addresses pass, international ones included', function () {
/** @var TestCase $this */
expect(passesPlausibility('presse@firma.de'))->toBeTrue()
->and(passesPlausibility('info@sub.firma.co.uk'))->toBeTrue()
->and(passesPlausibility('info@münchen-presse.de'))->toBeTrue()
->and(passesPlausibility('info@xn--mnchen-presse-mfb.de'))->toBeTrue();
});
test('malformed domains are rejected without asking dns', function () {
/** @var TestCase $this */
expect(passesPlausibility('info@-firma.de'))->toBeFalse()
->and(passesPlausibility('info@firma-.de'))->toBeFalse()
->and(passesPlausibility('info@firma..de'))->toBeFalse()
->and(passesPlausibility('info@firma.12'))->toBeFalse();
});
test('the domain of an address is returned in dns form', function () {
/** @var TestCase $this */
expect(PlausibleEmailDomain::domainOf('Presse@Firma.DE'))->toBe('firma.de')
->and(PlausibleEmailDomain::domainOf('info@münchen.de'))->toBe('xn--mnchen-3ya.de')
->and(PlausibleEmailDomain::domainOf('ohne-at'))->toBeNull()
->and(PlausibleEmailDomain::domainOf(null))->toBeNull();
});
test('the legacy api refuses a company address whose domain cannot exist', function () {
/** @var TestCase $this */
Queue::fake();
test()->seed(RolesAndPermissionsSeeder::class);
$user = User::factory()->create(['is_active' => true, 'portal' => Portal::Businessportal24]);
Sanctum::actingAs($user, ['press-releases:write']);
$this->postJson('/service/users/me/companies', [
'company' => ['name' => 'Hörwelt Basel', 'email' => 'info@hoerwelt-basel'],
])->assertStatus(422);
$this->postJson('/service/users/me/companies', [
'company' => ['name' => 'Hörwelt Basel', 'email' => 'info@hoerwelt-basel.ch'],
])->assertCreated();
});