Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Security/Http] don't require the session to be started when tracking its id #36118

Merged
merged 1 commit into from Mar 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -115,10 +115,10 @@ public function authenticate(RequestEvent $event)

if (null !== $session) {
$usageIndexValue = method_exists(Request::class, 'getPreferredFormat') && $session instanceof Session ? $usageIndexReference = &$session->getUsageIndex() : 0;
$sessionId = $session->getId();
$sessionId = $request->cookies->get($session->getName());
$token = $session->get($this->sessionKey);

if ($this->sessionTrackerEnabler && $session->getId() === $sessionId) {
if ($this->sessionTrackerEnabler && \in_array($sessionId, [true, $session->getId()], true)) {
$usageIndexReference = $usageIndexValue;
}
}
Expand Down
Expand Up @@ -344,6 +344,26 @@ public function testDeauthenticatedEvent()
$this->assertNull($tokenStorage->getToken());
}

/**
* @requires function \Symfony\Component\HttpFoundation\Request::getPreferredFormat
*/
public function testWithPreviousNotStartedSession()
{
$session = new Session(new MockArraySessionStorage());

$request = new Request();
$request->setSession($session);
$request->cookies->set('MOCKSESSID', true);

$usageIndex = $session->getUsageIndex();

$tokenStorage = new TokenStorage();
$listener = new ContextListener($tokenStorage, [], 'context_key', null, null, null, [$tokenStorage, 'getToken']);
$listener(new RequestEvent($this->getMockBuilder(HttpKernelInterface::class)->getMock(), $request, HttpKernelInterface::MASTER_REQUEST));

$this->assertSame($usageIndex, $session->getUsageIndex());
}

protected function runSessionOnKernelResponse($newToken, $original = null)
{
$session = new Session(new MockArraySessionStorage());
Expand Down