|
16 | 16 | use App\Controllers\Home; |
17 | 17 | use CodeIgniter\Exceptions\PageNotFoundException; |
18 | 18 | use CodeIgniter\Exceptions\RuntimeException; |
19 | | -use CodeIgniter\HTTP\IncomingRequest; |
20 | | -use CodeIgniter\HTTP\Response; |
21 | 19 | use CodeIgniter\Test\CIUnitTestCase; |
22 | 20 | use CodeIgniter\Test\IniTestTrait; |
23 | 21 | use CodeIgniter\Test\StreamFilterTrait; |
24 | | -use Config\App; |
25 | 22 | use Config\Exceptions as ExceptionsConfig; |
26 | 23 | use Config\Services; |
27 | 24 | use PHPUnit\Framework\Attributes\Group; |
@@ -391,32 +388,4 @@ public function testSanitizeDataWithScalars(): void |
391 | 388 | $this->assertFalse($sanitizeData(false)); |
392 | 389 | $this->assertNull($sanitizeData(null)); |
393 | 390 | } |
394 | | - |
395 | | - public function testHandleJsonResponseWithCSPEnabledProducesValidJson(): void |
396 | | - { |
397 | | - $config = config(App::class); |
398 | | - $config->CSPEnabled = true; |
399 | | - |
400 | | - /** @var IncomingRequest $request */ |
401 | | - $request = service('incomingrequest', $config, false); |
402 | | - $request->setHeader('accept', 'application/json'); |
403 | | - $response = new Response($config); |
404 | | - $response->pretend(); |
405 | | - |
406 | | - $exception = new RuntimeException('Test exception'); |
407 | | - |
408 | | - ob_start(); |
409 | | - $this->handler->handle($exception, $request, $response, 500, EXIT_ERROR); |
410 | | - $output = ob_get_clean(); |
411 | | - |
412 | | - $json = json_decode($output); |
413 | | - $this->assertNotNull($json); |
414 | | - |
415 | | - // Nonce placeholders must not appear in the output |
416 | | - $this->assertStringNotContainsString('{csp-style-nonce}', (string) $output); |
417 | | - $this->assertStringNotContainsString('{csp-script-nonce}', (string) $output); |
418 | | - |
419 | | - // The nonce attribute values should be properly JSON-escaped |
420 | | - $this->assertMatchesRegularExpression('/nonce=\\\\"[A-Za-z0-9+\/=]+\\\\"/', $output); |
421 | | - } |
422 | 391 | } |
0 commit comments