You are here

CspTest.php in Raven: Sentry Integration 3.x

Same filename and directory in other branches
  1. 8.2 tests/src/Functional/CspTest.php

File

tests/src/Functional/CspTest.php
View source
<?php

namespace Drupal\Tests\raven\Functional;

use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Tests\BrowserTestBase;

/**
 * Tests Raven and CSP modules.
 *
 * @group raven
 */
class CspTest extends BrowserTestBase {
  use StringTranslationTrait;

  /**
   * {@inheritdoc}
   */
  protected $defaultTheme = 'stark';

  /**
   * Modules to install.
   *
   * @var array
   */
  protected static $modules = [
    'csp',
    'raven',
  ];

  /**
   * Tests Sentry browser client configuration UI.
   */
  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");
  }

}

Classes

Namesort descending Description
CspTest Tests Raven and CSP modules.