@@ -323,6 +323,105 @@ public function provideAdditionalRequestMatcherConstraints()
323
323
yield 'Invalid configuration with port ' => [['port ' => 80 ]];
324
324
yield 'Invalid configuration with methods ' => [['methods ' => ['POST ' ]]];
325
325
yield 'Invalid configuration with ips ' => [['ips ' => ['0.0.0.0 ' ]]];
326
+ yield 'Invalid configuration with attributes ' => [['attributes ' => ['_route ' => 'foo_route ' ]]];
327
+ yield 'Invalid configuration with route ' => [['route ' => 'foo_route ' ]];
328
+ }
329
+
330
+ public function testRegisterAccessControlWithSpecifiedAttributes ()
331
+ {
332
+ $ container = $ this ->getRawContainer ();
333
+ $ container ->loadFromExtension ('security ' , [
334
+ 'enable_authenticator_manager ' => true ,
335
+ 'providers ' => [
336
+ 'default ' => ['id ' => 'foo ' ],
337
+ ],
338
+ 'firewalls ' => [
339
+ 'some_firewall ' => [
340
+ 'pattern ' => '/.* ' ,
341
+ 'http_basic ' => [],
342
+ ],
343
+ ],
344
+ 'access_control ' => [
345
+ ['attributes ' => ['_route ' => 'foo_route ' ]],
346
+ ],
347
+ ]);
348
+
349
+ $ container ->compile ();
350
+
351
+ $ accessMap = $ container ->getDefinition ('security.access_map ' );
352
+ $ this ->assertCount (1 , $ accessMap ->getMethodCalls ());
353
+ $ call = $ accessMap ->getMethodCalls ()[0 ];
354
+ $ this ->assertSame ('add ' , $ call [0 ]);
355
+ $ args = $ call [1 ];
356
+ $ requestMatcherId = (string ) $ args [0 ];
357
+
358
+ $ requestMatcherDefinition = $ container ->getDefinition ($ requestMatcherId );
359
+ $ requestMatcherConstructorArguments = $ requestMatcherDefinition ->getArguments ();
360
+ $ this ->assertArrayHasKey (4 , $ requestMatcherConstructorArguments );
361
+ $ attributes = $ requestMatcherConstructorArguments [4 ];
362
+ $ this ->assertArrayHasKey ('_route ' , $ attributes );
363
+ $ this ->assertSame ('foo_route ' , $ attributes ['_route ' ]);
364
+ }
365
+
366
+ public function testRegisterAccessControlWithSpecifiedRoute ()
367
+ {
368
+ $ container = $ this ->getRawContainer ();
369
+ $ container ->loadFromExtension ('security ' , [
370
+ 'enable_authenticator_manager ' => true ,
371
+ 'providers ' => [
372
+ 'default ' => ['id ' => 'foo ' ],
373
+ ],
374
+ 'firewalls ' => [
375
+ 'some_firewall ' => [
376
+ 'pattern ' => '/.* ' ,
377
+ 'http_basic ' => [],
378
+ ],
379
+ ],
380
+ 'access_control ' => [
381
+ ['route ' => 'foo_route ' ],
382
+ ],
383
+ ]);
384
+
385
+ $ container ->compile ();
386
+
387
+ $ accessMap = $ container ->getDefinition ('security.access_map ' );
388
+ $ this ->assertCount (1 , $ accessMap ->getMethodCalls ());
389
+ $ call = $ accessMap ->getMethodCalls ()[0 ];
390
+ $ this ->assertSame ('add ' , $ call [0 ]);
391
+ $ args = $ call [1 ];
392
+ $ requestMatcherId = (string ) $ args [0 ];
393
+
394
+ $ requestMatcherDefinition = $ container ->getDefinition ($ requestMatcherId );
395
+ $ requestMatcherConstructorArguments = $ requestMatcherDefinition ->getArguments ();
396
+ $ this ->assertArrayHasKey (4 , $ requestMatcherConstructorArguments );
397
+ $ attributes = $ requestMatcherConstructorArguments [4 ];
398
+ $ this ->assertArrayHasKey ('_route ' , $ attributes );
399
+ $ this ->assertSame ('foo_route ' , $ attributes ['_route ' ]);
400
+ }
401
+
402
+ public function testRegisterAccessControlWithSpecifiedAttributesThrowsException ()
403
+ {
404
+ $ container = $ this ->getRawContainer ();
405
+ $ container ->loadFromExtension ('security ' , [
406
+ 'enable_authenticator_manager ' => true ,
407
+ 'providers ' => [
408
+ 'default ' => ['id ' => 'foo ' ],
409
+ ],
410
+ 'firewalls ' => [
411
+ 'some_firewall ' => [
412
+ 'pattern ' => '/.* ' ,
413
+ 'http_basic ' => [],
414
+ ],
415
+ ],
416
+ 'access_control ' => [
417
+ ['route ' => 'anything ' , 'attributes ' => ['_route ' => 'foo_route ' ]],
418
+ ],
419
+ ]);
420
+
421
+ $ this ->expectException (InvalidConfigurationException::class);
422
+ $ this ->expectExceptionMessage ('The "route" option should not be specified alongside "attributes._route" option. Use just one of the options. ' );
423
+
424
+ $ container ->compile ();
326
425
}
327
426
328
427
public function testRemovesExpressionCacheWarmerDefinitionIfNoExpressions ()
0 commit comments