Skip to content

Commit 424df04

Browse files
authored
Merge pull request clue#169 from clue-labs/fix-auth
Fix `RedisClient` to pass correct password to internal `Factory`
2 parents 652d56e + fb494d1 commit 424df04

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

src/RedisClient.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ public function __construct(string $uri, ?ConnectorInterface $connector = null)
7272
$parts = parse_url($uri);
7373
}
7474

75-
$uri = (string) preg_replace(['/(:)[^:\/]*(@)/', '/([?&]password=).*?($|&)/'], '$1***$2', $uri);
7675
if ($parts === false || !isset($parts['scheme'], $parts['host']) || !in_array($parts['scheme'], ['redis', 'rediss', 'redis+unix'])) {
76+
$uri = (string) preg_replace(['/(:)[^:\/]*(@)/', '/([?&]password=).*?($|&)/'], '$1***$2', $uri);
7777
throw new \InvalidArgumentException(
7878
'Invalid Redis URI "' . $uri . '" (EINVAL)',
7979
defined('SOCKET_EINVAL') ? SOCKET_EINVAL : 22

tests/RedisClientTest.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,27 @@ public function testCtorWithInvalidUriThrows(string $uri, string $message): void
108108
public function testPingWillCreateUnderlyingClientAndReturnPendingPromise(): void
109109
{
110110
$promise = new Promise(function () { });
111-
$this->factory->expects($this->once())->method('createClient')->willReturn($promise);
111+
$this->factory->expects($this->once())->method('createClient')->with('redis://localhost')->willReturn($promise);
112+
113+
$loop = $this->createMock(LoopInterface::class);
114+
$loop->expects($this->never())->method('addTimer');
115+
assert($loop instanceof LoopInterface);
116+
Loop::set($loop);
117+
118+
$promise = $this->redis->ping();
119+
120+
$promise->then($this->expectCallableNever());
121+
}
122+
123+
public function testPingWithAuthWillCreateUnderlyingClientWithAuthAndReturnPendingPromise(): void
124+
{
125+
$this->redis = new RedisClient('user:pass@localhost');
126+
$ref = new \ReflectionProperty($this->redis, 'factory');
127+
$ref->setAccessible(true);
128+
$ref->setValue($this->redis, $this->factory);
129+
130+
$promise = new Promise(function () { });
131+
$this->factory->expects($this->once())->method('createClient')->with('redis://user:pass@localhost')->willReturn($promise);
112132

113133
$loop = $this->createMock(LoopInterface::class);
114134
$loop->expects($this->never())->method('addTimer');

0 commit comments

Comments
 (0)