Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b013a88

Browse files
Fix setting the IP address on the user context when it's not available (getsentry#565)
Co-authored-by: Stefano Arlandini <[email protected]>
1 parent 42787b4 commit b013a88

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## Unreleased
44

55
- Add return typehints to the methods of the `SentryExtension` class to prepare for Symfony 6 (#563)
6+
- Fix setting the IP address on the user context when it's not available (#565)
67

78
## 4.2.3 (2021-09-21)
89

src/EventListener/RequestListener.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ public function handleKernelRequestEvent(RequestListenerRequestEvent $event): vo
6060
}
6161

6262
$token = null;
63-
$userData = UserDataBag::createFromUserIpAddress($event->getRequest()->getClientIp());
63+
$userData = new UserDataBag();
64+
$userData->setIpAddress($event->getRequest()->getClientIp());
6465

6566
if (null !== $this->tokenStorage) {
6667
$token = $this->tokenStorage->getToken();

tests/EventListener/RequestListenerTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,17 @@ public function getCredentials()
420420
},
421421
new UserDataBag(null, null, '127.0.0.1', 'foo_user'),
422422
];
423+
424+
yield 'request.clientIp IS NULL' => [
425+
new RequestEvent(
426+
$this->createMock(HttpKernelInterface::class),
427+
new Request(),
428+
HttpKernelInterface::MASTER_REQUEST
429+
),
430+
$this->getMockedClientWithOptions(new Options(['send_default_pii' => true])),
431+
null,
432+
new UserDataBag(),
433+
];
423434
}
424435

425436
/**

0 commit comments

Comments
 (0)