Skip to content

Commit

Permalink
Merge branch '7.0' into 7.1
Browse files Browse the repository at this point in the history
* 7.0: (29 commits)
  fix tests
  add missing method
  fix merge
  fix test
  fix merge
  fix test
  change test to use a real ObjectManager
  [Mailer] Document the usage of custom headers in Infobip bridge
  [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
  ...
  • Loading branch information
xabbuh committed Jun 25, 2024
2 parents f2f7ee7 + 9b84f19 commit f7a49c1
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
15 changes: 15 additions & 0 deletions Tests/Transport/AmazonSqsSenderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,19 @@ public function testSendWithAmazonSqsXrayTraceHeaderStamp()
$sender = new AmazonSqsSender($connection, $serializer);
$sender->send($envelope);
}

public function testSendEncodeBodyToRespectAmazonRequirements()
{
$envelope = new Envelope(new DummyMessage('Oy'));
$encoded = ['body' => "\x7", 'headers' => ['type' => DummyMessage::class]];

$connection = $this->createMock(Connection::class);
$connection->expects($this->once())->method('send')->with(base64_encode($encoded['body']), $encoded['headers']);

$serializer = $this->createMock(SerializerInterface::class);
$serializer->method('encode')->with($envelope)->willReturn($encoded);

$sender = new AmazonSqsSender($connection, $serializer);
$sender->send($envelope);
}
}
17 changes: 17 additions & 0 deletions Transport/AmazonSqsSender.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public function __construct(
public function send(Envelope $envelope): Envelope
{
$encodedMessage = $this->serializer->encode($envelope);
$encodedMessage = $this->complyWithAmazonSqsRequirements($encodedMessage);

/** @var DelayStamp|null $delayStamp */
$delayStamp = $envelope->last(DelayStamp::class);
Expand Down Expand Up @@ -66,4 +67,20 @@ public function send(Envelope $envelope): Envelope

return $envelope;
}

/**
* @see https://docs.aws.amazon.com/AWSSimpleQueueService/latest/APIReference/API_SendMessage.html
*
* @param array{body: string, headers?: array<string>} $encodedMessage
*
* @return array{body: string, headers?: array<string>}
*/
private function complyWithAmazonSqsRequirements(array $encodedMessage): array
{
if (preg_match('/[^\x20-\x{D7FF}\xA\xD\x9\x{E000}-\x{FFFD}\x{10000}-\x{10FFFF}]/u', $encodedMessage['body'])) {
$encodedMessage['body'] = base64_encode($encodedMessage['body']);
}

return $encodedMessage;
}
}

0 comments on commit f7a49c1

Please sign in to comment.