From ef3bcda5e36572424e6c4f75253d70a3dbd3f3cc Mon Sep 17 00:00:00 2001 From: Craig Duncan Date: Fri, 17 Jan 2020 17:21:39 +0000 Subject: [PATCH 1/4] Mysqli doesn't support the named parameters used by PdoStore --- src/Symfony/Component/Lock/Store/PdoStore.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Symfony/Component/Lock/Store/PdoStore.php b/src/Symfony/Component/Lock/Store/PdoStore.php index 0cf3dd35f7..94ef6b1457 100644 --- a/src/Symfony/Component/Lock/Store/PdoStore.php +++ b/src/Symfony/Component/Lock/Store/PdoStore.php @@ -307,6 +307,7 @@ class PdoStore implements StoreInterface } else { switch ($this->driver = $con->getDriver()->getName()) { case 'mysqli': + throw new NotSupportedException(sprintf('The store "%s" does not support the mysqli driver, use pdo_mysql instead.', \get_class($this))); case 'pdo_mysql': case 'drizzle_pdo_mysql': $this->driver = 'mysql'; From a7864489b026535f6f07dd31566e9c0732852e2e Mon Sep 17 00:00:00 2001 From: Craig Duncan Date: Sat, 25 Jan 2020 13:06:31 +0000 Subject: [PATCH 2/4] Mysqli doesn't support the named parameters used by PdoAdapter --- src/Symfony/Component/Cache/Traits/PdoTrait.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Symfony/Component/Cache/Traits/PdoTrait.php b/src/Symfony/Component/Cache/Traits/PdoTrait.php index b636e7565b..3294f1fe50 100644 --- a/src/Symfony/Component/Cache/Traits/PdoTrait.php +++ b/src/Symfony/Component/Cache/Traits/PdoTrait.php @@ -395,6 +395,7 @@ trait PdoTrait } else { switch ($this->driver = $this->conn->getDriver()->getName()) { case 'mysqli': + throw new \LogicException(sprintf('The adapter "%s" does not support the mysqli driver, use pdo_mysql instead.', \get_class($this))); case 'pdo_mysql': case 'drizzle_pdo_mysql': $this->driver = 'mysql'; From ae0c6344b4b6579052742b1053baa5e89b60e4b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Deruss=C3=A9?= Date: Mon, 27 Jan 2020 19:01:48 +0100 Subject: [PATCH 3/4] Fix exception message in Doctrine Messenger --- .../Component/Messenger/Transport/Doctrine/Connection.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/Messenger/Transport/Doctrine/Connection.php b/src/Symfony/Component/Messenger/Transport/Doctrine/Connection.php index f665e8b31c..c0763eb157 100644 --- a/src/Symfony/Component/Messenger/Transport/Doctrine/Connection.php +++ b/src/Symfony/Component/Messenger/Transport/Doctrine/Connection.php @@ -86,13 +86,13 @@ class Connection // check for extra keys in options $optionsExtraKeys = array_diff(array_keys($options), array_keys(self::DEFAULT_OPTIONS)); if (0 < \count($optionsExtraKeys)) { - throw new InvalidArgumentException(sprintf('Unknown option found : [%s]. Allowed options are [%s]', implode(', ', $optionsExtraKeys), implode(', ', self::DEFAULT_OPTIONS))); + throw new InvalidArgumentException(sprintf('Unknown option found : [%s]. Allowed options are [%s]', implode(', ', $optionsExtraKeys), implode(', ', array_keys(self::DEFAULT_OPTIONS)))); } // check for extra keys in options $queryExtraKeys = array_diff(array_keys($query), array_keys(self::DEFAULT_OPTIONS)); if (0 < \count($queryExtraKeys)) { - throw new InvalidArgumentException(sprintf('Unknown option found in DSN: [%s]. Allowed options are [%s]', implode(', ', $queryExtraKeys), implode(', ', self::DEFAULT_OPTIONS))); + throw new InvalidArgumentException(sprintf('Unknown option found in DSN: [%s]. Allowed options are [%s]', implode(', ', $queryExtraKeys), implode(', ', array_keys(self::DEFAULT_OPTIONS)))); } return $configuration; From 21fffcadd5f898a2fae56af9fc36d7dfcef7bd31 Mon Sep 17 00:00:00 2001 From: Patrick Berenschot Date: Mon, 27 Jan 2020 11:46:05 +0000 Subject: [PATCH 4/4] =?UTF-8?q?[Messenger]=20Check=20for=20all=20serializa?= =?UTF-8?q?tion=20exceptions=20during=20message=20dec=E2=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Serialization/SerializerTest.php | 33 +++++++++++++++++++ .../Transport/Serialization/Serializer.php | 6 ++-- 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Component/Messenger/Tests/Transport/Serialization/SerializerTest.php b/src/Symfony/Component/Messenger/Tests/Transport/Serialization/SerializerTest.php index 73cbfb6cb9..604c497bfb 100644 --- a/src/Symfony/Component/Messenger/Tests/Transport/Serialization/SerializerTest.php +++ b/src/Symfony/Component/Messenger/Tests/Transport/Serialization/SerializerTest.php @@ -207,7 +207,40 @@ class SerializerTest extends TestCase $encoded = $serializer->encode($envelope); $this->assertStringNotContainsString('DummySymfonySerializerNonSendableStamp', print_r($encoded['headers'], true)); } + + public function testDecodingFailedConstructorDeserialization() + { + $serializer = new Serializer(); + + $this->expectException(MessageDecodingFailedException::class); + + $serializer->decode([ + 'body' => '{}', + 'headers' => ['type' => DummySymfonySerializerInvalidConstructor::class], + ]); + } + + public function testDecodingStampFailedDeserialization() + { + $serializer = new Serializer(); + + $this->expectException(MessageDecodingFailedException::class); + + $serializer->decode([ + 'body' => '{"message":"hello"}', + 'headers' => [ + 'type' => DummyMessage::class, + 'X-Message-Stamp-'.SerializerStamp::class => '[{}]', + ], + ]); + } } class DummySymfonySerializerNonSendableStamp implements NonSendableStampInterface { } +class DummySymfonySerializerInvalidConstructor +{ + public function __construct(string $missingArgument) + { + } +} diff --git a/src/Symfony/Component/Messenger/Transport/Serialization/Serializer.php b/src/Symfony/Component/Messenger/Transport/Serialization/Serializer.php index 3c13cb6e90..8d4b63994a 100644 --- a/src/Symfony/Component/Messenger/Transport/Serialization/Serializer.php +++ b/src/Symfony/Component/Messenger/Transport/Serialization/Serializer.php @@ -19,7 +19,7 @@ use Symfony\Component\Messenger\Stamp\SerializerStamp; use Symfony\Component\Messenger\Stamp\StampInterface; use Symfony\Component\Serializer\Encoder\JsonEncoder; use Symfony\Component\Serializer\Encoder\XmlEncoder; -use Symfony\Component\Serializer\Exception\UnexpectedValueException; +use Symfony\Component\Serializer\Exception\ExceptionInterface; use Symfony\Component\Serializer\Normalizer\ArrayDenormalizer; use Symfony\Component\Serializer\Normalizer\ObjectNormalizer; use Symfony\Component\Serializer\Serializer as SymfonySerializer; @@ -81,7 +81,7 @@ class Serializer implements SerializerInterface try { $message = $this->serializer->deserialize($encodedEnvelope['body'], $encodedEnvelope['headers']['type'], $this->format, $context); - } catch (UnexpectedValueException $e) { + } catch (ExceptionInterface $e) { throw new MessageDecodingFailedException(sprintf('Could not decode message: %s.', $e->getMessage()), $e->getCode(), $e); } @@ -119,7 +119,7 @@ class Serializer implements SerializerInterface try { $stamps[] = $this->serializer->deserialize($value, substr($name, \strlen(self::STAMP_HEADER_PREFIX)).'[]', $this->format, $this->context); - } catch (UnexpectedValueException $e) { + } catch (ExceptionInterface $e) { throw new MessageDecodingFailedException(sprintf('Could not decode stamp: %s.', $e->getMessage()), $e->getCode(), $e); } }