Skip to content
Snippets Groups Projects
Commit 4c7a6818 authored by Ben Johnson's avatar Ben Johnson
Browse files

Add Password support to Redis library

For Redis instances that require authentication, the current Redis store does not work.  So, this commit adds optional support for utilizing the Predis password option.  It will pick up the password from the config file and pass it along when it instantiates the Predis client.

The test simply checks that adding the password option doesn't break the constructor. Since Predis parameters end up as protected, we can't verify that the instance contains the password.
parent 03c6b6e0
No related branches found
No related tags found
No related merge requests found
......@@ -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,
]
......
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment