mivita/tests/Feature/Monitoring/BrowserErrorReportingTest.php
Kevin Adametz 0b02b1b15c GlitchTip: Fehlerprotokoll fuer Server, Fehlersignale und Browser
- sentry/sentry-laravel 4.28; config/sentry.php gehaertet (keine PII,
  keine Request-Bodys, before_send ErrorReportScrubber)
- Handler: Integration::captureUnhandledException, CommandNotFoundException
  nicht melden
- ReportErrorSignals (global): toter interner Link (nach Pfad wegen
  Catch-all-Route), 403/429 fuer Angemeldete, 419; gedrosselt
- Browser: selbst gehostetes SDK (esbuild-Bundle 11.5.0), Loader ohne
  Build-Schritt und ohne Regex-Lookbehind, in 7 Layouts mit area-Tag
- phpunit.xml: DSNs und ntfy-URL leer, CACHE_DRIVER=array (Tests schrieben
  bisher in den lokalen Datei-Cache)
- dev/glitch-tip/README.md mit Instanz, Org, Projekt-IDs, API-Auswertung

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

60 lines
2.4 KiB
PHP

<?php
use App\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Blade;
use Tests\TestCase;
uses(TestCase::class, RefreshDatabase::class);
/**
* Browserfehler: Meta-Konfiguration und Skript nur mit DSN; die User-ID ist
* der einzige Personenbezug. Das SDK ist selbst gehostet (kein Drittanbieter).
*/
test('nothing is rendered without a browser dsn', function () {
config()->set('monitoring.browser.dsn', null);
expect(trim(Blade::render('<x-monitoring.browser-errors />')))->toBe('');
});
test('the configuration carries dsn, release, sdk and the user id only', function () {
config()->set('monitoring.browser.dsn', 'https://public@glitchtip.test/2');
config()->set('sentry.release', 'v1.3.0');
$user = User::forceCreate(['email' => 'kunde@example.com', 'password' => bcrypt('secret'), 'lang' => 'de']);
$this->actingAs($user);
$html = Blade::render('<x-monitoring.browser-errors area="portal" />');
preg_match('/<meta name="mivita-error-reporting" content="([^"]+)"/', $html, $match);
$config = json_decode(html_entity_decode($match[1]), true);
expect($config)->toMatchArray([
'dsn' => 'https://public@glitchtip.test/2',
'release' => 'v1.3.0',
'userId' => $user->id,
'area' => 'portal',
])
->and($config['sdk'])->toEndWith('/js/error-reporting/sentry-browser-'.config('monitoring.browser.sdk_version').'.min.js')
->and($html)->toContain('js/error-reporting/error-reporting.js')
->and($html)->not->toContain('kunde@example.com');
});
test('the self-hosted sdk and the loader exist and the loader avoids regex lookbehind', function () {
$loader = file_get_contents(public_path('js/error-reporting/error-reporting.js'));
expect(public_path('js/error-reporting/sentry-browser-'.config('monitoring.browser.sdk_version').'.min.js'))->toBeFile()
->and($loader)->not->toContain('(?<=')
->and($loader)->not->toContain('(?<!');
});
test('every page layout includes the browser error reporting', function (string $layout) {
expect(file_get_contents(resource_path("views/{$layout}.blade.php")))->toContain('<x-monitoring.browser-errors');
})->with([
'layouts/application',
'layouts/auth',
'portal/layouts/application',
'portal/layouts/auth',
'portal/layouts/public',
'web/layouts/application',
'web/user/layouts/application',
]);