[Messenger] Add TLS option to Redis transport's DSN

This commit is contained in:
Nyholm 2020-01-29 10:07:13 +01:00 committed by Fabien Potencier
parent f0748f8978
commit 09ec907a7e
3 changed files with 33 additions and 1 deletions

View File

@ -5,3 +5,4 @@ CHANGELOG
-----
* Introduced the Redis bridge.
* Added TLS option in the DSN. Example: `redis://127.0.0.1?tls=1`

View File

@ -12,8 +12,8 @@
namespace Symfony\Component\Messenger\Bridge\Redis\Tests\Transport;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Messenger\Exception\TransportException;
use Symfony\Component\Messenger\Bridge\Redis\Transport\Connection;
use Symfony\Component\Messenger\Exception\TransportException;
/**
* @requires extension redis >= 4.3.0
@ -73,6 +73,28 @@ class ConnectionTest extends TestCase
);
}
public function testFromDsnWithTls()
{
$redis = $this->createMock(\Redis::class);
$redis->expects($this->once())
->method('connect')
->with('tls://127.0.0.1', 6379)
->willReturn(null);
Connection::fromDsn('redis://127.0.0.1?tls=1', [], $redis);
}
public function testFromDsnWithTlsOption()
{
$redis = $this->createMock(\Redis::class);
$redis->expects($this->once())
->method('connect')
->with('tls://127.0.0.1', 6379)
->willReturn(null);
Connection::fromDsn('redis://127.0.0.1', ['tls' => true], $redis);
}
public function testFromDsnWithQueryOptions()
{
$this->assertEquals(

View File

@ -104,6 +104,12 @@ class Connection
unset($redisOptions['dbindex']);
}
$tls = false;
if (\array_key_exists('tls', $redisOptions)) {
$tls = filter_var($redisOptions['tls'], FILTER_VALIDATE_BOOLEAN);
unset($redisOptions['tls']);
}
$configuration = [
'stream' => $redisOptions['stream'] ?? null,
'group' => $redisOptions['group'] ?? null,
@ -125,6 +131,9 @@ class Connection
$configuration['stream'] = $pathParts[1] ?? $configuration['stream'];
$configuration['group'] = $pathParts[2] ?? $configuration['group'];
$configuration['consumer'] = $pathParts[3] ?? $configuration['consumer'];
if ($tls) {
$connectionCredentials['host'] = 'tls://'.$connectionCredentials['host'];
}
} else {
$connectionCredentials = [
'host' => $parsedUrl['path'],