Skip to content

Commit

Permalink
[Security] Correctly initialize the voter property
Browse files Browse the repository at this point in the history
  • Loading branch information
aschempp authored and nicolas-grekas committed Mar 14, 2024
1 parent 10d7d43 commit b184401
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ public function collect(Request $request, Response $response, ?\Throwable $excep
// collect voters and access decision manager information
if ($this->accessDecisionManager instanceof TraceableAccessDecisionManager) {
$this->data['voter_strategy'] = $this->accessDecisionManager->getStrategy();
$this->data['voters'] = [];

foreach ($this->accessDecisionManager->getVoters() as $voter) {
if ($voter instanceof TraceableVoter) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,36 @@ public function dispatch(object $event, ?string $eventName = null): object
$this->assertSame($dataCollector->getVoterStrategy(), $strategy, 'Wrong value returned by getVoterStrategy');
}

public function testGetVotersIfAccessDecisionManagerHasNoVoters()
{
$strategy = MainConfiguration::STRATEGY_AFFIRMATIVE;

$accessDecisionManager = $this->createMock(TraceableAccessDecisionManager::class);

$accessDecisionManager
->method('getStrategy')
->willReturn($strategy);

$accessDecisionManager
->method('getVoters')
->willReturn([]);

$accessDecisionManager
->method('getDecisionLog')
->willReturn([[
'attributes' => ['view'],
'object' => new \stdClass(),
'result' => true,
'voterDetails' => [],
]]);

$dataCollector = new SecurityDataCollector(null, null, null, $accessDecisionManager, null, null, true);

$dataCollector->collect(new Request(), new Response());

$this->assertEmpty($dataCollector->getVoters());
}

public static function provideRoles(): array
{
return [
Expand Down

0 comments on commit b184401

Please sign in to comment.