|
21 | 21 | use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; |
22 | 22 | use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; |
23 | 23 | use Symfony\Component\Security\Core\Exception\LogoutException; |
| 24 | +use Symfony\Component\Security\Csrf\CsrfToken; |
24 | 25 | use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface; |
25 | 26 | use Symfony\Component\Security\Http\Event\LogoutEvent; |
26 | 27 | use Symfony\Component\Security\Http\Firewall\LogoutListener; |
@@ -82,6 +83,49 @@ public function testHandleMatchedPathWithCsrfValidation() |
82 | 83 | $this->assertSame($response, $event->getResponse()); |
83 | 84 | } |
84 | 85 |
|
| 86 | + public function testHandleMatchedPathWithCsrfInQueryParamAndBody() |
| 87 | + { |
| 88 | + $tokenManager = $this->getTokenManager(); |
| 89 | + $dispatcher = $this->getEventDispatcher(); |
| 90 | + |
| 91 | + [$listener, $tokenStorage, $httpUtils, $options] = $this->getListener($dispatcher, $tokenManager); |
| 92 | + |
| 93 | + $request = new Request(); |
| 94 | + $request->query->set('_csrf_token', 'token'); |
| 95 | + $request->request->set('_csrf_token', 'token2'); |
| 96 | + |
| 97 | + $httpUtils->expects($this->once()) |
| 98 | + ->method('checkRequestPath') |
| 99 | + ->with($request, $options['logout_path']) |
| 100 | + ->willReturn(true); |
| 101 | + |
| 102 | + $tokenManager->expects($this->once()) |
| 103 | + ->method('isTokenValid') |
| 104 | + ->with($this->callback(function ($token) { |
| 105 | + return $token instanceof CsrfToken && 'token2' === $token->getValue(); |
| 106 | + })) |
| 107 | + ->willReturn(true); |
| 108 | + |
| 109 | + $response = new Response(); |
| 110 | + $dispatcher->addListener(LogoutEvent::class, function (LogoutEvent $event) use ($response) { |
| 111 | + $event->setResponse($response); |
| 112 | + }); |
| 113 | + |
| 114 | + $tokenStorage->expects($this->once()) |
| 115 | + ->method('getToken') |
| 116 | + ->willReturn($token = $this->getToken()); |
| 117 | + |
| 118 | + $tokenStorage->expects($this->once()) |
| 119 | + ->method('setToken') |
| 120 | + ->with(null); |
| 121 | + |
| 122 | + $event = new RequestEvent($this->createMock(HttpKernelInterface::class), $request, HttpKernelInterface::MAIN_REQUEST); |
| 123 | + |
| 124 | + $listener($event); |
| 125 | + |
| 126 | + $this->assertSame($response, $event->getResponse()); |
| 127 | + } |
| 128 | + |
85 | 129 | public function testHandleMatchedPathWithoutCsrfValidation() |
86 | 130 | { |
87 | 131 | $dispatcher = $this->getEventDispatcher(); |
|
0 commit comments