8000 bug #43124 [Messenger] [Redis] Allow authentication with user and pas… · symfony/symfony@c9275a9 · GitHub
[go: up one dir, main page]

Skip to content

Commit c9275a9

Browse files
committed
bug #43124 [Messenger] [Redis] Allow authentication with user and password (GaryPEGEOT)
This PR was squashed before being merged into the 4.4 branch. Discussion ---------- [Messenger] [Redis] Allow authentication with user and password | Q | A | ------------- | --- | Branch? | 5.3 | Bug fix? | yes | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tickets | | License | MIT | Doc PR | N/A Allow to authenticate on Redis with user **and** password, instead of only password Commits ------- 5a6bf50 [Messenger] [Redis] Allow authentication with user and password
2 parents 66e8ae9 + 5a6bf50 commit c9275a9

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-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: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ 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+
// See: https://github.com/phpredis/phpredis/#auth
101+
'auth' => isset($parsedUrl['pass']) && isset($parsedUrl['user']) ? [$parsedUrl['user'], $parsedUrl['pass']] : $parsedUrl['pass'] ?? $parsedUrl['user'] ?? null,
101102
];
102103

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

0 commit comments

Comments
 (0)
0