bug #17925 [Bridge] The WebProcessor now forwards the client IP (magnetik)
This PR was submitted for the master branch but it was merged into the 2.3 branch instead (closes #17925).
Discussion
----------
[Bridge] The WebProcessor now forwards the client IP
| Q | A
| ------------- | ---
| Bug fix? | yes
| New feature? | yes
| BC breaks? | yes
| Deprecations? | yes
| Tests pass? | yes
| Fixed tickets | #17905
| License | MIT
Commits
-------
e740852
The WebProcessor now forwards the client IP
This commit is contained in:
commit
afa4d524c2
@ -32,6 +32,7 @@ class WebProcessor extends BaseWebProcessor
|
||||
{
|
||||
if (HttpKernelInterface::MASTER_REQUEST === $event->getRequestType()) {
|
||||
$this->serverData = $event->getRequest()->server->all();
|
||||
$this->serverData['REMOTE_ADDR'] = $event->getRequest()->getClientIp();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -34,6 +34,23 @@ class WebProcessorTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertEquals($server['HTTP_REFERER'], $record['extra']['referrer']);
|
||||
}
|
||||
|
||||
public function testUseRequestClientIp()
|
||||
{
|
||||
Request::setTrustedProxies(['192.168.0.1']);
|
||||
list($event, $server) = $this->createRequestEvent(array('X_FORWARDED_FOR' => '192.168.0.2'));
|
||||
|
||||
$processor = new WebProcessor();
|
||||
$processor->onKernelRequest($event);
|
||||
$record = $processor($this->getRecord());
|
||||
|
||||
$this->assertCount(5, $record['extra']);
|
||||
$this->assertEquals($server['REQUEST_URI'], $record['extra']['url']);
|
||||
$this->assertEquals($server['X_FORWARDED_FOR'], $record['extra']['ip']);
|
||||
$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']);
|
||||
}
|
||||
|
||||
public function testCanBeConstructedWithExtraFields()
|
||||
{
|
||||
if (!$this->isExtraFieldsSupported()) {
|
||||
@ -54,18 +71,22 @@ class WebProcessorTest extends \PHPUnit_Framework_TestCase
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
private function createRequestEvent()
|
||||
private function createRequestEvent($additionalServerParameters = array())
|
||||
{
|
||||
$server = array(
|
||||
'REQUEST_URI' => 'A',
|
||||
'REMOTE_ADDR' => 'B',
|
||||
'REQUEST_METHOD' => 'C',
|
||||
'SERVER_NAME' => 'D',
|
||||
'HTTP_REFERER' => 'E',
|
||||
$server = array_merge(
|
||||
array(
|
||||
'REQUEST_URI' => 'A',
|
||||
'REMOTE_ADDR' => '192.168.0.1',
|
||||
'REQUEST_METHOD' => 'C',
|
||||
'SERVER_NAME' => 'D',
|
||||
'HTTP_REFERER' => 'E',
|
||||
),
|
||||
$additionalServerParameters
|
||||
);
|
||||
|
||||
$request = new Request();
|
||||
$request->server->replace($server);
|
||||
$request->headers->replace($server);
|
||||
|
||||
$event = $this->getMockBuilder('Symfony\Component\HttpKernel\Event\GetResponseEvent')
|
||||
->disableOriginalConstructor()
|
||||
|
Reference in New Issue
Block a user