Skip to content
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
Diff view
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