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 4be827d

Browse filesBrowse files
committed
Changing to MessageDecodingFailedException so that invalid messages are rejected
1 parent 88042a3 commit 4be827d
Copy full SHA for 4be827d

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.