public function DrupalKernelTest::testTrustedHosts in Drupal 8
Same name and namespace in other branches
- 9 core/tests/Drupal/Tests/Core/DrupalKernel/DrupalKernelTest.php \Drupal\Tests\Core\DrupalKernel\DrupalKernelTest::testTrustedHosts()
- 10 core/tests/Drupal/Tests/Core/DrupalKernel/DrupalKernelTest.php \Drupal\Tests\Core\DrupalKernel\DrupalKernelTest::testTrustedHosts()
Tests hostname validation with settings.
@covers ::setupTrustedHosts @dataProvider providerTestTrustedHosts
File
- core/
tests/ Drupal/ Tests/ Core/ DrupalKernel/ DrupalKernelTest.php, line 23
Class
- DrupalKernelTest
- @coversDefaultClass \Drupal\Core\DrupalKernel @group DrupalKernel
Namespace
Drupal\Tests\Core\DrupalKernelCode
public function testTrustedHosts($host, $server_name, $message, $expected = FALSE) {
$request = new Request();
$trusted_host_patterns = [
'^example\\.com$',
'^.+\\.example\\.com$',
'^example\\.org',
'^.+\\.example\\.org',
];
if (!empty($host)) {
$request->headers
->set('HOST', $host);
}
$request->server
->set('SERVER_NAME', $server_name);
$method = new \ReflectionMethod('Drupal\\Core\\DrupalKernel', 'setupTrustedHosts');
$method
->setAccessible(TRUE);
$valid_host = $method
->invoke(NULL, $request, $trusted_host_patterns);
$this
->assertSame($expected, $valid_host, $message);
// Reset the trusted hosts because it is statically stored on the request.
$method
->invoke(NULL, $request, []);
// Reset the request factory because it is statically stored on the request.
Request::setFactory(NULL);
}