You are here

public function ValidateHostnameTest::providerTestValidateHostname in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/tests/Drupal/Tests/Core/DrupalKernel/ValidateHostnameTest.php \Drupal\Tests\Core\DrupalKernel\ValidateHostnameTest::providerTestValidateHostname()

Provides test data for testValidateHostname().

File

core/tests/Drupal/Tests/Core/DrupalKernel/ValidateHostnameTest.php, line 34
Contains \Drupal\Tests\Core\DrupalKernel\ValidateHostnameTest.

Class

ValidateHostnameTest
@coversDefaultClass \Drupal\Core\DrupalKernel @group DrupalKernel

Namespace

Drupal\Tests\Core\DrupalKernel

Code

public function providerTestValidateHostname() {
  $data = [];

  // Verifies that DrupalKernel::validateHostname() prevents invalid
  // characters per RFC 952/2181.
  $data[] = [
    'security/.drupal.org:80',
    'HTTP_HOST with / is invalid',
  ];
  $data[] = [
    'security/.drupal.org:80',
    'HTTP_HOST with / is invalid',
  ];
  $data[] = [
    'security\\.drupal.org:80',
    'HTTP_HOST with \\ is invalid',
  ];
  $data[] = [
    'security<.drupal.org:80',
    'HTTP_HOST with &lt; is invalid',
  ];
  $data[] = [
    'security..drupal.org:80',
    'HTTP_HOST with .. is invalid',
  ];

  // Verifies hostnames that are too long, or have too many parts are
  // invalid.
  $data[] = [
    str_repeat('x', 1000) . '.security.drupal.org:80',
    'HTTP_HOST with more than 1000 characters is invalid.',
  ];
  $data[] = [
    str_repeat('x.', 100) . 'security.drupal.org:80',
    'HTTP_HOST with more than 100 subdomains is invalid.',
  ];
  $data[] = [
    'security.drupal.org:80' . str_repeat(':x', 100),
    'HTTP_HOST with more than 100 port separators is invalid.',
  ];

  // Verifies that a valid hostname is allowed.
  $data[] = [
    'security.drupal.org:80',
    'Properly formed HTTP_HOST is valid.',
    TRUE,
  ];

  // Verifies that using valid IP address for the hostname is allowed.
  $data[] = [
    '72.21.91.99:80',
    'Properly formed HTTP_HOST with IPv4 address valid.',
    TRUE,
  ];
  $data[] = [
    '2607:f8b0:4004:803::1002:80',
    'Properly formed HTTP_HOST with IPv6 address valid.',
    TRUE,
  ];

  // Verfies that the IPv6 loopback address is valid.
  $data[] = [
    '[::1]:80',
    'HTTP_HOST containing IPv6 loopback is valid.',
    TRUE,
  ];
  return $data;
}