- 21 test files covering controllers, services, entities, enums, messages - CI: add test job with Xdebug coverage (clover + text) - SonarQube: configure coverage report path and test sources Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
57 lines
1.6 KiB
PHP
57 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Tests\Controller;
|
|
|
|
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
|
|
|
class CspReportControllerTest extends WebTestCase
|
|
{
|
|
public function testInvalidPayloadReturnsBadRequest(): void
|
|
{
|
|
$client = static::createClient();
|
|
$client->request('POST', '/my-csp-report', [], [], [
|
|
'CONTENT_TYPE' => 'application/json',
|
|
], '');
|
|
|
|
self::assertResponseStatusCodeSame(400);
|
|
}
|
|
|
|
public function testBrowserExtensionViolationIsIgnored(): void
|
|
{
|
|
$client = static::createClient();
|
|
$payload = json_encode([
|
|
'csp-report' => [
|
|
'source-file' => 'chrome-extension://abc',
|
|
'blocked-uri' => 'inline',
|
|
'document-uri' => 'https://e-cosplay.fr/',
|
|
'violated-directive' => 'script-src',
|
|
],
|
|
]);
|
|
|
|
$client->request('POST', '/my-csp-report', [], [], [
|
|
'CONTENT_TYPE' => 'application/json',
|
|
], $payload);
|
|
|
|
self::assertResponseStatusCodeSame(204);
|
|
}
|
|
|
|
public function testRealViolationIsProcessed(): void
|
|
{
|
|
$client = static::createClient();
|
|
$payload = json_encode([
|
|
'csp-report' => [
|
|
'source-file' => 'https://evil.com/script.js',
|
|
'blocked-uri' => 'https://evil.com',
|
|
'document-uri' => 'https://e-cosplay.fr/page',
|
|
'violated-directive' => 'script-src',
|
|
],
|
|
]);
|
|
|
|
$client->request('POST', '/my-csp-report', [], [], [
|
|
'CONTENT_TYPE' => 'application/json',
|
|
], $payload);
|
|
|
|
self::assertResponseStatusCodeSame(204);
|
|
}
|
|
}
|