function ValidateHostnameTest::providerTestValidateHostname

Same name in other branches
  1. 9 core/tests/Drupal/Tests/Core/DrupalKernel/ValidateHostnameTest.php \Drupal\Tests\Core\DrupalKernel\ValidateHostnameTest::providerTestValidateHostname()
  2. 10 core/tests/Drupal/Tests/Core/DrupalKernel/ValidateHostnameTest.php \Drupal\Tests\Core\DrupalKernel\ValidateHostnameTest::providerTestValidateHostname()
  3. 11.x 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 29

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,
    ];
    // Verifies that the IPv6 loopback address is valid.
    $data[] = [
        '[::1]:80',
        'HTTP_HOST containing IPv6 loopback is valid.',
        TRUE,
    ];
    return $data;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.