|
11 | 11 |
|
12 | 12 | namespace Symfony\Component\Security\Http\Tests\Firewall;
|
13 | 13 |
|
| 14 | +use PHPUnit\Framework\Assert; |
14 | 15 | use PHPUnit\Framework\TestCase;
|
15 | 16 | use Symfony\Component\EventDispatcher\EventDispatcher;
|
16 | 17 | use Symfony\Component\HttpFoundation\Request;
|
|
24 | 25 | use Symfony\Component\Security\Core\Authentication\Token\AnonymousToken;
|
25 | 26 | use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage;
|
26 | 27 | use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
|
| 28 | +use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; |
27 | 29 | use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
|
28 | 30 | use Symfony\Component\Security\Core\Exception\UnsupportedUserException;
|
29 | 31 | use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
|
30 | 32 | use Symfony\Component\Security\Core\User\User;
|
31 | 33 | use Symfony\Component\Security\Core\User\UserInterface;
|
32 | 34 | use Symfony\Component\Security\Core\User\UserProviderInterface;
|
33 | 35 | use Symfony\Component\Security\Http\Firewall\ContextListener;
|
| 36 | +use Symfony\Component\Security\Http\RememberMe\RememberMeServicesInterface; |
| 37 | +use Symfony\Component\Security\Http\Tests\RememberMe\AbstractRememberMeServicesTest; |
34 | 38 |
|
35 | 39 | class ContextListenerTest extends TestCase
|
36 | 40 | {
|
@@ -316,6 +320,26 @@ public function testRuntimeExceptionIsThrownIfNoSupportingUserProviderWasRegiste
|
316 | 320 | $this->handleEventWithPreviousSession(new TokenStorage(), [new NotSupportingUserProvider(), new NotSupportingUserProvider()]);
|
317 | 321 | }
|
318 | 322 |
|
| 323 | + public function testLogoutOnChangeEventAsBeenSent() |
| 324 | + { |
| 325 | + $tokenStorage = new TokenStorage(); |
| 326 | + $refreshedUser = new User('foobar', 'baz'); |
| 327 | + |
| 328 | + $user = new User('foo', 'bar'); |
| 329 | + |
| 330 | + $session = new Session(new MockArraySessionStorage()); |
| 331 | + $session->set('_security_context_key', serialize(new UsernamePasswordToken($user, '', 'context_key', ['ROLE_USER']))); |
| 332 | + |
| 333 | + $request = new Request(); |
| 334 | + $request->setSession($session); |
| 335 | + $request->cookies->set('MOCKSESSID', true); |
| 336 | + $listener = new ContextListener($tokenStorage, [new NotSupportingUserProvider(), new SupportingUserProvider($refreshedUser)], 'context_key', null, null, null, new testRememberMeServices($this)); |
| 337 | + $listener->setLogoutOnUserChange($refreshedUser); |
| 338 | + $listener->handle(new GetResponseEvent($this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock(), $request, HttpKernelInterface::MASTER_REQUEST)); |
| 339 | + |
| 340 | + $this->assertNull($tokenStorage->getToken()); |
| 341 | + } |
| 342 | + |
319 | 343 | public function testAcceptsProvidersAsTraversable()
|
320 | 344 | {
|
321 | 345 | $tokenStorage = new TokenStorage();
|
@@ -387,6 +411,24 @@ public function supportsClass($class)
|
387 | 411 | }
|
388 | 412 | }
|
389 | 413 |
|
| 414 | +class testRememberMeServices implements RememberMeServicesInterface |
| 415 | +{ |
| 416 | + |
| 417 | + public function autoLogin(Request $request) |
| 418 | + { |
| 419 | + } |
| 420 | + |
| 421 | + public function loginFail(Request $request, \Exception $exception = null) |
| 422 | + { |
| 423 | + Assert::assertTrue($request->cookies->get('MOCKSESSID')); |
| 424 | + return null; |
| 425 | + } |
| 426 | + |
| 427 | + public function loginSuccess(Request $request, Response $response, TokenInterface $token) |
| 428 | + { |
| 429 | + } |
| 430 | +} |
| 431 | + |
390 | 432 | class SupportingUserProvider implements UserProviderInterface
|
391 | 433 | {
|
392 | 434 | private $refreshedUser;
|
|
0 commit comments