bug #37654 [Messenger] Fix invalid option sslmode in AmazonSqs bridge (jderusse)
This PR was merged into the 5.1 branch.
Discussion
----------
[Messenger] Fix invalid option sslmode in AmazonSqs bridge
| Q | A
| ------------- | ---
| Branch? | 5.1
| Bug fix? | yes
| New feature? | no
| Deprecations? | no
| Tickets | />
| License | MIT
| Doc PR | /
The sslmode option allows people to use AmazonSqs with non-offical endpoint like the [asyncaws/testing-sqs](https://hub.docker.com/r/asyncaws/testing-sqs) docker image
By fixing precedence of DNS options in https://github.com/symfony/symfony/pull/37269 I introduced a bug that trigger an exception `Unknown option found: [sslmode]`. I apologize for this
This PR adds `sslmode` in list of allowed options
Commits
-------
afbd51b368
Fix invalid option sslmode
This commit is contained in:
commit
bfc0351da6
@ -97,6 +97,24 @@ class ConnectionTest extends TestCase
|
||||
);
|
||||
}
|
||||
|
||||
public function testFromDsnWithSslMode()
|
||||
{
|
||||
$httpClient = $this->getMockBuilder(HttpClientInterface::class)->getMock();
|
||||
$this->assertEquals(
|
||||
new Connection(['queue_name' => 'queue'], new SqsClient(['region' => 'eu-west-1', 'endpoint' => 'http://localhost', 'accessKeyId' => null, 'accessKeySecret' => null], null, $httpClient)),
|
||||
Connection::fromDsn('sqs://localhost/queue?sslmode=disable', [], $httpClient)
|
||||
);
|
||||
}
|
||||
|
||||
public function testFromDsnWithSslModeOnDefault()
|
||||
{
|
||||
$httpClient = $this->getMockBuilder(HttpClientInterface::class)->getMock();
|
||||
$this->assertEquals(
|
||||
new Connection(['queue_name' => 'queue'], new SqsClient(['region' => 'eu-west-1', 'accessKeyId' => null, 'accessKeySecret' => null], null, $httpClient)),
|
||||
Connection::fromDsn('sqs://default/queue?sslmode=disable', [], $httpClient)
|
||||
);
|
||||
}
|
||||
|
||||
public function testFromDsnWithCustomEndpointAndPort()
|
||||
{
|
||||
$httpClient = $this->getMockBuilder(HttpClientInterface::class)->getMock();
|
||||
@ -149,6 +167,30 @@ class ConnectionTest extends TestCase
|
||||
);
|
||||
}
|
||||
|
||||
public function testFromDsnWithInvalidQueryString()
|
||||
{
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
$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].');
|
||||
|
||||
Connection::fromDsn('sqs://default?foo=foo');
|
||||
}
|
||||
|
||||
public function testFromDsnWithInvalidOption()
|
||||
{
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
$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].');
|
||||
|
||||
Connection::fromDsn('sqs://default', ['bar' => 'bar']);
|
||||
}
|
||||
|
||||
public function testFromDsnWithInvalidQueryStringAndOption()
|
||||
{
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
$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].');
|
||||
|
||||
Connection::fromDsn('sqs://default?foo=foo', ['bar' => 'bar']);
|
||||
}
|
||||
|
||||
public function testKeepGettingPendingMessages()
|
||||
{
|
||||
$client = $this->createMock(SqsClient::class);
|
||||
|
@ -44,6 +44,7 @@ class Connection
|
||||
'region' => 'eu-west-1',
|
||||
'queue_name' => 'messages',
|
||||
'account' => null,
|
||||
'sslmode' => null,
|
||||
];
|
||||
|
||||
private $configuration;
|
||||
@ -94,6 +95,19 @@ class Connection
|
||||
if (isset($parsedUrl['query'])) {
|
||||
parse_str($parsedUrl['query'], $query);
|
||||
}
|
||||
|
||||
// check for extra keys in options
|
||||
$optionsExtraKeys = array_diff(array_keys($options), array_keys(self::DEFAULT_OPTIONS));
|
||||
if (0 < \count($optionsExtraKeys)) {
|
||||
throw new InvalidArgumentException(sprintf('Unknown option found: [%s]. Allowed options are [%s].', implode(', ', $optionsExtraKeys), implode(', ', array_keys(self::DEFAULT_OPTIONS))));
|
||||
}
|
||||
|
||||
// check for extra keys in options
|
||||
$queryExtraKeys = array_diff(array_keys($query), array_keys(self::DEFAULT_OPTIONS));
|
||||
if (0 < \count($queryExtraKeys)) {
|
||||
throw new InvalidArgumentException(sprintf('Unknown option found in DSN: [%s]. Allowed options are [%s].', implode(', ', $queryExtraKeys), implode(', ', array_keys(self::DEFAULT_OPTIONS))));
|
||||
}
|
||||
|
||||
$options = $query + $options + self::DEFAULT_OPTIONS;
|
||||
$configuration = [
|
||||
'buffer_size' => (int) $options['buffer_size'],
|
||||
@ -116,7 +130,6 @@ class Connection
|
||||
if (preg_match(';^sqs\.([^\.]++)\.amazonaws\.com$;', $parsedUrl['host'], $matches)) {
|
||||
$clientConfiguration['region'] = $matches[1];
|
||||
}
|
||||
unset($query['sslmode']);
|
||||
} elseif (self::DEFAULT_OPTIONS['endpoint'] !== $options['endpoint'] ?? self::DEFAULT_OPTIONS['endpoint']) {
|
||||
$clientConfiguration['endpoint'] = $options['endpoint'];
|
||||
}
|
||||
@ -127,18 +140,6 @@ class Connection
|
||||
}
|
||||
$configuration['account'] = 2 === \count($parsedPath) ? $parsedPath[0] : $options['account'] ?? self::DEFAULT_OPTIONS['account'];
|
||||
|
||||
// check for extra keys in options
|
||||
$optionsExtraKeys = array_diff(array_keys($options), array_keys(self::DEFAULT_OPTIONS));
|
||||
if (0 < \count($optionsExtraKeys)) {
|
||||
throw new InvalidArgumentException(sprintf('Unknown option found : [%s]. Allowed options are [%s].', implode(', ', $optionsExtraKeys), implode(', ', array_keys(self::DEFAULT_OPTIONS))));
|
||||
}
|
||||
|
||||
// check for extra keys in options
|
||||
$queryExtraKeys = array_diff(array_keys($query), array_keys(self::DEFAULT_OPTIONS));
|
||||
if (0 < \count($queryExtraKeys)) {
|
||||
throw new InvalidArgumentException(sprintf('Unknown option found in DSN: [%s]. Allowed options are [%s].', implode(', ', $queryExtraKeys), implode(', ', array_keys(self::DEFAULT_OPTIONS))));
|
||||
}
|
||||
|
||||
return new self($configuration, new SqsClient($clientConfiguration, null, $client));
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user