[Security\Http] Skip remember-me logout on empty token

This commit is contained in:
Robin Chalas 2020-07-06 12:01:01 +02:00
parent 309b06201a
commit 551f9418a3
2 changed files with 34 additions and 0 deletions

View File

@ -40,6 +40,10 @@ class RememberMeLogoutListener implements EventSubscriberInterface
return;
}
if (!$event->getToken()) {
return;
}
if (null === $event->getResponse()) {
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__));
}

View File

@ -0,0 +1,30 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Security\Http\Tests\EventListener;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Security\Http\Event\LogoutEvent;
use Symfony\Component\Security\Http\EventListener\RememberMeLogoutListener;
use Symfony\Component\Security\Http\RememberMe\AbstractRememberMeServices;
class RememberMeLogoutListenerTest extends TestCase
{
public function testOnLogoutDoesNothingIfNoToken()
{
$rememberMeServices = $this->createMock(AbstractRememberMeServices::class);
$rememberMeServices->expects($this->never())->method('logout');
$rememberMeLogoutListener = new RememberMeLogoutListener($rememberMeServices);
$rememberMeLogoutListener->onLogout(new LogoutEvent(new Request(), null));
}
}