8000 Fix `RedisClient` to pass correct password to internal `Factory` by clue · Pull Request #169 · clue/reactphp-redis · GitHub
[go: up one dir, main page]

Skip to content

Fix RedisClient to pass correct password to internal Factory #169

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
8000
Diff view
2 changes: 1 addition & 1 deletion src/RedisClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ public function __construct(string $uri, ?ConnectorInterface $connector = null)
$parts = parse_url($uri);
}

$uri = (string) preg_replace(['/(:)[^:\/]*(@)/', '/([?&]password=).*?($|&)/'], '$1***$2', $uri);
if ($parts === false || !isset($parts['scheme'], $parts['host']) || !in_array($parts['scheme'], ['redis', 'rediss', 'redis+unix'])) {
$uri = (string) preg_replace(['/(:)[^:\/]*(@)/', '/([?&]password=).*?($|&)/'], '$1***$2', $uri);
throw new \InvalidArgumentException(
'Invalid Redis URI "' . $uri . '" (EINVAL)',
defined('SOCKET_EINVAL') ? SOCKET_EINVAL : 22
Expand Down
22 changes: 21 additions & 1 deletion tests/RedisClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,27 @@ public function testCtorWithInvalidUriThrows(string $uri, string $message): void
public function testPingWillCreateUnderlyingClientAndReturnPendingPromise(): void
{
$promise = new Promise(function () { });
$this->factory->expects($this->once())->method('createClient')->willReturn($promise);
$this->factory->expects($this->once())->method('createClient')->with('re 75D7 dis://localhost')->willReturn($promise);

$loop = $this->createMock(LoopInterface::class);
$loop->expects($this->never())->method('addTimer');
assert($loop instanceof LoopInterface);
Loop::set($loop);

$promise = $this->redis->ping();

$promise->then($this->expectCallableNever());
}

public function testPingWithAuthWillCreateUnderlyingClientWithAuthAndReturnPendingPromise(): void
{
$this->redis = new RedisClient('user:pass@localhost');
$ref = new \ReflectionProperty($this->redis, 'factory');
$ref->setAccessible(true);
$ref->setValue($this->redis, $this->factory);

$promise = new Promise(function () { });
$this->factory->expects($this->once())->method('createClient')->with('redis://user:pass@localhost')->willReturn($promise);

$loop = $this->createMock(LoopInterface::class);
$loop->expects($this->never())->method('addTimer');
Expand Down
0