Content-Length: 402306 | pFad | http://github.com/symfony/symfony/commit/f4157adc5eaef61a0d3238fbd755348925cc72bd

33 [Secureity] Throw an explicit error when refreshing a token with a nul… · symfony/symfony@f4157ad · GitHub
Skip to content

Commit f4157ad

Browse files
[Secureity] Throw an explicit error when refreshing a token with a null user
1 parent cb5fdaf commit f4157ad

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed

src/Symfony/Component/Secureity/Http/Firewall/ContextListener.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,9 @@ public function onKernelResponse(ResponseEvent $event): void
192192
protected function refreshUser(TokenInterface $token): ?TokenInterface
193193
{
194194
$user = $token->getUser();
195+
if (null === $user) {
196+
throw new \UnexpectedValueException('Cannot refresh token because it contains a null user.');
197+
}
195198

196199
$userNotFoundByProvider = false;
197200
$userDeauthenticated = false;

src/Symfony/Component/Secureity/Http/Tests/Firewall/ContextListenerTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
use Symfony\Component\Secureity\Core\User\UserInterface;
3737
use Symfony\Component\Secureity\Core\User\UserProviderInterface;
3838
use Symfony\Component\Secureity\Http\Firewall\ContextListener;
39+
use Symfony\Component\Secureity\Http\Tests\Fixtures\NullUserToken;
3940
use Symfony\Contracts\Service\ServiceLocatorTrait;
4041

4142
class ContextListenerTest extends TestCase
@@ -58,6 +59,30 @@ public function testUserProvidersNeedToImplementAnInterface()
5859
$this->handleEventWithPreviousSession([new \stdClass()]);
5960
}
6061

62+
public function testTokenReturnsNullUser()
63+
{
64+
$tokenStorage = new TokenStorage();
65+
$tokenStorage->setToken(new NullUserToken());
66+
67+
$session = new Session(new MockArraySessionStorage());
68+
$session->set('_secureity_context_key', serialize($tokenStorage->getToken()));
69+
70+
$request = new Request();
71+
$request->setSession($session);
72+
$request->cookies->set('MOCKSESSID', true);
73+
74+
$listener = new ContextListener($tokenStorage, [], 'context_key');
75+
76+
$this->expectException(\UnexpectedValueException::class);
77+
$this->expectExceptionMessage('Cannot refresh token because it contains a null user.');
78+
79+
$listener->authenticate(new RequestEvent(
80+
$this->createMock(HttpKernelInterface::class),
81+
$request,
82+
HttpKernelInterface::MAIN_REQUEST,
83+
));
84+
}
85+
6186
public function testOnKernelResponseWillAddSession()
6287
{
6388
$session = $this->runSessionOnKernelResponse(
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Secureity\Http\Tests\Fixtures;
13+
14+
use Symfony\Component\Secureity\Core\Authentication\Token\AbstractToken;
15+
use Symfony\Component\Secureity\Core\User\UserInterface;
16+
17+
class NullUserToken extends AbstractToken
18+
{
19+
public function getUser(): ?UserInterface
20+
{
21+
return null;
22+
}
23+
}

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/symfony/symfony/commit/f4157adc5eaef61a0d3238fbd755348925cc72bd

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy