[HttpKernel] Fix restoring trusted proxies in tests
This commit is contained in:
parent
b1f60216a4
commit
efe9beb186
@ -49,6 +49,8 @@ class WebProcessorTest extends TestCase
|
||||
$this->assertEquals($server['REQUEST_METHOD'], $record['extra']['http_method']);
|
||||
$this->assertEquals($server['SERVER_NAME'], $record['extra']['server']);
|
||||
$this->assertEquals($server['HTTP_REFERER'], $record['extra']['referrer']);
|
||||
|
||||
Request::setTrustedProxies(array());
|
||||
}
|
||||
|
||||
public function testCanBeConstructedWithExtraFields()
|
||||
|
@ -20,6 +20,7 @@ class RequestTest extends TestCase
|
||||
{
|
||||
protected function tearDown()
|
||||
{
|
||||
Request::setTrustedProxies(array());
|
||||
Request::setTrustedHosts(array());
|
||||
}
|
||||
|
||||
@ -750,8 +751,6 @@ class RequestTest extends TestCase
|
||||
));
|
||||
$port = $request->getPort();
|
||||
$this->assertEquals(80, $port, 'With only PROTO set and value is not recognized, getPort() defaults to 80.');
|
||||
|
||||
Request::setTrustedProxies(array());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -827,8 +826,6 @@ class RequestTest extends TestCase
|
||||
$request = $this->getRequestInstanceForClientIpTests($remoteAddr, $httpForwardedFor, $trustedProxies);
|
||||
|
||||
$this->assertEquals($expected[0], $request->getClientIp());
|
||||
|
||||
Request::setTrustedProxies(array());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -839,8 +836,6 @@ class RequestTest extends TestCase
|
||||
$request = $this->getRequestInstanceForClientIpTests($remoteAddr, $httpForwardedFor, $trustedProxies);
|
||||
|
||||
$this->assertEquals($expected, $request->getClientIps());
|
||||
|
||||
Request::setTrustedProxies(array());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -851,8 +846,6 @@ class RequestTest extends TestCase
|
||||
$request = $this->getRequestInstanceForClientIpsForwardedTests($remoteAddr, $httpForwarded, $trustedProxies);
|
||||
|
||||
$this->assertEquals($expected, $request->getClientIps());
|
||||
|
||||
Request::setTrustedProxies(array());
|
||||
}
|
||||
|
||||
public function getClientIpsForwardedProvider()
|
||||
@ -975,8 +968,6 @@ class RequestTest extends TestCase
|
||||
|
||||
$clientIps = $request->getClientIps();
|
||||
|
||||
Request::setTrustedProxies(array());
|
||||
|
||||
$this->assertSame($expectedIps, $clientIps);
|
||||
}
|
||||
|
||||
|
@ -21,6 +21,11 @@ use Symfony\Component\HttpKernel\KernelEvents;
|
||||
|
||||
class ValidateRequestListenerTest extends TestCase
|
||||
{
|
||||
protected function tearDown()
|
||||
{
|
||||
Request::setTrustedProxies(array());
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\HttpFoundation\Exception\ConflictingHeadersException
|
||||
*/
|
||||
|
@ -56,7 +56,6 @@ class InlineFragmentRendererTest extends TestCase
|
||||
$subRequest->attributes->replace(array('object' => $object, '_format' => 'html', '_controller' => 'main_controller', '_locale' => 'en'));
|
||||
$subRequest->headers->set('x-forwarded-for', array('127.0.0.1'));
|
||||
$subRequest->server->set('HTTP_X_FORWARDED_FOR', '127.0.0.1');
|
||||
$subRequest->server->set('REMOTE_ADDR', '1.1.1.1');
|
||||
|
||||
$strategy = new InlineFragmentRenderer($this->getKernelExpectingRequest($subRequest));
|
||||
|
||||
@ -85,7 +84,7 @@ class InlineFragmentRendererTest extends TestCase
|
||||
{
|
||||
Request::setTrustedHeaderName(Request::HEADER_CLIENT_IP, '');
|
||||
|
||||
$strategy = new InlineFragmentRenderer($this->getKernelExpectingRequest(Request::create('/', 'GET', array(), array(), array(), array('REMOTE_ADDR' => '1.1.1.1'))));
|
||||
$strategy = new InlineFragmentRenderer($this->getKernelExpectingRequest(Request::create('/')));
|
||||
$this->assertSame('foo', $strategy->render('/', Request::create('/'))->getContent());
|
||||
}
|
||||
|
||||
@ -169,7 +168,6 @@ class InlineFragmentRendererTest extends TestCase
|
||||
{
|
||||
$expectedSubRequest = Request::create('/');
|
||||
$expectedSubRequest->headers->set('Surrogate-Capability', 'abc="ESI/1.0"');
|
||||
$expectedSubRequest->server->set('REMOTE_ADDR', '1.1.1.1');
|
||||
|
||||
if (Request::getTrustedHeaderName(Request::HEADER_CLIENT_IP)) {
|
||||
$expectedSubRequest->headers->set('x-forwarded-for', array('127.0.0.1'));
|
||||
@ -195,7 +193,7 @@ class InlineFragmentRendererTest extends TestCase
|
||||
|
||||
public function testHeadersPossiblyResultingIn304AreNotAssignedToSubrequest()
|
||||
{
|
||||
$expectedSubRequest = Request::create('/', 'GET', array(), array(), array(), array('REMOTE_ADDR' => '1.1.1.1'));
|
||||
$expectedSubRequest = Request::create('/');
|
||||
if (Request::getTrustedHeaderName(Request::HEADER_CLIENT_IP)) {
|
||||
$expectedSubRequest->headers->set('x-forwarded-for', array('127.0.0.1'));
|
||||
$expectedSubRequest->server->set('HTTP_X_FORWARDED_FOR', '127.0.0.1');
|
||||
@ -206,6 +204,28 @@ class InlineFragmentRendererTest extends TestCase
|
||||
$strategy->render('/', $request);
|
||||
}
|
||||
|
||||
public function testFirstTrustedProxyIsSetAsRemote()
|
||||
{
|
||||
$expectedSubRequest = Request::create('/');
|
||||
$expectedSubRequest->headers->set('Surrogate-Capability', 'abc="ESI/1.0"');
|
||||
$expectedSubRequest->server->set('REMOTE_ADDR', '1.1.1.1');
|
||||
|
||||
if (Request::getTrustedHeaderName(Request::HEADER_CLIENT_IP)) {
|
||||
$expectedSubRequest->headers->set('x-forwarded-for', array('127.0.0.1'));
|
||||
$expectedSubRequest->server->set('HTTP_X_FORWARDED_FOR', '127.0.0.1');
|
||||
}
|
||||
|
||||
Request::setTrustedProxies(array('1.1.1.1'));
|
||||
|
||||
$strategy = new InlineFragmentRenderer($this->getKernelExpectingRequest($expectedSubRequest));
|
||||
|
||||
$request = Request::create('/');
|
||||
$request->headers->set('Surrogate-Capability', 'abc="ESI/1.0"');
|
||||
$strategy->render('/', $request);
|
||||
|
||||
Request::setTrustedProxies(array());
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a Kernel expecting a request equals to $request
|
||||
* Allows delta in comparison in case REQUEST_TIME changed by 1 second.
|
||||
|
@ -1315,6 +1315,8 @@ class HttpCacheTest extends HttpCacheTestCase
|
||||
$this->request('GET', '/', array('REMOTE_ADDR' => '10.0.0.1'));
|
||||
|
||||
$this->assertEquals($expected, Request::getTrustedProxies());
|
||||
|
||||
Request::setTrustedProxies(array());
|
||||
}
|
||||
|
||||
public function getTrustedProxyData()
|
||||
|
@ -291,6 +291,8 @@ class HttpKernelTest extends TestCase
|
||||
$request->headers->set('X_FORWARDED_FOR', '3.3.3.3');
|
||||
|
||||
$kernel->handle($request, $kernel::MASTER_REQUEST, false);
|
||||
|
||||
Request::setTrustedProxies(array());
|
||||
}
|
||||
|
||||
protected function getResolver($controller = null)
|
||||
|
Reference in New Issue
Block a user