Skip to content

Navigation Menu

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 fa8672b

Browse filesBrowse files
committed
Fix invalid option sslmode
1 parent ea25825 commit fa8672b
Copy full SHA for fa8672b

File tree

2 files changed

+57
-13
lines changed
Filter options

2 files changed

+57
-13
lines changed

‎src/Symfony/Component/Messenger/Bridge/AmazonSqs/Tests/Transport/ConnectionTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Messenger/Bridge/AmazonSqs/Tests/Transport/ConnectionTest.php
+43Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,24 @@ public function testFromDsnWithCustomEndpoint()
9797
);
9898
}
9999

100+
public function testFromDsnWithSslMode()
101+
{
102+
$httpClient = $this->getMockBuilder(HttpClientInterface::class)->getMock();
103+
$this->assertEquals(
104+
new Connection(['queue_name' => 'queue'], new SqsClient(['region' => 'eu-west-1', 'endpoint' => 'http://localhost', 'accessKeyId' => null, 'accessKeySecret' => null], null, $httpClient)),
105+
Connection::fromDsn('sqs://localhost/queue?sslmode=disable', [], $httpClient)
106+
);
107+
}
108+
109+
public function testFromDsnWithSslModeOnDefault()
110+
{
111+
$httpClient = $this->getMockBuilder(HttpClientInterface::class)->getMock();
112+
$this->assertEquals(
113+
new Connection(['queue_name' => 'queue'], new SqsClient(['region' => 'eu-west-1', 'accessKeyId' => null, 'accessKeySecret' => null], null, $httpClient)),
114+
Connection::fromDsn('sqs://default/queue?sslmode=disable', [], $httpClient)
115+
);
116+
}
117+
100118
public function testFromDsnWithCustomEndpointAndPort()
101119
{
102120
$httpClient = $this->getMockBuilder(HttpClientInterface::class)->getMock();
@@ -149,6 +167,31 @@ public function testFromDsnWithAccountAndEndpointOption()
149167
);
150168
}
151169

170+
public function testFromDsnWithInvalidQueryString()
171+
{
172+
$this->expectException(\InvalidArgumentException::class);
173+
$this->expectExceptionMessage('Unknown option found in DSN: [foo]. Allowed options are [buffer_size, wait_time, poll_timeout, visibility_timeout, auto_setup, access_key, secret_key, endpoint, region, queue_name, account, sslmode].');
174+
175+
Connection::fromDsn('sqs://default?foo=foo');
176+
}
177+
178+
public function testFromDsnWithInvalidOption()
179+
{
180+
$this->expectException(\InvalidArgumentException::class);
181+
$this->expectExceptionMessage('Unknown option found: [bar]. Allowed options are [buffer_size, wait_time, poll_timeout, visibility_timeout, auto_setup, access_key, secret_key, endpoint, region, queue_name, account, sslmode].');
182+
183+
Connection::fromDsn('sqs://default', ['bar' => 'bar']);
184+
}
185+
186+
public function testFromDsnWithInvalidQueryStringAndOption()
187+
{
188+
$this->expectException(\InvalidArgumentException::class);
189+
$this->expectExceptionMessage('Unknown option found: [bar]. Allowed options are [buffer_size, wait_time, poll_timeout, visibility_timeout, auto_setup, access_key, secret_key, endpoint, region, queue_name, account, sslmode].');
190+
191+
Connection::fromDsn('sqs://default?foo=foo', ['bar' => 'bar']);
192+
}
193+
194+
152195
public function testKeepGettingPendingMessages()
153196
{
154197
$client = $this->createMock(SqsClient::class);

‎src/Symfony/Component/Messenger/Bridge/AmazonSqs/Transport/Connection.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Messenger/Bridge/AmazonSqs/Transport/Connection.php
+14-13Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ class Connection
4444
'region' => 'eu-west-1',
4545
'queue_name' => 'messages',
4646
'account' => null,
47+
'sslmode' => null,
4748
];
4849

4950
private $configuration;
@@ -94,6 +95,19 @@ public static function fromDsn(string $dsn, array $options = [], HttpClientInter
9495
if (isset($parsedUrl['query'])) {
9596
parse_str($parsedUrl['query'], $query);
9697
}
98+
99+
// check for extra keys in options
100+
$optionsExtraKeys = array_diff(array_keys($options), array_keys(self::DEFAULT_OPTIONS));
101+
if (0 < \count($optionsExtraKeys)) {
102+
throw new InvalidArgumentException(sprintf('Unknown option found: [%s]. Allowed options are [%s].', implode(', ', $optionsExtraKeys), implode(', ', array_keys(self::DEFAULT_OPTIONS))));
103+
}
104+
105+
// check for extra keys in options
106+
$queryExtraKeys = array_diff(array_keys($query), array_keys(self::DEFAULT_OPTIONS));
107+
if (0 < \count($queryExtraKeys)) {
108+
throw new InvalidArgumentException(sprintf('Unknown option found in DSN: [%s]. Allowed options are [%s].', implode(', ', $queryExtraKeys), implode(', ', array_keys(self::DEFAULT_OPTIONS))));
109+
}
110+
97111
$options = $query + $options + self::DEFAULT_OPTIONS;
98112
$configuration = [
99113
'buffer_size' => (int) $options['buffer_size'],
@@ -116,7 +130,6 @@ public static function fromDsn(string $dsn, array $options = [], HttpClientInter
116130
if (preg_match(';^sqs\.([^\.]++)\.amazonaws\.com$;', $parsedUrl['host'], $matches)) {
117131
$clientConfiguration['region'] = $matches[1];
118132
}
119-
unset($query['sslmode']);
120133
} elseif (self::DEFAULT_OPTIONS['endpoint'] !== $options['endpoint'] ?? self::DEFAULT_OPTIONS['endpoint']) {
121134
$clientConfiguration['endpoint'] = $options['endpoint'];
122135
}
@@ -127,18 +140,6 @@ public static function fromDsn(string $dsn, array $options = [], HttpClientInter
127140
}
128141
$configuration['account'] = 2 === \count($parsedPath) ? $parsedPath[0] : $options['account'] ?? self::DEFAULT_OPTIONS['account'];
129142

130-
// check for extra keys in options
131-
$optionsExtraKeys = array_diff(array_keys($options), array_keys(self::DEFAULT_OPTIONS));
132-
if (0 < \count($optionsExtraKeys)) {
133-
throw new InvalidArgumentException(sprintf('Unknown option found : [%s]. Allowed options are [%s].', implode(', ', $optionsExtraKeys), implode(', ', array_keys(self::DEFAULT_OPTIONS))));
134-
}
135-
136-
// check for extra keys in options
137-
$queryExtraKeys = array_diff(array_keys($query), array_keys(self::DEFAULT_OPTIONS));
138-
if (0 < \count($queryExtraKeys)) {
139-
throw new InvalidArgumentException(sprintf('Unknown option found in DSN: [%s]. Allowed options are [%s].', implode(', ', $queryExtraKeys), implode(', ', array_keys(self::DEFAULT_OPTIONS))));
140-
}
141-
142143
return new self($configuration, new SqsClient($clientConfiguration, null, $client));
143144
}
144145

0 commit comments

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