8000 Handle precendence for path and credentials · symfony/symfony@3908741 · GitHub
[go: up one dir, main page]

Skip to content

Commit 3908741

Browse files
committed
Handle precendence for path and credentials
1 parent c4942b8 commit 3908741

File tree

4 files changed

+7
-6
lines changed

4 files changed

+7
-6
lines changed

src/Symfony/Component/Lock/Store/MongoDbStore.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public function __construct($mongo, array $options = [], float $initialTtl = 300
121121
parse_str($parsedUrl['query'], $query);
122122
}
123123
$this->options['collection'] = $query['collection'] ?? $this->options['collection'] ?? null;
124-
$this->options['database'] = $this->options['database'] ?? ltrim($parsedUrl['path'] ?? '', '/') ?: null;
124+
$this->options['database'] = ltrim($parsedUrl['path'] ?? '', '/') ?: $this->options['database'] ?? null;
125125
if (null === $this->options['database']) {
126126
throw new InvalidArgumentException(sprintf('"%s()" requires the "database" in the URI path or option when constructing with a URI.', __METHOD__));
127127
}

src/Symfony/Component/Lock/Tests/Store/MongoDbStoreTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,12 +125,13 @@ public function testDsnPrecedence()
125125
{
126126
$client = self::getMongoClient();
127127

128-
$store = new MongoDbStore('mongodb://localhost/test?collection=lock_dns', ['collection' => 'lock_option']);
128+
$store = new MongoDbStore('mongodb://localhost/test_dsn?collection=lock_dns', ['collection' => 'lock_option', 'database' => 'test_option']);
129129
$r = new \ReflectionObject($store);
130130
$p = $r->getProperty('options');
131131
$p->setAccessible(true);
132132
$options = $p->getValue($store);
133133
$this->assertSame('lock_dns', $options['collection']);
134+
$this->assertSame('test_dsn', $options['database']);
134135
}
135136

136137
/**

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ public function testDsnPrecedence()
7474
{
7575
$httpClient = $this->getMockBuilder(HttpClientInterface::class)->getMock();
7676
$this->assertEquals(
77-
new Connection(['queue_name' => 'queue'], new SqsClient(['region' => 'us-east-2', 'accessKeyId' => null, 'accessKeySecret' => null], null, $httpClient)),
78-
Connection::fromDsn('sqs://default/queue?region=us-east-2', ['region' => 'eu-west-3'], $httpClient)
77+
new Connection(['queue_name' => 'queue_dsn'], new SqsClient(['region' => 'us-east-2', 'accessKeyId' => 'key_dsn', 'accessKeySecret' => 'secret_dsn'], null, $httpClient)),
78+
Connection::fromDsn('sqs://key_dsn:secret_dsn@default/queue_dsn?region=us-east-2', ['region' => 'eu-west-3', 'queue_name' => 'queue_options', 'accessKeyId' => 'key_option', 'accessKeySecret' => 'secret_option'], $httpClient)
7979
);
8080
}
8181

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ public static function fromDsn(string $dsn, array $options = [], HttpClientInter
105105

106106
$clientConfiguration = [
107107
'region' => $options['region'],
108-
'accessKeyId' => $options['access_key'] ?? (urldecode($parsedUrl['user'] ?? '') ?: self::DEFAULT_OPTIONS['access_key']),
109-
'accessKeySecret' => $options['secret_key'] ?? (urldecode($parsedUrl['pass'] ?? '') ?: self::DEFAULT_OPTIONS['secret_key']),
108+
'accessKeyId' => urldecode($parsedUrl['user'] ?? '') ?: $options['access_key'] ?? self::DEFAULT_OPTIONS['access_key'],
109+
'accessKeySecret' => urldecode($parsedUrl['pass'] ?? '') ?: $options['secret_key'] ?? self::DEFAULT_OPTIONS['secret_key'],
110110
];
111111
unset($query['region']);
112112

0 commit comments

Comments
 (0)
0