[Messenger] Add TLS option to Redis transport's DSN
This commit is contained in:
parent
f0748f8978
commit
09ec907a7e
@ -5,3 +5,4 @@ CHANGELOG
|
||||
-----
|
||||
|
||||
* Introduced the Redis bridge.
|
||||
* Added TLS option in the DSN. Example: `redis://127.0.0.1?tls=1`
|
||||
|
@ -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(
|
||||
|
@ -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'],
|
||||
|
Reference in New Issue
Block a user