Skip to content

Commit

Permalink
Merge branch '5.4' into 6.3
Browse files Browse the repository at this point in the history
* 5.4:
  [Messenger] Fix cloned TraceableStack not unstacking the stack independently
  [DependencyInjection] Fix autocasting null env values to empty string with container.env_var_processors_locator
  [Cache] Fix support for Redis Sentinel using php-redis 6.0.0
  minor #51693 Disable the dead code analysis in Psalm (stof)
  Update the PR template
  [SecurityBundle][PasswordHasher] Fix password migration with custom hasher service with security bundle config
  [Translator] Fix support for `default_path` in XML
  [HttpClient] Fix TraceableResponse if response has no destruct method
  • Loading branch information
nicolas-grekas committed Sep 25, 2023
2 parents 93b1bef + 8f432fa commit a1a5eea
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
5 changes: 4 additions & 1 deletion DependencyInjection/SecurityExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,10 @@ private function createHasher(array $config): Reference|array
{
// a custom hasher service
if (isset($config['id'])) {
return new Reference($config['id']);
return $config['migrate_from'] ?? false ? [
'instance' => new Reference($config['id']),
'migrate_from' => $config['migrate_from'],
] : new Reference($config['id']);
}

if ($config['migrate_from'] ?? false) {
Expand Down
27 changes: 27 additions & 0 deletions Tests/DependencyInjection/SecurityExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -887,6 +887,33 @@ public function testNothingDoneWithEmptyConfiguration()
$this->assertFalse($container->has('security.authorization_checker'));
}

public function testCustomHasherWithMigrateFrom()
{
$container = $this->getRawContainer();

$container->loadFromExtension('security', [
'enable_authenticator_manager' => true,
'password_hashers' => [
'legacy' => 'md5',
'App\User' => [
'id' => 'App\Security\CustomHasher',
'migrate_from' => 'legacy',
],
],
'firewalls' => ['main' => ['http_basic' => true]],
]);

$container->compile();

$hashersMap = $container->getDefinition('security.password_hasher_factory')->getArgument(0);

$this->assertArrayHasKey('App\User', $hashersMap);
$this->assertEquals($hashersMap['App\User'], [
'instance' => new Reference('App\Security\CustomHasher'),
'migrate_from' => ['legacy'],
]);
}

protected function getRawContainer()
{
$container = new ContainerBuilder();
Expand Down

0 comments on commit a1a5eea

Please sign in to comment.