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

Skip to content

Commit e87be57

Browse files
committed
[Security\Http] Skip remember-me logout on empty token
1 parent 309b062 commit e87be57

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

src/Symfony/Component/Security/Http/EventListener/RememberMeLogoutListener.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ public function onLogout(LogoutEvent $event): void
4040
return;
4141
}
4242

43+
if (!$event->getToken()) {
44+
return;
45+
}
46+
4347
if (null === $event->getResponse()) {
4448
throw new LogicException(sprintf('No response was set for this logout action. Make sure the DefaultLogoutListener or another listener has set the response before "%s" is called.', __CLASS__));
4549
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
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\Security\Http\Tests\EventListener;
13+
14+
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\HttpFoundation\Request;
16+
use Symfony\Component\Security\Http\Event\LogoutEvent;
17+
use Symfony\Component\Security\Http\EventListener\RememberMeLogoutListener;
18+
use Symfony\Component\Security\Http\RememberMe\AbstractRememberMeServices;
19+
20+
class RememberMeLogoutListenerTest extends TestCase
21+
{
22+
public function testOnLogoutDoesNothingIfNoToken()
23+
{
24+
$rememberMeServices = $this->createMock(AbstractRememberMeServices::class);
25+
$rememberMeServices->expects($this->never())->method('logout');
26+
27+
$rememberMeLogoutListener = new RememberMeLogoutListener($rememberMeServices);
28+
$rememberMeLogoutListener->onLogout(new LogoutEvent(new Request(),null));
29+
}
30+
}

0 commit comments

Comments
 (0)