From f03bf4bdd8b6515b58a176d1670dd984616c85a3 Mon Sep 17 00:00:00 2001 From: Ruslan Zavacky Date: Wed, 8 Sep 2021 14:24:05 +0300 Subject: [PATCH 1/5] [Messenger] Support rediss in transport bridge --- Tests/Transport/RedisTransportFactoryTest.php | 1 + Transport/RedisTransportFactory.php | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Tests/Transport/RedisTransportFactoryTest.php b/Tests/Transport/RedisTransportFactoryTest.php index 728fe67..754e5ae 100644 --- a/Tests/Transport/RedisTransportFactoryTest.php +++ b/Tests/Transport/RedisTransportFactoryTest.php @@ -27,6 +27,7 @@ public function testSupportsOnlyRedisTransports() $factory = new RedisTransportFactory(); $this->assertTrue($factory->supports('redis://localhost', [])); + $this->assertTrue($factory->supports('rediss://localhost', [])); $this->assertFalse($factory->supports('sqs://localhost', [])); $this->assertFalse($factory->supports('invalid-dsn', [])); } diff --git a/Transport/RedisTransportFactory.php b/Transport/RedisTransportFactory.php index 55deeb0..88cead8 100644 --- a/Transport/RedisTransportFactory.php +++ b/Transport/RedisTransportFactory.php @@ -30,7 +30,7 @@ public function createTransport(string $dsn, array $options, SerializerInterface public function supports(string $dsn, array $options): bool { - return 0 === strpos($dsn, 'redis://'); + return 0 === strpos($dsn, 'redis://') || 0 === strpos($dsn, 'rediss://'); } } From c49156985aeecb44a2dcc4a68638ed648f7b46d5 Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Tue, 14 Sep 2021 19:26:58 +0200 Subject: [PATCH 2/5] [Messenger] Fix broken Redis mocks --- Tests/Transport/ConnectionTest.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Tests/Transport/ConnectionTest.php b/Tests/Transport/ConnectionTest.php index 9223d5a..5becdb8 100644 --- a/Tests/Transport/ConnectionTest.php +++ b/Tests/Transport/ConnectionTest.php @@ -78,7 +78,7 @@ public function testFromDsnWithTls() $redis->expects($this->once()) ->method('connect') ->with('tls://127.0.0.1', 6379) - ->willReturn(null); + ->willReturn(true); Connection::fromDsn('redis://127.0.0.1?tls=1', [], $redis); } @@ -92,7 +92,7 @@ public function testFromDsnWithTlsOption() $redis->expects($this->once()) ->method('connect') ->with('tls://127.0.0.1', 6379) - ->willReturn(null); + ->willReturn(true); Connection::fromDsn('redis://127.0.0.1', ['tls' => true], $redis); } @@ -103,7 +103,7 @@ public function testFromDsnWithRedissScheme() $redis->expects($this->once()) ->method('connect') ->with('tls://127.0.0.1', 6379) - ->willReturn(null); + ->willReturn(true); Connection::fromDsn('rediss://127.0.0.1', [], $redis); } @@ -315,7 +315,7 @@ public function testMaxEntries() $redis->expects($this->exactly(1))->method('xadd') ->with('queue', '*', ['message' => '{"body":"1","headers":[]}'], 20000, true) - ->willReturn(1); + ->willReturn('1'); $connection = Connection::fromDsn('redis://localhost/queue?stream_max_entries=20000', [], $redis); // 1 = always $connection->add('1', []); @@ -355,7 +355,7 @@ public function testLastErrorGetsCleared() { $redis = $this->createMock(\Redis::class); - $redis->expects($this->once())->method('xadd')->willReturn(0); + $redis->expects($this->once())->method('xadd')->willReturn('0'); $redis->expects($this->once())->method('xack')->willReturn(0); $redis->method('getLastError')->willReturnOnConsecutiveCalls('xadd error', 'xack error'); From c26593970a32ed33125dc657e9d661eaed1ef290 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Fri, 24 Sep 2021 17:59:58 +0200 Subject: [PATCH 3/5] Merge branch '4.4' into 5.3 * 4.4: [VarDumper] fix dumping typed references from properties Update README.md [Messenger] [Redis] Allow authentication with user and password --- Tests/Transport/ConnectionTest.php | 17 ++++++++++++++--- Transport/Connection.php | 3 ++- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/Tests/Transport/ConnectionTest.php b/Tests/Transport/ConnectionTest.php index 5becdb8..1754c83 100644 --- a/Tests/Transport/ConnectionTest.php +++ b/Tests/Transport/ConnectionTest.php @@ -163,15 +163,26 @@ public function testKeepGettingPendingMessages() $this->assertNotNull($connection->get()); } - public function testAuth() + /** + * @param string|array $expected + * + * @dataProvider provideAuthDsn + */ + public function testAuth($expected, string $dsn) { $redis = $this->createMock(\Redis::class); $redis->expects($this->exactly(1))->method('auth') - ->with('password') + ->with($expected) ->willReturn(true); - Connection::fromDsn('redis://password@localhost/queue', [], $redis); + Connection::fromDsn($dsn, [], $redis); + } + + public function provideAuthDsn(): \Generator + { + yield 'Password only' => ['password', 'redis://password@localhost/queue']; + yield 'User and password' => [['user', 'password'], 'redis://user:password@localhost/queue']; } public function testAuthFromOptions() diff --git a/Transport/Connection.php b/Transport/Connection.php index 4515660..d30e3e8 100644 --- a/Transport/Connection.php +++ b/Transport/Connection.php @@ -233,7 +233,8 @@ public static function fromDsn(string $dsn, array $redisOptions = [], $redis = n $connectionCredentials = [ 'host' => $parsedUrl['host'] ?? '127.0.0.1', 'port' => $parsedUrl['port'] ?? 6379, - 'auth' => $redisOptions['auth'] ?? $parsedUrl['pass'] ?? $parsedUrl['user'] ?? null, + // See: https://github.com/phpredis/phpredis/#auth + 'auth' => $redisOptions['auth'] ?? (isset($parsedUrl['pass']) && isset($parsedUrl['user']) ? [$parsedUrl['user'], $parsedUrl['pass']] : $parsedUrl['pass'] ?? $parsedUrl['user'] ?? null), ]; $pathParts = explode('/', rtrim($parsedUrl['path'] ?? '', '/')); From 04cb86e8626de216439dccdf4f4d2d12da70af4a Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Sat, 25 Sep 2021 09:16:24 +0200 Subject: [PATCH 4/5] relax parameter type --- Transport/Connection.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Transport/Connection.php b/Transport/Connection.php index d30e3e8..a5054c1 100644 --- a/Transport/Connection.php +++ b/Transport/Connection.php @@ -111,7 +111,10 @@ public function __construct(array $configuration, array $connectionCredentials = $this->claimInterval = $configuration['claim_interval'] ?? self::DEFAULT_OPTIONS['claim_interval']; } - private static function initializeRedis(\Redis $redis, string $host, int $port, ?string $auth, int $serializer, int $dbIndex): \Redis + /** + * @param string|string[]|null $auth + */ + private static function initializeRedis(\Redis $redis, string $host, int $port, $auth, int $serializer, int $dbIndex): \Redis { $redis->connect($host, $port); $redis->setOption(\Redis::OPT_SERIALIZER, $serializer); From 4d775c1728fc3124a58376dc746e643d8ae80849 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Sat, 25 Sep 2021 10:57:14 +0200 Subject: [PATCH 5/5] [Messenger] relax parameter type in cluster mode --- Transport/Connection.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Transport/Connection.php b/Transport/Connection.php index a5054c1..7ffd04c 100644 --- a/Transport/Connection.php +++ b/Transport/Connection.php @@ -130,7 +130,10 @@ private static function initializeRedis(\Redis $redis, string $host, int $port, return $redis; } - private static function initializeRedisCluster(?\RedisCluster $redis, array $hosts, ?string $auth, int $serializer): \RedisCluster + /** + * @param string|string[]|null $auth + */ + private static function initializeRedisCluster(?\RedisCluster $redis, array $hosts, $auth, int $serializer): \RedisCluster { if (null === $redis) { $redis = new \RedisCluster(null, $hosts, 0.0, 0.0, false, $auth);