public function CspOptimizationTest::testDuplicate in Content-Security-Policy 8
Test that source values are not repeated in the header.
@covers ::getHeaderValue
File
- tests/
src/ Unit/ CspOptimizationTest.php, line 21
Class
- CspOptimizationTest
- Test optimization of CSP directives.
Namespace
Drupal\Tests\csp\UnitCode
public function testDuplicate() {
$policy = new Csp();
// Provide identical sources in an array.
$policy
->setDirective('default-src', [
Csp::POLICY_SELF,
Csp::POLICY_SELF,
]);
// Provide identical sources in a string.
$policy
->setDirective('script-src', 'one.example.com one.example.com');
// Provide identical sources through both set and append.
$policy
->setDirective('style-src', [
'two.example.com',
'two.example.com',
]);
$policy
->appendDirective('style-src', [
'two.example.com',
'two.example.com',
]);
$this
->assertEquals("default-src 'self'; script-src one.example.com; style-src two.example.com", $policy
->getHeaderValue());
}