Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 378126a

Browse files
committed
[Messenger] [Redis] Allow authentication with user and password
1 parent 66e8ae9 commit 378126a

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

src/Symfony/Component/Messenger/Tests/Transport/RedisExt/ConnectionTest.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,15 +113,26 @@ public function testKeepGettingPendingMessages()
113113
$this->assertNotNull($connection->get());
114114
}
115115

116-
public function testAuth()
116+
/**
117+
* @param string|array $expected
118+
*
119+
* @dataProvider provideAuthDsn
120+
*/
121+
public function testAuth($expected, string $dsn)
117122
{
118123
$redis = $this->createMock(\Redis::class);
119124

120125
$redis->expects($this->exactly(1))->method('auth')
121-
->with('password')
126+
->with($expected)
122127
->willReturn(true);
123128

124-
Connection::fromDsn('redis://password@localhost/queue', [], $redis);
129+
Connection::fromDsn($dsn, [], $redis);
130+
}
131+
132+
public function provideAuthDsn(): \Generator
133+
{
134+
yield 'Password only' => ['password', 'redis://password@localhost/queue'];
135+
yield 'User and password' => [['user', 'password'], 'redis://user:password@localhost/queue'];
125136
}
126137

127138
public function testNoAuthWithEmptyPassword()

src/Symfony/Component/Messenger/Transport/RedisExt/Connection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public static function fromDsn(string $dsn, array $redisOptions = [], \Redis $re
9797
$connectionCredentials = [
9898
'host' => $parsedUrl['host'] ?? '127.0.0.1',
9999
'port' => $parsedUrl['port'] ?? 6379,
100-
'auth' => $parsedUrl['pass'] ?? $parsedUrl['user'] ?? null,
100+
'auth' => isset($parsedUrl['pass']) && isset($parsedUrl['user']) ? [$parsedUrl['user'], $parsedUrl['pass']] : $parsedUrl['pass'] ?? $parsedUrl['user'] ?? null,
101101
];
102102

103103
if (isset($parsedUrl['query'])) {

0 commit comments

Comments
 (0)