mirror of
https://github.com/predis/predis.git
synced 2026-08-30 04:02:22 +00:00
sentinel default to no password when replica authentication is used (#807)
* set default nopass if password is not provided * remove debug output * added tests for noauth sentinel * Update SentinelReplication.php Co-authored-by: Mehmet Tolga Avcioglu <mehmet.avcioglu@pusula.net.tr> Co-authored-by: Till Krüss <tillkruss@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
bb6c1a7b6d
commit
1a0eb7ee85
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
*/
|
||||
|
||||
@@ -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');
|
||||
|
||||
Reference in New Issue
Block a user