diff --git a/src/Connection/Replication/SentinelReplication.php b/src/Connection/Replication/SentinelReplication.php index 8ad2f480..b91807a7 100644 --- a/src/Connection/Replication/SentinelReplication.php +++ b/src/Connection/Replication/SentinelReplication.php @@ -269,6 +269,12 @@ class SentinelReplication implements ReplicationInterface $parameters['database'] = null; $parameters['username'] = null; + // don't leak password from between configurations + // https://github.com/predis/predis/pull/807/#discussion_r985764770 + if (! isset($parameters['password'])) { + $parameters['password'] = null; + } + if (!isset($parameters['timeout'])) { $parameters['timeout'] = $this->sentinelTimeout; } diff --git a/tests/Predis/Connection/Replication/SentinelReplicationTest.php b/tests/Predis/Connection/Replication/SentinelReplicationTest.php index 636a1de8..a4d57fbd 100644 --- a/tests/Predis/Connection/Replication/SentinelReplicationTest.php +++ b/tests/Predis/Connection/Replication/SentinelReplicationTest.php @@ -62,6 +62,7 @@ class SentinelReplicationTest extends PredisTestCase $this->assertArrayNotHasKey('database', $parameters, 'Parameter `database` was expected to not exist in connection parameters'); $this->assertArrayNotHasKey('username', $parameters, 'Parameter `username` was expected to not exist in connection parameters'); + $this->assertArrayNotHasKey('password', $parameters, 'Parameter `password` was expected to not exist in connection parameters'); } /** @@ -117,6 +118,30 @@ class SentinelReplicationTest extends PredisTestCase $this->assertNotNull($parameters->database); } + /** + * @group disconnected + */ + public function testConnectionParametersInstanceForSentinelConnectionIsNotModifiedEmptyPassword(): void + { + $sentinel1 = Connection\Parameters::create('tcp://127.0.0.1:5381?role=sentinel&database=1&password='); + $sentinel2 = Connection\Parameters::create('tcp://127.0.0.1:5381?role=sentinel&database=1'); + + $replication1 = $this->getReplicationConnection('svc', array($sentinel1)); + $replication2 = $this->getReplicationConnection('svc', array($sentinel2)); + + $parameters1 = $replication1->getSentinelConnection()->getParameters(); + $parameters2 = $replication2->getSentinelConnection()->getParameters(); + + $this->assertSame($sentinel1, $parameters1); + $this->assertSame($sentinel2, $parameters2); + + $this->assertNull($parameters1->password); + $this->assertNull($parameters2->password); + + $this->assertNotNull($parameters1->database); + $this->assertNotNull($parameters2->database); + } + /** * @group disconnected */ diff --git a/tests/Predis/Connection/StreamConnectionTest.php b/tests/Predis/Connection/StreamConnectionTest.php index 81bbfb70..a31a6c3e 100644 --- a/tests/Predis/Connection/StreamConnectionTest.php +++ b/tests/Predis/Connection/StreamConnectionTest.php @@ -62,7 +62,6 @@ class StreamConnectionTest extends PredisConnectionTestCase */ public function testDoesntThrowErrorOnInvalidResource(): void { - var_dump('PHP v' . PHP_VERSION); $this->expectException('Predis\Connection\ConnectionException'); $cmdSelect = RawCommand::create('SELECT', '1000');