8000 Merge branch '5.4' into 6.4 · symfony/amazon-sqs-messenger@12bc102 · GitHub
[go: up one dir, main page]

Skip to content

Commit 12bc102

Browse files
committed
Merge branch '5.4' into 6.4
* 5.4: (21 commits) [SecurityBundle] Add `provider` XML attribute to the authenticators it’s missing from [DoctrineBridge] Test reset with a true manager Sync php-cs-fixer config file with 7.2 [HttpClient] Fix parsing SSE [Notifier] Fix thread key in GoogleChat bridge [HttpKernel][Security] Fix accessing session for stateless request [Serializer] Fix `ObjectNormalizer` with property path test handling of special "value" constraint option [PhpUnitBridge] Add missing import [FrameworkBundle] Fix setting default context for certain normalizers [57251] Missing translations for Romanian (ro) [ErrorHandler] Fix rendered exception code highlighting on PHP 8.3 [String] Fix #54611 pluralization of -on ending words + singularization of -a ending foreign words [Validator] [UniqueValidator] Use correct variable as parameter in (custom) error message [Messenger] Comply with Amazon SQS requirements for message body fix cssColor HSLA test dataProvider properly handle invalid data for false/true types chore: upgrade class doc add space in error message [Messenger] [Amqp] Handle AMQPConnectionException when publishing a message. ...
2 parents 067db1a + 2d91f57 commit 12bc102

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

Tests/Transport/AmazonSqsSenderTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,19 @@ public function testSendWithAmazonSqsXrayTraceHeaderStamp()
7272
$sender = new AmazonSqsSender($connection, $serializer);
7373
$sender->send($envelope);
7474
}
75+
76+
public function testSendEncodeBodyToRespectAmazonRequirements()
77+
{
78+
$envelope = new Envelope(new DummyMessage('Oy'));
79+
$encoded = ['body' => "\x7", 'headers' => ['type' => DummyMessage::class]];
80+
81+
$connection = $this->createMock(Connection::class);
82+
$connection->expects($this->once())->method('send')->with(base64_encode($encoded['body']), $encoded['headers']);
83+
84+
$serializer = $this->createMock(SerializerInterface::class);
85+
$serializer->method('encode')->with($envelope)->willReturn($encoded);
86+
87+
$sender = new AmazonSqsSender($connection, $serializer);
88+
$sender->send($envelope);
89+
}
7590
}

Transport/AmazonSqsSender.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public function __construct(Connection $connection, SerializerInterface $seriali
3535
public function send(Envelope $envelope): Envelope
3636
{
3737
$encodedMessage = $this->serializer->encode($envelope);
38+
$encodedMessage = $this->complyWithAmazonSqsRequirements($encodedMessage);
3839

3940
/** @var DelayStamp|null $delayStamp */
4041
$delayStamp = $envelope->last(DelayStamp::class);
@@ -69,4 +70,20 @@ public function send(Envelope $envelope): Envelope
6970

7071
return $envelope;
7172
}
73+
74+
/**
75+
* @see https://docs.aws.amazon.com/AWSSimpleQueueService/latest/APIReference/API_SendMessage.html
76+
*
77+
* @param array{body: string, headers?: array<string>} $encodedMessage
78+
*
79+
* @return array{body: string, headers?: array<string>}
80+
*/
81+
private function complyWithAmazonSqsRequirements(array $encodedMessage): array
82+
{
83+
if (preg_match('/[^\x20-\x{D7FF}\xA\xD\x9\x{E000}-\x{FFFD}\x{10000}-\x{10FFFF}]/u', $encodedMessage['body'])) {
84+
$encodedMessage['body'] = base64_encode($encodedMessage['body']);
85+
}
86+
87+
return $encodedMessage;
88+
}
7289
}

0 commit comments

Comments
 (0)
0