diff --git a/lib/SimpleSAML/Store/Redis.php b/lib/SimpleSAML/Store/Redis.php index 9091ddd631ebb9fffa80c48706fa73919f2d9af8..310caa98f42cb480cc1e8d17102a20d7f7c0cc82 100644 --- a/lib/SimpleSAML/Store/Redis.php +++ b/lib/SimpleSAML/Store/Redis.php @@ -31,13 +31,14 @@ class Redis extends Store $host = $config->getString('store.redis.host', 'localhost'); $port = $config->getInteger('store.redis.port', 6379); $prefix = $config->getString('store.redis.prefix', 'SimpleSAMLphp'); + $password = $config->getString('store.redis.password', ''); $redis = new \Predis\Client( [ 'scheme' => 'tcp', 'host' => $host, 'port' => $port, - ], + ] + (!empty($password) ? ['password' => $password] : []), [ 'prefix' => $prefix, ] diff --git a/tests/lib/SimpleSAML/Store/RedisTest.php b/tests/lib/SimpleSAML/Store/RedisTest.php index 7774a5dd211cf72b069bd9535bdbb592a3110890..b1e8cc0e0b4d6564b812a7c5aea57bbc5058463c 100644 --- a/tests/lib/SimpleSAML/Store/RedisTest.php +++ b/tests/lib/SimpleSAML/Store/RedisTest.php @@ -88,6 +88,27 @@ class RedisTest extends TestCase $this->clearInstance($store, '\SimpleSAML\Store'); } + /** + * @covers \SimpleSAML\Store::getInstance + * @covers \SimpleSAML\Store\Redis::__construct + * @test + */ + public function testRedisInstanceWithPassword() + { + $config = Configuration::loadFromArray([ + 'store.type' => 'redis', + 'store.redis.prefix' => 'phpunit_', + 'store.redis.password' => 'password', + ], '[ARRAY]', 'simplesaml'); + + $store = Store::getInstance(); + + $this->assertInstanceOf('SimpleSAML\Store\Redis', $store); + + $this->clearInstance($config, '\SimpleSAML\Configuration'); + $this->clearInstance($store, '\SimpleSAML\Store'); + } + /** * @covers \SimpleSAML\Store\Redis::get * @covers \SimpleSAML\Store\Redis::set