[Messenger] Add rediss:// DSN scheme support for TLS to Redis transport

This commit is contained in:
viktor 2020-12-22 12:01:12 +01:00 committed by Nicolas Grekas
parent 64b76968bf
commit 28e7b74b47
6 changed files with 31 additions and 4 deletions

View File

@ -50,6 +50,7 @@ Messenger
--------- ---------
* Deprecated the `prefetch_count` parameter in the AMQP bridge, it has no effect and will be removed in Symfony 6.0 * Deprecated the `prefetch_count` parameter in the AMQP bridge, it has no effect and will be removed in Symfony 6.0
* Deprecated the use of TLS option for Redis Bridge, use `rediss://127.0.0.1` instead of `redis://127.0.0.1?tls=1`
Notifier Notifier
-------- --------

View File

@ -122,6 +122,7 @@ Messenger
* The signature of method `RetryStrategyInterface::isRetryable()` has been updated to `RetryStrategyInterface::isRetryable(Envelope $message, \Throwable $throwable = null)`. * The signature of method `RetryStrategyInterface::isRetryable()` has been updated to `RetryStrategyInterface::isRetryable(Envelope $message, \Throwable $throwable = null)`.
* The signature of method `RetryStrategyInterface::getWaitingTime()` has been updated to `RetryStrategyInterface::getWaitingTime(Envelope $message, \Throwable $throwable = null)`. * The signature of method `RetryStrategyInterface::getWaitingTime()` has been updated to `RetryStrategyInterface::getWaitingTime(Envelope $message, \Throwable $throwable = null)`.
* Removed the `prefetch_count` parameter in the AMQP bridge. * Removed the `prefetch_count` parameter in the AMQP bridge.
* Removed the use of TLS option for Redis Bridge, use `rediss://127.0.0.1` instead of `redis://127.0.0.1?tls=1`
Mime Mime
---- ----

View File

@ -1,6 +1,12 @@
CHANGELOG CHANGELOG
========= =========
5.3
---
* Add `rediss://` DSN scheme support for TLS protocol
* Deprecate TLS option, use `rediss://127.0.0.1` instead of `redis://127.0.0.1?tls=1`
5.2.0 5.2.0
----- -----

View File

@ -86,6 +86,9 @@ class ConnectionTest extends TestCase
); );
} }
/**
* @group legacy
*/
public function testFromDsnWithTls() public function testFromDsnWithTls()
{ {
$redis = $this->createMock(\Redis::class); $redis = $this->createMock(\Redis::class);
@ -97,6 +100,9 @@ class ConnectionTest extends TestCase
Connection::fromDsn('redis://127.0.0.1?tls=1', [], $redis); Connection::fromDsn('redis://127.0.0.1?tls=1', [], $redis);
} }
/**
* @group legacy
*/
public function testFromDsnWithTlsOption() public function testFromDsnWithTlsOption()
{ {
$redis = $this->createMock(\Redis::class); $redis = $this->createMock(\Redis::class);
@ -108,6 +114,17 @@ class ConnectionTest extends TestCase
Connection::fromDsn('redis://127.0.0.1', ['tls' => true], $redis); Connection::fromDsn('redis://127.0.0.1', ['tls' => true], $redis);
} }
public function testFromDsnWithRedissScheme()
{
$redis = $this->createMock(\Redis::class);
$redis->expects($this->once())
->method('connect')
->with('tls://127.0.0.1', 6379)
->willReturn(null);
Connection::fromDsn('rediss://127.0.0.1', [], $redis);
}
public function testFromDsnWithQueryOptions() public function testFromDsnWithQueryOptions()
{ {
$this->assertEquals( $this->assertEquals(

View File

@ -119,9 +119,10 @@ class Connection
public static function fromDsn(string $dsn, array $redisOptions = [], \Redis $redis = null): self public static function fromDsn(string $dsn, array $redisOptions = [], \Redis $redis = null): self
{ {
$url = $dsn; $url = $dsn;
$scheme = 0 === strpos($dsn, 'rediss:') ? 'rediss' : 'redis';
if (preg_match('#^redis:///([^:@])+$#', $dsn)) { if (preg_match('#^'.$scheme.':///([^:@])+$#', $dsn)) {
$url = str_replace('redis:', 'file:', $dsn); $url = str_replace($scheme.':', 'file:', $dsn);
} }
if (false === $parsedUrl = parse_url($url)) { if (false === $parsedUrl = parse_url($url)) {
@ -164,8 +165,9 @@ class Connection
unset($redisOptions['dbindex']); unset($redisOptions['dbindex']);
} }
$tls = false; $tls = 'rediss' === $scheme;
if (\array_key_exists('tls', $redisOptions)) { if (\array_key_exists('tls', $redisOptions)) {
trigger_deprecation('symfony/redis-messenger', '5.3', 'Providing "tls" parameter is deprecated, use "rediss://" DSN scheme instead');
$tls = filter_var($redisOptions['tls'], \FILTER_VALIDATE_BOOLEAN); $tls = filter_var($redisOptions['tls'], \FILTER_VALIDATE_BOOLEAN);
unset($redisOptions['tls']); unset($redisOptions['tls']);
} }

View File

@ -43,7 +43,7 @@ class TransportFactory implements TransportFactoryInterface
$packageSuggestion = ' Run "composer require symfony/amqp-messenger" to install AMQP transport.'; $packageSuggestion = ' Run "composer require symfony/amqp-messenger" to install AMQP transport.';
} elseif (0 === strpos($dsn, 'doctrine://')) { } elseif (0 === strpos($dsn, 'doctrine://')) {
$packageSuggestion = ' Run "composer require symfony/doctrine-messenger" to install Doctrine transport.'; $packageSuggestion = ' Run "composer require symfony/doctrine-messenger" to install Doctrine transport.';
} elseif (0 === strpos($dsn, 'redis://')) { } elseif (0 === strpos($dsn, 'redis://') || 0 === strpos($dsn, 'rediss://')) {
$packageSuggestion = ' Run "composer require symfony/redis-messenger" to install Redis transport.'; $packageSuggestion = ' Run "composer require symfony/redis-messenger" to install Redis transport.';
} elseif (0 === strpos($dsn, 'sqs://') || preg_match('#^https://sqs\.[\w\-]+\.amazonaws\.com/.+#', $dsn)) { } elseif (0 === strpos($dsn, 'sqs://') || preg_match('#^https://sqs\.[\w\-]+\.amazonaws\.com/.+#', $dsn)) {
$packageSuggestion = ' Run "composer require symfony/amazon-sqs-messenger" to install Amazon SQS transport.'; $packageSuggestion = ' Run "composer require symfony/amazon-sqs-messenger" to install Amazon SQS transport.';