function ReverseProxyMiddlewareTest::trustedHeadersAreSet

Same name in other branches
  1. 9 core/tests/Drupal/Tests/Core/StackMiddleware/ReverseProxyMiddlewareTest.php \Drupal\Tests\Core\StackMiddleware\ReverseProxyMiddlewareTest::trustedHeadersAreSet()
  2. 10 core/tests/Drupal/Tests/Core/StackMiddleware/ReverseProxyMiddlewareTest.php \Drupal\Tests\Core\StackMiddleware\ReverseProxyMiddlewareTest::trustedHeadersAreSet()
  3. 11.x core/tests/Drupal/Tests/Core/StackMiddleware/ReverseProxyMiddlewareTest.php \Drupal\Tests\Core\StackMiddleware\ReverseProxyMiddlewareTest::trustedHeadersAreSet()

Tests that trusted headers are set correctly.

\Symfony\Component\HttpFoundation\Request::setTrustedProxies() should always be called when reverse proxy settings are enabled.

Parameters

\Drupal\Core\Site\Settings $settings: The settings object that holds reverse proxy configuration.

int $expected_trusted_header_set: The expected bit value returned by \Symfony\Component\HttpFoundation\Request::getTrustedHeaderSet()

2 calls to ReverseProxyMiddlewareTest::trustedHeadersAreSet()
ReverseProxyMiddlewareTest::testReverseProxyEnabled in core/tests/Drupal/Tests/Core/StackMiddleware/ReverseProxyMiddlewareTest.php
Tests that subscriber sets trusted headers when reverse proxy is set.
ReverseProxyMiddlewareTest::testReverseProxyEnabledLegacy in core/tests/Drupal/Tests/Core/StackMiddleware/ReverseProxyMiddlewareTest.php
Tests that subscriber sets trusted headers when reverse proxy is set.

File

core/tests/Drupal/Tests/Core/StackMiddleware/ReverseProxyMiddlewareTest.php, line 151

Class

ReverseProxyMiddlewareTest
Unit test the reverse proxy stack middleware.

Namespace

Drupal\Tests\Core\StackMiddleware

Code

protected function trustedHeadersAreSet(Settings $settings, $expected_trusted_header_set) {
    $middleware = new ReverseProxyMiddleware($this->mockHttpKernel, $settings);
    $request = new Request();
    $middleware->handle($request);
    $this->assertSame($settings->get('reverse_proxy_addresses'), $request->getTrustedProxies());
    $this->assertSame($expected_trusted_header_set, $request->getTrustedHeaderSet());
}

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