class CspFirefoxBugTest in Content-Security-Policy 8
Test Csp handling of Firefox bug #1313937.
@coversDefaultClass \Drupal\csp\Csp @group csp
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\csp\Unit\CspFirefoxBugTest
Expanded class hierarchy of CspFirefoxBugTest
See also
https://bugzilla.mozilla.org/show_bug.cgi?id=1313937
File
- tests/
src/ Unit/ CspFirefoxBugTest.php, line 16
Namespace
Drupal\Tests\csp\UnitView source
class CspFirefoxBugTest extends UnitTestCase {
/**
* Test that no modifications are made if default-src isn't set.
*
* @covers ::ff1313937
*/
public function testEmptyDefault() {
$policy = new Csp();
$policy
->setDirective('script-src', [
Csp::POLICY_STRICT_DYNAMIC,
"'nonce-abc'",
]);
$policy
->setDirective('style-src', [
Csp::POLICY_SELF,
"'hash-abc'",
]);
$this
->assertEquals("script-src 'strict-dynamic' 'nonce-abc'; style-src 'self' 'hash-abc'", $policy
->getHeaderValue());
}
/**
* Test that 'strict-dynamic' directive is copied from default-src.
*
* @covers ::ff1313937
*/
public function testStrictDynamic() {
$policy = new Csp();
$policy
->setDirective('default-src', [
Csp::POLICY_STRICT_DYNAMIC,
"'nonce-abc'",
]);
$this
->assertEquals("default-src 'strict-dynamic' 'nonce-abc'; script-src 'strict-dynamic' 'nonce-abc'; style-src 'nonce-abc'", $policy
->getHeaderValue());
}
/**
* Test that nonce directives are copied from default-src.
*
* @covers ::ff1313937
*/
public function testNonce() {
$policy = new Csp();
$policy
->setDirective('default-src', [
Csp::POLICY_SELF,
"'nonce-abc'",
]);
$this
->assertEquals("default-src 'self' 'nonce-abc'; script-src 'self' 'nonce-abc'; style-src 'self' 'nonce-abc'", $policy
->getHeaderValue());
}
/**
* Test that hash directives are copied from default-src.
*
* @covers ::ff1313937
*/
public function testHash() {
$policy = new Csp();
$policy
->setDirective('default-src', [
Csp::POLICY_SELF,
"'hash-abc'",
]);
$this
->assertEquals("default-src 'self' 'hash-abc'; script-src 'self' 'hash-abc'; style-src 'self' 'hash-abc'", $policy
->getHeaderValue());
}
/**
* Test that directives are not copied if more specific directive set.
*
* @covers ::ff1313937
*/
public function testSetScriptSrc() {
$policy = new Csp();
$policy
->setDirective('default-src', [
Csp::POLICY_SELF,
"'hash-abc'",
]);
$policy
->setDirective('script-src', [
Csp::POLICY_STRICT_DYNAMIC,
"'nonce-abc'",
]);
$this
->assertEquals("default-src 'self' 'hash-abc'; script-src 'strict-dynamic' 'nonce-abc'; style-src 'self' 'hash-abc'", $policy
->getHeaderValue());
}
/**
* Test that directives are not copied if more specific directive set.
*
* @covers ::ff1313937
*/
public function testSetStyleSrc() {
$policy = new Csp();
$policy
->setDirective('default-src', [
Csp::POLICY_SELF,
Csp::POLICY_STRICT_DYNAMIC,
"'hash-abc'",
]);
$policy
->setDirective('style-src', [
Csp::POLICY_SELF,
]);
$this
->assertEquals("default-src 'self' 'strict-dynamic' 'hash-abc'; script-src 'self' 'strict-dynamic' 'hash-abc'; style-src 'self'", $policy
->getHeaderValue());
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CspFirefoxBugTest:: |
public | function | Test that no modifications are made if default-src isn't set. | |
CspFirefoxBugTest:: |
public | function | Test that hash directives are copied from default-src. | |
CspFirefoxBugTest:: |
public | function | Test that nonce directives are copied from default-src. | |
CspFirefoxBugTest:: |
public | function | Test that directives are not copied if more specific directive set. | |
CspFirefoxBugTest:: |
public | function | Test that directives are not copied if more specific directive set. | |
CspFirefoxBugTest:: |
public | function | Test that 'strict-dynamic' directive is copied from default-src. | |
PhpunitCompatibilityTrait:: |
public | function | Returns a mock object for the specified class using the available method. | |
PhpunitCompatibilityTrait:: |
public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | 1 |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | 1 |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. | |
UnitTestCase:: |
protected | function | 340 |