1
0

fix(error): harden logging, i18n, a11y and handler tests

This commit is contained in:
2026-03-24 22:00:14 +01:00
parent 44a357dfc4
commit a0d816caaa
10 changed files with 515 additions and 100 deletions

View File

@@ -36,7 +36,7 @@ class ErrorLoggerTest extends TestCase
'request_id' => 'abc-123',
'channel' => 'web',
'method' => 'GET',
'url' => '/admin/dashboard',
'url' => '/admin/dashboard?token=very-secret',
'ip' => '127.0.0.1',
'user_id' => 5,
'tenant_id' => 1,
@@ -60,11 +60,41 @@ class ErrorLoggerTest extends TestCase
$this->assertSame('error', $entry['level']);
$this->assertSame('abc-123', $entry['request_id']);
$this->assertSame('RuntimeException', $entry['exception']['class']);
$this->assertSame('Test error', $entry['exception']['message']);
$this->assertSame('[REDACTED]', $entry['exception']['message']);
$this->assertArrayHasKey('message_hash', $entry['exception']);
$this->assertStringStartsWith('sha256:', (string) $entry['exception']['message_hash']);
$this->assertArrayHasKey('ip_hash', $entry['request']);
$this->assertStringStartsWith('sha256:', $entry['request']['ip_hash']);
$this->assertSame('/admin/dashboard', $entry['request']['path']);
$this->assertArrayNotHasKey('url', $entry['request']);
// Raw IP should NOT be in the log.
$this->assertStringNotContainsString('127.0.0.1', json_encode($entry));
$this->assertStringNotContainsString('very-secret', json_encode($entry));
}
public function testLogStoresPathWithoutQueryParameters(): void
{
$exception = new \RuntimeException('Query redaction');
$data = [
'request' => [
'request_id' => 'query-test',
'url' => '/auth/reset-password?email=user@example.com&token=abc123',
],
'exception' => [],
'environment' => [],
];
ErrorLogger::log($exception, $data);
$this->assertFileExists($this->logFile);
$lines = array_filter(explode("\n", (string) file_get_contents($this->logFile)));
$this->assertCount(1, $lines);
$entry = json_decode($lines[0], true);
$this->assertIsArray($entry);
$this->assertSame('/auth/reset-password', $entry['request']['path']);
$this->assertStringNotContainsString('user@example.com', $lines[0]);
$this->assertStringNotContainsString('token=abc123', $lines[0]);
}
public function testLogRedactsIpAddress(): void