From 2d0c19961b8dbb7ddd190a9c6ac5d09ecedc411d Mon Sep 17 00:00:00 2001 From: Alexey Deriyenko Date: Fri, 26 Nov 2021 17:21:56 +0100 Subject: [PATCH 1/5] fixing queue_name precedence: config -> DSN -> default --- .../Tests/Transport/ConnectionTest.php | 23 +++++++++++++++---- .../Bridge/AmazonSqs/Transport/Connection.php | 9 ++++---- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/src/Symfony/Component/Messenger/Bridge/AmazonSqs/Tests/Transport/ConnectionTest.php b/src/Symfony/Component/Messenger/Bridge/AmazonSqs/Tests/Transport/ConnectionTest.php index 6f3b906a5a188..0db7b3bd25136 100644 --- a/src/Symfony/Component/Messenger/Bridge/AmazonSqs/Tests/Transport/ConnectionTest.php +++ b/src/Symfony/Component/Messenger/Bridge/AmazonSqs/Tests/Transport/ConnectionTest.php @@ -77,11 +77,24 @@ public function testDsnPrecedence() { $httpClient = $this->createMock(HttpClientInterface::class); $this->assertEquals( - new Connection(['queue_name' => 'queue_dsn'], new SqsClient(['region' => 'us-east-2', 'accessKeyId' => 'key_dsn', 'accessKeySecret' => 'secret_dsn'], null, $httpClient)), + new Connection(['queue_name' => 'queue_options'], new SqsClient(['region' => 'us-east-2', 'accessKeyId' => 'key_dsn', 'accessKeySecret' => 'secret_dsn'], null, $httpClient)), Connection::fromDsn('sqs://key_dsn:secret_dsn@default/queue_dsn?region=us-east-2', ['region' => 'eu-west-3', 'queue_name' => 'queue_options', 'access_key' => 'key_option', 'secret_key' => 'secret_option'], $httpClient) ); } + public function testQueueNameDefault() + { + $httpClient = $this->createMock(HttpClientInterface::class); + $this->assertEquals( + new Connection(['queue_name' => 'messages'], new SqsClient(['region' => 'us-east-2', 'accessKeyId' => 'key_dsn', 'accessKeySecret' => 'secret_dsn'], null, $httpClient)), + Connection::fromDsn( + 'sqs://key_dsn:secret_dsn@default/?region=us-east-2', + ['region' => 'eu-west-3', 'access_key' => 'key_option', 'secret_key' => 'secret_option'], + $httpClient + ) + ); + } + public function testFromDsnWithRegion() { $httpClient = $this->createMock(HttpClientInterface::class); @@ -165,7 +178,7 @@ public function testFromDsnWithQueueNameOption() $this->assertEquals( new Connection(['queue_name' => 'queue'], new SqsClient(['region' => 'eu-west-1', 'accessKeyId' => null, 'accessKeySecret' => null], null, $httpClient)), - Connection::fromDsn('sqs://default/queue', ['queue_name' => 'queue_ignored'], $httpClient) + Connection::fromDsn('sqs://default/queue_ignored', ['queue_name' => 'queue'], $httpClient) ); } @@ -342,7 +355,8 @@ public function testLoggerWithDebugOption() private function getMockedQueueUrlResponse(): MockResponse { - return new MockResponse(<< https://sqs.us-east-2.amazonaws.com/123456789012/MyQueue @@ -357,7 +371,8 @@ private function getMockedQueueUrlResponse(): MockResponse private function getMockedReceiveMessageResponse(): MockResponse { - return new MockResponse(<< diff --git a/src/Symfony/Component/Messenger/Bridge/AmazonSqs/Transport/Connection.php b/src/Symfony/Component/Messenger/Bridge/AmazonSqs/Transport/Connection.php index ae09e2a97c01b..fd591e9a71d3c 100644 --- a/src/Symfony/Component/Messenger/Bridge/AmazonSqs/Transport/Connection.php +++ b/src/Symfony/Component/Messenger/Bridge/AmazonSqs/Transport/Connection.php @@ -128,6 +128,11 @@ public static function fromDsn(string $dsn, array $options = [], HttpClientInter throw new InvalidArgumentException(sprintf('Unknown option found in DSN: [%s]. Allowed options are [%s].', implode(', ', $queryExtraKeys), implode(', ', array_keys(self::DEFAULT_OPTIONS)))); } + $parsedPath = explode('/', ltrim($parsedUrl['path'] ?? '/', '/')); + if (\count($parsedPath) > 0 && !empty($queueName = end($parsedPath)) && empty($options['queue_name'])) { + $options['queue_name'] = $queueName; + } + $options = $query + $options + self::DEFAULT_OPTIONS; $configuration = [ 'buffer_size' => (int) $options['buffer_size'], @@ -157,10 +162,6 @@ public static function fromDsn(string $dsn, array $options = [], HttpClientInter $clientConfiguration['endpoint'] = $options['endpoint']; } - $parsedPath = explode('/', ltrim($parsedUrl['path'] ?? '/', '/')); - if (\count($parsedPath) > 0 && !empty($queueName = end($parsedPath))) { - $configuration['queue_name'] = $queueName; - } $configuration['account'] = 2 === \count($parsedPath) ? $parsedPath[0] : $options['account'] ?? self::DEFAULT_OPTIONS['account']; // When the DNS looks like a QueueUrl, we can directly inject it in the connection From 3358bf214f2bc138332d5e942ef0b933455a118e Mon Sep 17 00:00:00 2001 From: Alexey Deriyenko Date: Fri, 26 Nov 2021 17:25:46 +0100 Subject: [PATCH 2/5] reverting accidental commit --- .../Component/Notifier/Bridge/AllMySms/AllMySmsTransport.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/Notifier/Bridge/AllMySms/AllMySmsTransport.php b/src/Symfony/Component/Notifier/Bridge/AllMySms/AllMySmsTransport.php index 28508bdde3506..fab94304bf015 100644 --- a/src/Symfony/Component/Notifier/Bridge/AllMySms/AllMySmsTransport.php +++ b/src/Symfony/Component/Notifier/Bridge/AllMySms/AllMySmsTransport.php @@ -64,7 +64,7 @@ protected function doSend(MessageInterface $message): SentMessage $endpoint = sprintf('https://%s/sms/send/', $this->getEndpoint()); $response = $this->client->request('POST', $endpoint, [ 'auth_basic' => $this->login.':'.$this->apiKey, - 'json' => [ + 'body' => [ 'from' => $this->from, 'to' => $message->getPhone(), 'text' => $message->getSubject(), From d9835b392aeb9a9b4d993899a36b550ace12ed4e Mon Sep 17 00:00:00 2001 From: Alexey Deriyenko Date: Fri, 26 Nov 2021 17:29:35 +0100 Subject: [PATCH 3/5] 5.4 change removed --- .../Component/Notifier/Bridge/AllMySms/AllMySmsTransport.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/Notifier/Bridge/AllMySms/AllMySmsTransport.php b/src/Symfony/Component/Notifier/Bridge/AllMySms/AllMySmsTransport.php index fab94304bf015..28508bdde3506 100644 --- a/src/Symfony/Component/Notifier/Bridge/AllMySms/AllMySmsTransport.php +++ b/src/Symfony/Component/Notifier/Bridge/AllMySms/AllMySmsTransport.php @@ -64,7 +64,7 @@ protected function doSend(MessageInterface $message): SentMessage $endpoint = sprintf('https://%s/sms/send/', $this->getEndpoint()); $response = $this->client->request('POST', $endpoint, [ 'auth_basic' => $this->login.':'.$this->apiKey, - 'body' => [ + 'json' => [ 'from' => $this->from, 'to' => $message->getPhone(), 'text' => $message->getSubject(), From a38d04d9e1fc09f54c63e4004a76fd1e7601172b Mon Sep 17 00:00:00 2001 From: Alexey Deriyenko Date: Sun, 28 Nov 2021 14:05:52 +0100 Subject: [PATCH 4/5] reviews --- .../Bridge/AmazonSqs/Tests/Transport/ConnectionTest.php | 7 +++---- .../Messenger/Bridge/AmazonSqs/Transport/Connection.php | 9 ++++----- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/Symfony/Component/Messenger/Bridge/AmazonSqs/Tests/Transport/ConnectionTest.php b/src/Symfony/Component/Messenger/Bridge/AmazonSqs/Tests/Transport/ConnectionTest.php index 0db7b3bd25136..546f41a5467fa 100644 --- a/src/Symfony/Component/Messenger/Bridge/AmazonSqs/Tests/Transport/ConnectionTest.php +++ b/src/Symfony/Component/Messenger/Bridge/AmazonSqs/Tests/Transport/ConnectionTest.php @@ -77,7 +77,7 @@ public function testDsnPrecedence() { $httpClient = $this->createMock(HttpClientInterface::class); $this->assertEquals( - new Connection(['queue_name' => 'queue_options'], new SqsClient(['region' => 'us-east-2', 'accessKeyId' => 'key_dsn', 'accessKeySecret' => 'secret_dsn'], null, $httpClient)), + new Connection(['queue_name' => 'queue_dsn'], new SqsClient(['region' => 'us-east-2', 'accessKeyId' => 'key_dsn', 'accessKeySecret' => 'secret_dsn'], null, $httpClient)), Connection::fromDsn('sqs://key_dsn:secret_dsn@default/queue_dsn?region=us-east-2', ['region' => 'eu-west-3', 'queue_name' => 'queue_options', 'access_key' => 'key_option', 'secret_key' => 'secret_option'], $httpClient) ); } @@ -178,7 +178,7 @@ public function testFromDsnWithQueueNameOption() $this->assertEquals( new Connection(['queue_name' => 'queue'], new SqsClient(['region' => 'eu-west-1', 'accessKeyId' => null, 'accessKeySecret' => null], null, $httpClient)), - Connection::fromDsn('sqs://default/queue_ignored', ['queue_name' => 'queue'], $httpClient) + Connection::fromDsn('sqs://default/queue', ['queue_name' => 'queue_ignored'], $httpClient) ); } @@ -355,8 +355,7 @@ public function testLoggerWithDebugOption() private function getMockedQueueUrlResponse(): MockResponse { - return new MockResponse( - << https://sqs.us-east-2.amazonaws.com/123456789012/MyQueue diff --git a/src/Symfony/Component/Messenger/Bridge/AmazonSqs/Transport/Connection.php b/src/Symfony/Component/Messenger/Bridge/AmazonSqs/Transport/Connection.php index fd591e9a71d3c..ae09e2a97c01b 100644 --- a/src/Symfony/Component/Messenger/Bridge/AmazonSqs/Transport/Connection.php +++ b/src/Symfony/Component/Messenger/Bridge/AmazonSqs/Transport/Connection.php @@ -128,11 +128,6 @@ public static function fromDsn(string $dsn, array $options = [], HttpClientInter throw new InvalidArgumentException(sprintf('Unknown option found in DSN: [%s]. Allowed options are [%s].', implode(', ', $queryExtraKeys), implode(', ', array_keys(self::DEFAULT_OPTIONS)))); } - $parsedPath = explode('/', ltrim($parsedUrl['path'] ?? '/', '/')); - if (\count($parsedPath) > 0 && !empty($queueName = end($parsedPath)) && empty($options['queue_name'])) { - $options['queue_name'] = $queueName; - } - $options = $query + $options + self::DEFAULT_OPTIONS; $configuration = [ 'buffer_size' => (int) $options['buffer_size'], @@ -162,6 +157,10 @@ public static function fromDsn(string $dsn, array $options = [], HttpClientInter $clientConfiguration['endpoint'] = $options['endpoint']; } + $parsedPath = explode('/', ltrim($parsedUrl['path'] ?? '/', '/')); + if (\count($parsedPath) > 0 && !empty($queueName = end($parsedPath))) { + $configuration['queue_name'] = $queueName; + } $configuration['account'] = 2 === \count($parsedPath) ? $parsedPath[0] : $options['account'] ?? self::DEFAULT_OPTIONS['account']; // When the DNS looks like a QueueUrl, we can directly inject it in the connection From 0827528d7eedbc508ec677a39ae7e22ffd2f2d85 Mon Sep 17 00:00:00 2001 From: Alexey Deriyenko Date: Sun, 28 Nov 2021 14:06:23 +0100 Subject: [PATCH 5/5] reviews --- .../Bridge/AmazonSqs/Tests/Transport/ConnectionTest.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Symfony/Component/Messenger/Bridge/AmazonSqs/Tests/Transport/ConnectionTest.php b/src/Symfony/Component/Messenger/Bridge/AmazonSqs/Tests/Transport/ConnectionTest.php index 546f41a5467fa..74cfb98ce0d97 100644 --- a/src/Symfony/Component/Messenger/Bridge/AmazonSqs/Tests/Transport/ConnectionTest.php +++ b/src/Symfony/Component/Messenger/Bridge/AmazonSqs/Tests/Transport/ConnectionTest.php @@ -370,8 +370,7 @@ private function getMockedQueueUrlResponse(): MockResponse private function getMockedReceiveMessageResponse(): MockResponse { - return new MockResponse( - <<