Merge branch '4.4' into 5.0

* 4.4:
  [HttpKernel] Make ErrorListener::onKernelException()'s dispatcher argument explicit
  Removed extra whitespace
  [Security] Fix best encoder not wired using migrate_from
This commit is contained in:
Nicolas Grekas 2019-11-18 08:34:28 +01:00
commit 15f7ea1362
4 changed files with 7 additions and 7 deletions

View File

@ -52,7 +52,7 @@ class HtmlErrorRenderer implements ErrorRendererInterface
/**
* {@inheritdoc}
*/
public function render(\Throwable $exception): FlattenException
public function render(\Throwable $exception): FlattenException
{
$exception = FlattenException::createFromThrowable($exception, null, [
'Content-Type' => 'text/html; charset='.$this->charset,

View File

@ -46,7 +46,7 @@ class ErrorListener implements EventSubscriberInterface
$this->logException($event->getThrowable(), sprintf('Uncaught PHP Exception %s: "%s" at %s line %s', $e->getClass(), $e->getMessage(), $e->getFile(), $e->getLine()));
}
public function onKernelException(ExceptionEvent $event)
public function onKernelException(ExceptionEvent $event, string $eventName = null, EventDispatcherInterface $eventDispatcher = null)
{
if (null === $this->controller) {
return;
@ -54,7 +54,6 @@ class ErrorListener implements EventSubscriberInterface
$exception = $event->getThrowable();
$request = $this->duplicateRequest($exception, $event->getRequest());
$eventDispatcher = \func_num_args() > 2 ? func_get_arg(2) : null;
try {
$response = $event->getKernel()->handle($request, HttpKernelInterface::SUB_REQUEST, false);

View File

@ -114,7 +114,9 @@ class EncoderFactory implements EncoderFactoryInterface
}
if ($fromEncoders = ($config['migrate_from'] ?? false)) {
$encoderChain = [];
unset($config['migrate_from']);
$encoderChain = [$this->createEncoder($config, true)];
foreach ($fromEncoders as $name) {
if ($encoder = $this->encoders[$name] ?? false) {
$encoder = $encoder instanceof PasswordEncoderInterface ? $encoder : $this->createEncoder($encoder, true);

View File

@ -143,9 +143,7 @@ class EncoderFactoryTest extends TestCase
$factory = new EncoderFactory([
'digest_encoder' => $digest = new MessageDigestPasswordEncoder('sha256'),
'pbdkf2' => $digest = new MessageDigestPasswordEncoder('sha256'),
'bcrypt_encoder' => ['algorithm' => 'bcrypt'],
SomeUser::class => ['algorithm' => 'sodium', 'migrate_from' => ['bcrypt_encoder', 'digest_encoder']],
SomeUser::class => ['algorithm' => 'sodium', 'migrate_from' => ['bcrypt', 'digest_encoder']],
]);
$encoder = $factory->getEncoder(SomeUser::class);
@ -154,6 +152,7 @@ class EncoderFactoryTest extends TestCase
$this->assertTrue($encoder->isPasswordValid((new SodiumPasswordEncoder())->encodePassword('foo', null), 'foo', null));
$this->assertTrue($encoder->isPasswordValid((new NativePasswordEncoder(null, null, null, \PASSWORD_BCRYPT))->encodePassword('foo', null), 'foo', null));
$this->assertTrue($encoder->isPasswordValid($digest->encodePassword('foo', null), 'foo', null));
$this->assertStringStartsWith(SODIUM_CRYPTO_PWHASH_STRPREFIX, $encoder->encodePassword('foo', null));
}
public function testDefaultMigratingEncoders()