CspTest.php in Raven: Sentry Integration 3.x
File
tests/src/Functional/CspTest.php
View source
<?php
namespace Drupal\Tests\raven\Functional;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Tests\BrowserTestBase;
class CspTest extends BrowserTestBase {
use StringTranslationTrait;
protected $defaultTheme = 'stark';
protected static $modules = [
'csp',
'raven',
];
public function testRavenJavascriptConfig() {
$admin_user = $this
->drupalCreateUser([
'administer csp configuration',
'administer site configuration',
'send javascript errors to sentry',
]);
$this
->drupalLogin($admin_user);
$this
->drupalGet('admin/config/development/logging');
$this
->submitForm([
'raven[js][javascript_error_handler]' => TRUE,
'raven[js][public_dsn]' => 'https://a@domain.test/1',
], $this
->t('Save configuration'));
$this
->drupalGet('admin/config/system/csp');
$this
->submitForm([
'report-only[reporting][handler]' => 'raven',
], $this
->t('Save configuration'));
$this
->assertSession()
->responseHeaderEquals('Content-Security-Policy-Report-Only', "script-src 'self'; style-src 'self'; frame-ancestors 'self'; report-uri https://domain.test/api/1/security/?sentry_key=a");
$this
->drupalGet('admin/config/system/csp');
$this
->submitForm([
'report-only[directives][connect-src][enable]' => TRUE,
'report-only[directives][connect-src][base]' => 'self',
], $this
->t('Save configuration'));
$this
->assertSession()
->responseHeaderEquals('Content-Security-Policy-Report-Only', "connect-src 'self' https://domain.test/api/1/store/ https://domain.test/api/1/envelope/; script-src 'self'; style-src 'self'; frame-ancestors 'self'; report-uri https://domain.test/api/1/security/?sentry_key=a");
}
}