presseportale/tests/Feature/PlausibleEmailDomainTest.php
Kevin Adametz e77d9e7d09 feat: API-Zugang endet mit der Buchung, optionales Ablaufdatum für API-Tokens
Bisher blieb ein einmal erstellter Token gültig, auch wenn Abo bzw. Buchung
längst beendet waren. EnsureApiAccessIsBooked prüft jetzt bei jeder Anfrage
(v1 und /service/…-Altpfade), ob das Konto API-Zugang hat
(ApiAccessEligibilityService::hasApiAccess), sonst 403. Die Tokens bleiben
erhalten und funktionieren nach erneuter Buchung wieder.

Kunden können beim Erstellen optional ein Ablaufdatum setzen (bis 5 Jahre);
die Token-Liste zeigt „Gültig bis“ und einen Hinweis, wenn der Zugang
pausiert ist. sanctum:prune-expired räumt abgelaufene Tokens nach 30 Tagen
täglich ab. API-Doku (public/api/v1.yml) ergänzt.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-08 11:41:24 +00:00

68 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 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]);
apiActingAs($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();
});