Skip to content

Commit ec51c23

Browse files
committed
Fixes
1 parent 8f18406 commit ec51c23

File tree

2 files changed

+10
-17
lines changed

2 files changed

+10
-17
lines changed

src/Symfony/Component/Security/Http/Attribute/IsCsrfTokenValid.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function __construct(
2929
/**
3030
* Sets the key of the request that contains the actual token value that should be validated.
3131
*/
32-
public string $tokenKey = '_token',
32+
public ?string $tokenKey = '_token',
3333

3434
/**
3535
* Sets the available http methods that can be used to validate the token.

src/Symfony/Component/Security/Http/Tests/EventListener/IsCsrfTokenValidAttributeListenerTest.php

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,7 @@ public function testNothingHappensWithNoConfig()
5353
{
5454
$csrfTokenManager = $this->createMock(CsrfTokenManagerInterface::class);
5555
$csrfTokenManager->expects($this->never())
56-
->method('isTokenValid')
57-
->withAnyParameters();
56+
->method('isTokenValid');
5857

5958
$event = new ControllerArgumentsEvent(
6059
$this->createMock(HttpKernelInterface::class),
@@ -165,16 +164,15 @@ public function testIsCsrfTokenValidCalledCorrectlyWithCustomTokenKey()
165164
$listener->onKernelControllerArguments($event);
166165
}
167166

168-
public function testIsCsrfTokenValidThrowExceptionWhenInvalidToken()
167+
public function testIsCsrfTokenValidThrowExceptionWhenInvalidMatchingToken()
169168
{
170169
$this->expectException(InvalidCsrfTokenException::class);
171170

172171
$request = new Request(request: ['_token' => 'bar']);
173172

174173
$csrfTokenManager = $this->createMock(CsrfTokenManagerInterface::class);
175174
$csrfTokenManager->expects($this->never())
176-
->method('isTokenValid')
177-
->withAnyParameters();
175+
->method('isTokenValid');
178176

179177
$event = new ControllerArgumentsEvent(
180178
$this->createMock(HttpKernelInterface::class),
@@ -188,14 +186,13 @@ public function testIsCsrfTokenValidThrowExceptionWhenInvalidToken()
188186
$listener->onKernelControllerArguments($event);
189187
}
190188

191-
public function testIsCsrfTokenValidThrowExceptionWhenInvalidToken2()
189+
public function testIsCsrfTokenValidThrowExceptionWhenMissingRequestToken()
192190
{
193191
$this->expectException(InvalidCsrfTokenException::class);
194192

195193
$csrfTokenManager = $this->createMock(CsrfTokenManagerInterface::class);
196194
$csrfTokenManager->expects($this->never())
197-
->method('isTokenValid')
198-
->withAnyParameters();
195+
->method('isTokenValid');
199196

200197
$event = new ControllerArgumentsEvent(
201198
$this->createMock(HttpKernelInterface::class),
@@ -239,8 +236,7 @@ public function testIsCsrfTokenValidIgnoredWithNonMatchingMethod()
239236

240237
$csrfTokenManager = $this->createMock(CsrfTokenManagerInterface::class);
241238
$csrfTokenManager->expects($this->never())
242-
->method('isTokenValid')
243-
->withAnyParameters();
239+
->method('isTokenValid');
244240

245241
$event = new ControllerArgumentsEvent(
246242
$this->createMock(HttpKernelInterface::class),
@@ -284,8 +280,7 @@ public function testIsCsrfTokenValidIgnoredWithGetOrPostMethodWithPutMethod()
284280

285281
$csrfTokenManager = $this->createMock(CsrfTokenManagerInterface::class);
286282
$csrfTokenManager->expects($this->never())
287-
->method('isTokenValid')
288-
->withAnyParameters();
283+
->method('isTokenValid');
289284

290285
$event = new ControllerArgumentsEvent(
291286
$this->createMock(HttpKernelInterface::class),
@@ -308,8 +303,7 @@ public function testIsCsrfTokenValidThrowExceptionWithInvalidTokenKeyAndPostMeth
308303

309304
$csrfTokenManager = $this->createMock(CsrfTokenManagerInterface::class);
310305
$csrfTokenManager->expects($this->never())
311-
->method('isTokenValid')
312-
->withAnyParameters();
306+
->method('isTokenValid');
313307

314308
$event = new ControllerArgumentsEvent(
315309
$this->createMock(HttpKernelInterface::class),
@@ -330,8 +324,7 @@ public function testIsCsrfTokenValidIgnoredWithInvalidTokenKeyAndUnavailableMeth
330324

331325
$csrfTokenManager = $this->createMock(CsrfTokenManagerInterface::class);
332326
$csrfTokenManager->expects($this->never())
333-
->method('isTokenValid')
334-
->withAnyParameters();
327+
->method('isTokenValid');
335328

336329
$event = new ControllerArgumentsEvent(
337330
$this->createMock(HttpKernelInterface::class),

0 commit comments

Comments
 (0)