Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 8253353

Browse filesBrowse files
committed
bug #30756 Changing to MessageDecodingFailedException so that invalid messages are rejected (weaverryan)
This PR was merged into the 4.3-dev branch. Discussion ---------- Changing to MessageDecodingFailedException so that invalid messages are rejected | Q | A | ------------- | --- | Branch? | master | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes <!-- please add some, will be required by reviewers --> | Fixed tickets | #30649 | License | MIT | Doc PR | not needed for bug fix Bug fix if a message body is completely blank. I'm fixing this on master only, because in 4.2 and earlier, there is actually no system in place to fail serialization and cause the messages to be rejected. In 4.3, we just need to throw this exception. Cheers! Commits ------- 4be827d Changing to MessageDecodingFailedException so that invalid messages are rejected
2 parents 177a0d9 + 4be827d commit 8253353
Copy full SHA for 8253353

File tree

Expand file treeCollapse file tree

4 files changed

+44
-5
lines changed
Filter options
Expand file treeCollapse file tree

4 files changed

+44
-5
lines changed

‎src/Symfony/Component/Messenger/Tests/Transport/Serialization/PhpSerializerTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Messenger/Tests/Transport/Serialization/PhpSerializerTest.php
+10Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,16 @@ public function testEncodedIsDecodable()
2828
$this->assertEquals($envelope, $serializer->decode($serializer->encode($envelope)));
2929
}
3030

31+
public function testDecodingFailsWithMissingBodyKey()
32+
{
33+
$this->expectException(MessageDecodingFailedException::class);
34+
$this->expectExceptionMessage('Encoded envelope should have at least a "body".');
35+
36+
$serializer = new PhpSerializer();
37+
38+
$serializer->decode([]);
39+
}
40+
3141
public function testDecodingFailsWithBadFormat()
3242
{
3343
$this->expectException(MessageDecodingFailedException::class);

‎src/Symfony/Component/Messenger/Tests/Transport/Serialization/SerializerTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Messenger/Tests/Transport/Serialization/SerializerTest.php
+31Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,37 @@ public function testDecodingFailsWithBadFormat()
108108
]);
109109
}
110110

111+
/**
112+
* @dataProvider getMissingKeyTests
113+
*/
114+
public function testDecodingFailsWithMissingKeys(array $data, string $expectedMessage)
115+
{
116+
$this->expectException(MessageDecodingFailedException::class);
117+
$this->expectExceptionMessage($expectedMessage);
118+
119+
$serializer = new Serializer();
120+
121+
$serializer->decode($data);
122+
}
123+
124+
public function getMissingKeyTests()
125+
{
126+
yield 'no_body' => [
127+
['headers' => ['type' => 'bar']],
128+
'Encoded envelope should have at least a "body" and some "headers".',
129+
];
130+
131+
yield 'no_headers' => [
132+
['body' => '{}'],
133+
'Encoded envelope should have at least a "body" and some "headers".',
134+
];
135+
136+
yield 'no_headers_type' => [
137+
['body' => '{}', 'headers' => ['foo' => 'bar']],
138+
'Encoded envelope does not have a "type" header.',
139+
];
140+
}
141+
111142
public function testDecodingFailsWithBadClass()
112143
{
113144
$this->expectException(MessageDecodingFailedException::class);

‎src/Symfony/Component/Messenger/Transport/Serialization/PhpSerializer.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Messenger/Transport/Serialization/PhpSerializer.php
+1-2Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
namespace Symfony\Component\Messenger\Transport\Serialization;
1313

1414
use Symfony\Component\Messenger\Envelope;
15-
use Symfony\Component\Messenger\Exception\InvalidArgumentException;
1615
use Symfony\Component\Messenger\Exception\MessageDecodingFailedException;
1716

1817
/**
@@ -28,7 +27,7 @@ class PhpSerializer implements SerializerInterface
2827
public function decode(array $encodedEnvelope): Envelope
2928
{
3029
if (empty($encodedEnvelope['body'])) {
31-
throw new InvalidArgumentException('Encoded envelope should have at least a "body".');
30+
throw new MessageDecodingFailedException('Encoded envelope should have at least a "body".');
3231
}
3332

3433
return $this->safelyUnserialize($encodedEnvelope['body']);

‎src/Symfony/Component/Messenger/Transport/Serialization/Serializer.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Messenger/Transport/Serialization/Serializer.php
+2-3Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
namespace Symfony\Component\Messenger\Transport\Serialization;
1313

1414
use Symfony\Component\Messenger\Envelope;
15-
use Symfony\Component\Messenger\Exception\InvalidArgumentException;
1615
use Symfony\Component\Messenger\Exception\LogicException;
1716
use Symfony\Component\Messenger\Exception\MessageDecodingFailedException;
1817
use Symfony\Component\Messenger\Stamp\SerializerStamp;
@@ -63,11 +62,11 @@ public static function create(): self
6362
public function decode(array $encodedEnvelope): Envelope
6463
{
6564
if (empty($encodedEnvelope['body']) || empty($encodedEnvelope['headers'])) {
66-
throw new InvalidArgumentException('Encoded envelope should have at least a "body" and some "headers".');
65+
throw new MessageDecodingFailedException('Encoded envelope should have at least a "body" and some "headers".');
6766
}
6867

6968
if (empty($encodedEnvelope['headers']['type'])) {
70-
throw new InvalidArgumentException('Encoded envelope does not have a "type" header.');
69+
throw new MessageDecodingFailedException('Encoded envelope does not have a "type" header.');
7170
}
7271

7372
$stamps = $this->decodeStamps($encodedEnvelope);

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.