Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
feature #35503 [Messenger] Add TLS option to Redis transport's DSN (N…
…yholm)

This PR was squashed before being merged into the 5.1-dev branch (closes #35503).

Discussion
----------

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

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| Deprecations? | no
| Tickets       | Fix #33025
| License       | MIT
| Doc PR        |

As suggested by @matas-valuzis, this will enable TLS support for Redis transport.

Configure it with the following DSN

```
redis://127.0.0.1?tls=1
```

The implementation just prefix the host with `tls://` as described here: https://github.com/phpredis/phpredis#connect-open

It is already possible to use TLS with the Redis transport, but there are not support in the DSN until now.

Commits
-------

09ec907 [Messenger] Add TLS option to Redis transport's DSN
  • Loading branch information
fabpot committed Jan 29, 2020
2 parents f0748f8 + 09ec907 commit 8769c7a
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/Symfony/Component/Messenger/Bridge/Redis/CHANGELOG.md
Expand Up @@ -5,3 +5,4 @@ CHANGELOG
-----

* Introduced the Redis bridge.
* Added TLS option in the DSN. Example: `redis://127.0.0.1?tls=1`
Expand Up @@ -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
Expand Down Expand Up @@ -73,6 +73,28 @@ public function testFromDsnWithOptions()
);
}

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(
Expand Down
Expand Up @@ -104,6 +104,12 @@ public static function fromDsn(string $dsn, array $redisOptions = [], \Redis $re
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,
Expand All @@ -125,6 +131,9 @@ public static function fromDsn(string $dsn, array $redisOptions = [], \Redis $re
$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'],
Expand Down

0 comments on commit 8769c7a

Please sign in to comment.