class ValidateHostnameTest
Same name and namespace in other branches
- 11.x core/tests/Drupal/Tests/Core/DrupalKernel/ValidateHostnameTest.php \Drupal\Tests\Core\DrupalKernel\ValidateHostnameTest
- 10 core/tests/Drupal/Tests/Core/DrupalKernel/ValidateHostnameTest.php \Drupal\Tests\Core\DrupalKernel\ValidateHostnameTest
- 9 core/tests/Drupal/Tests/Core/DrupalKernel/ValidateHostnameTest.php \Drupal\Tests\Core\DrupalKernel\ValidateHostnameTest
- 8.9.x core/tests/Drupal/Tests/Core/DrupalKernel/ValidateHostnameTest.php \Drupal\Tests\Core\DrupalKernel\ValidateHostnameTest
Tests Drupal\Core\DrupalKernel.
Attributes
#[CoversClass(DrupalKernel::class)]
#[Group('DrupalKernel')]
Hierarchy
- class \Drupal\Tests\UnitTestCase uses \Drupal\Tests\DrupalTestCaseTrait, \Drupal\Tests\PhpUnitCompatibilityTrait, \Prophecy\PhpUnit\ProphecyTrait, \Drupal\TestTools\Extension\DeprecationBridge\ExpectDeprecationTrait, \Drupal\Tests\RandomGeneratorTrait extends \PHPUnit\Framework\TestCase
- class \Drupal\Tests\Core\DrupalKernel\ValidateHostnameTest extends \Drupal\Tests\UnitTestCase
Expanded class hierarchy of ValidateHostnameTest
File
-
core/
tests/ Drupal/ Tests/ Core/ DrupalKernel/ ValidateHostnameTest.php, line 17
Namespace
Drupal\Tests\Core\DrupalKernelView source
class ValidateHostnameTest extends UnitTestCase {
/**
* Tests validate hostname.
*/
public function testValidateHostname($hostname, $message, $expected = FALSE) : void {
$server = [
'HTTP_HOST' => $hostname,
];
$request = new Request([], [], [], [], [], $server);
$validated_hostname = DrupalKernel::validateHostname($request);
$this->assertSame($expected, $validated_hostname, $message);
}
/**
* Provides test data for testValidateHostname().
*/
public static function providerTestValidateHostname() : array {
$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 < is invalid',
];
$data[] = [
'security..drupal.org:80',
'HTTP_HOST with .. is invalid',
];
// Verifies host names 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;
}
}
Members
| Title Sort descending | Deprecated | Modifiers | Object type | Summary | Overrides |
|---|---|---|---|---|---|
| DrupalTestCaseTrait::checkErrorHandlerOnTearDown | public | function | Checks the test error handler after test execution. | ||
| ExpectDeprecationTrait::expectDeprecation | Deprecated | public | function | Adds an expected deprecation. | |
| ExpectDeprecationTrait::regularExpressionForFormatDescription | private | function | |||
| RandomGeneratorTrait::getRandomGenerator | protected | function | Gets the random generator for the utility methods. | ||
| RandomGeneratorTrait::randomMachineName | protected | function | Generates a unique random string containing letters and numbers. | ||
| RandomGeneratorTrait::randomObject | public | function | Generates a random PHP object. | ||
| RandomGeneratorTrait::randomString | public | function | Generates a pseudo-random string of ASCII characters of codes 32 to 126. | ||
| UnitTestCase::$root | protected | property | The app root. | ||
| UnitTestCase::getClassResolverStub | protected | function | Returns a stub class resolver. | ||
| UnitTestCase::getConfigFactoryStub | public | function | Returns a stub config factory that behaves according to the passed array. | ||
| UnitTestCase::getContainerWithCacheTagsInvalidator | protected | function | Sets up a container with a cache tags invalidator. | ||
| UnitTestCase::getStringTranslationStub | public | function | Returns a stub translation manager that just returns the passed string. | ||
| UnitTestCase::setDebugDumpHandler | public static | function | Registers the dumper CLI handler when the DebugDump extension is enabled. | ||
| UnitTestCase::setUp | protected | function | 366 | ||
| UnitTestCase::setupMockIterator | protected | function | Set up a traversable class mock to return specific items when iterated. | ||
| ValidateHostnameTest::providerTestValidateHostname | public static | function | Provides test data for testValidateHostname(). | ||
| ValidateHostnameTest::testValidateHostname | public | function | Tests validate hostname. |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.