Skip to content

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

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
Feb 26, 2021
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
1 change: 1 addition & 0 deletions UPGRADE-5.3.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 use of TLS option for Redis Bridge, use `rediss://127.0.0.1` instead of `redis://127.0.0.1?tls=1`

Notifier
--------
Expand Down
1 change: 1 addition & 0 deletions UPGRADE-6.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -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::getWaitingTime()` has been updated to `RetryStrategyInterface::getWaitingTime(Envelope $message, \Throwable $throwable = null)`.
* 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
----
Expand Down
6 changes: 6 additions & 0 deletions src/Symfony/Component/Messenger/Bridge/Redis/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
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
-----

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ public function testFromDsnWithOptionsAndTrailingSlash()
);
}

/**
* @group legacy
*/
public function testFromDsnWithTls()
{
$redis = $this->createMock(\Redis::class);
Expand All @@ -97,6 +100,9 @@ public function testFromDsnWithTls()
Connection::fromDsn('redis://127.0.0.1?tls=1', [], $redis);
}

/**
* @group legacy
*/
public function testFromDsnWithTlsOption()
{
$redis = $this->createMock(\Redis::class);
Expand All @@ -108,6 +114,17 @@ public function testFromDsnWithTlsOption()
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()
{
$this->assertEquals(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,10 @@ public function __construct(array $configuration, array $connectionCredentials =
public static function fromDsn(string $dsn, array $redisOptions = [], \Redis $redis = null): self
{
$url = $dsn;
$scheme = 0 === strpos($dsn, 'rediss:') ? 'rediss' : 'redis';

if (preg_match('#^redis:///([^:@])+$#', $dsn)) {
$url = str_replace('redis:', 'file:', $dsn);
if (preg_match('#^'.$scheme.':///([^:@])+$#', $dsn)) {
$url = str_replace($scheme.':', 'file:', $dsn);
}

if (false === $parsedUrl = parse_url($url)) {
Expand Down Expand Up @@ -164,8 +165,9 @@ public static function fromDsn(string $dsn, array $redisOptions = [], \Redis $re
unset($redisOptions['dbindex']);
}

$tls = false;
$tls = 'rediss' === $scheme;
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);
unset($redisOptions['tls']);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function createTransport(string $dsn, array $options, SerializerInterface
$packageSuggestion = ' Run "composer require symfony/amqp-messenger" to install AMQP transport.';
} elseif (0 === strpos($dsn, 'doctrine://')) {
$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.';
} 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.';
Expand Down