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