8000 Fix redis connect with empty password by alexander-schranz · Pull Request #37791 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

Fix redis connect with empty password #37791

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
Aug 10, 2020
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 8000
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Fix redis connect with empty password
  • Loading branch information
alexander-schranz authored and fabpot committed Aug 10, 2020
commit 9946f7fecf6ade82466d73bda64d8ea6118598a8
4 changes: 4 additions & 0 deletions src/Symfony/Component/Cache/Traits/RedisTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ public static function createConnection($dsn, array $options = [])
$params = preg_replace_callback('#^'.$scheme.':(//)?(?:(?:[^:@]*+:)?([^@]*+)@)?#', function ($m) use (&$auth) {
if (isset($m[2])) {
$auth = $m[2];

if ('' === $auth) {
$auth = null;
}
}

return 'file:'.($m[1] ?? '');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,28 @@ public function testAuth()
Connection::fromDsn('redis://password@localhost/queue', [], $redis);
}

public function testNoAuthWithEmptyPassword()
{
$redis = $this->getMockBuilder(\Redis::class)->disableOriginalConstructor()->getMock();

$redis->expects($this->exactly(0))->method('auth')
->with('')
->willThrowException(new \RuntimeException());

Connection::fromDsn('redis://@localhost/queue', [], $redis);
}

public function testAuthZeroPassword()
{
$redis = $this->getMockBuilder(\Redis::class)->disableOriginalConstructor()->getMock();

$redis->expects($this->exactly(1))->method('auth')
->with('0')
->willReturn(true);

Connection::fromDsn('redis://0@localhost/queue', [], $redis);
}

public function testFailedAuth()
{
$this->expectException(\InvalidArgumentException::class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,12 @@ public function __construct(array $configuration, array $connectionCredentials =
$this->connection->connect($connectionCredentials['host'] ?? '127.0.0.1', $connectionCredentials['port'] ?? 6379);
$this->connection->setOption(\Redis::OPT_SERIALIZER, $redisOptions['serializer'] ?? \Redis::SERIALIZER_PHP);

if (isset($connectionCredentials['auth']) && !$this->connection->auth($connectionCredentials['auth'])) {
$auth = $connectionCredentials['auth'] ?? null;
if ('' === $auth) {
$auth = null;
}

if (null !== $auth && !$this->connection->auth($auth)) {
throw new InvalidArgumentException('Redis connection failed: '.$redis->getLastError());
}

Expand Down
0