Fix invalid option sslmode
This commit is contained in:
parent
ea258254d0
commit
afbd51b368
@ -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()
|
public function testFromDsnWithCustomEndpointAndPort()
|
||||||
{
|
{
|
||||||
$httpClient = $this->getMockBuilder(HttpClientInterface::class)->getMock();
|
$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()
|
public function testKeepGettingPendingMessages()
|
||||||
{
|
{
|
||||||
$client = $this->createMock(SqsClient::class);
|
$client = $this->createMock(SqsClient::class);
|
||||||
|
@ -44,6 +44,7 @@ class Connection
|
|||||||
'region' => 'eu-west-1',
|
'region' => 'eu-west-1',
|
||||||
'queue_name' => 'messages',
|
'queue_name' => 'messages',
|
||||||
'account' => null,
|
'account' => null,
|
||||||
|
'sslmode' => null,
|
||||||
];
|
];
|
||||||
|
|
||||||
private $configuration;
|
private $configuration;
|
||||||
@ -94,6 +95,19 @@ class Connection
|
|||||||
if (isset($parsedUrl['query'])) {
|
if (isset($parsedUrl['query'])) {
|
||||||
parse_str($parsedUrl['query'], $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;
|
$options = $query + $options + self::DEFAULT_OPTIONS;
|
||||||
$configuration = [
|
$configuration = [
|
||||||
'buffer_size' => (int) $options['buffer_size'],
|
'buffer_size' => (int) $options['buffer_size'],
|
||||||
@ -116,7 +130,6 @@ class Connection
|
|||||||
if (preg_match(';^sqs\.([^\.]++)\.amazonaws\.com$;', $parsedUrl['host'], $matches)) {
|
if (preg_match(';^sqs\.([^\.]++)\.amazonaws\.com$;', $parsedUrl['host'], $matches)) {
|
||||||
$clientConfiguration['region'] = $matches[1];
|
$clientConfiguration['region'] = $matches[1];
|
||||||
}
|
}
|
||||||
unset($query['sslmode']);
|
|
||||||
} elseif (self::DEFAULT_OPTIONS['endpoint'] !== $options['endpoint'] ?? self::DEFAULT_OPTIONS['endpoint']) {
|
} elseif (self::DEFAULT_OPTIONS['endpoint'] !== $options['endpoint'] ?? self::DEFAULT_OPTIONS['endpoint']) {
|
||||||
$clientConfiguration['endpoint'] = $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'];
|
$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));
|
return new self($configuration, new SqsClient($clientConfiguration, null, $client));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user