You are here

public function HstsTest::testHsts in HTTP Strict Transport Security 8

Tests that a HSTS header is set.

File

src/Tests/HstsTest.php, line 37
Definition of Drupal\hsts\Tests\HstsTest.

Class

HstsTest
HSTS tests.

Namespace

Drupal\hsts\Tests

Code

public function testHsts() {
  $this
    ->drupalGet('admin/config/system/hsts');
  $fields = [
    'enabled' => TRUE,
    'max_age' => 63072000,
    'subdomains' => TRUE,
  ];
  $this
    ->drupalPostForm(NULL, $fields, t('Save configuration'));
  $this
    ->assertHeader('Strict-Transport-Security', 'max-age=63072000; includeSubDomains');
  $fields = [
    'enabled' => TRUE,
    'max_age' => 63072000,
    'subdomains' => TRUE,
    'preload' => TRUE,
  ];
  $this
    ->drupalPostForm(NULL, $fields, t('Save configuration'));
  $this
    ->assertHeader('Strict-Transport-Security', 'max-age=63072000; includeSubDomains; preload');
}