Skip to content
Snippets Groups Projects
Unverified Commit 1f0a1f22 authored by Thijs Kinkhorst's avatar Thijs Kinkhorst Committed by GitHub
Browse files

Merge pull request #1012 from benrj/redis-password-support

Add Password Support to Redis library
parents 03c6b6e0 7992d4ee
No related branches found
No related tags found
No related merge requests found
...@@ -161,7 +161,7 @@ The required tables are created automatically. If you are storing data from mult ...@@ -161,7 +161,7 @@ The required tables are created automatically. If you are storing data from mult
To store sessions in Redis, set the `store.type` option to `redis`. To store sessions in Redis, set the `store.type` option to `redis`.
By default SimpleSAMLphp will attempt to connect to Redis on the `localhost` at port `6379`. These can be configured via the `store.redis.host` and `store.redis.port` options, respectively. You may also set a key prefix with the `store.redis.prefix` option. By default SimpleSAMLphp will attempt to connect to Redis on the `localhost` at port `6379`. These can be configured via the `store.redis.host` and `store.redis.port` options, respectively. You may also set a key prefix with the `store.redis.prefix` option. For Redis instances that [require authentication](https://redis.io/commands/auth), use the `store.redis.password` option.
## Metadata storage ## Metadata storage
......
...@@ -31,13 +31,14 @@ class Redis extends Store ...@@ -31,13 +31,14 @@ class Redis extends Store
$host = $config->getString('store.redis.host', 'localhost'); $host = $config->getString('store.redis.host', 'localhost');
$port = $config->getInteger('store.redis.port', 6379); $port = $config->getInteger('store.redis.port', 6379);
$prefix = $config->getString('store.redis.prefix', 'SimpleSAMLphp'); $prefix = $config->getString('store.redis.prefix', 'SimpleSAMLphp');
$password = $config->getString('store.redis.password', '');
$redis = new \Predis\Client( $redis = new \Predis\Client(
[ [
'scheme' => 'tcp', 'scheme' => 'tcp',
'host' => $host, 'host' => $host,
'port' => $port, 'port' => $port,
], ] + (!empty($password) ? ['password' => $password] : []),
[ [
'prefix' => $prefix, 'prefix' => $prefix,
] ]
......
...@@ -88,6 +88,27 @@ class RedisTest extends TestCase ...@@ -88,6 +88,27 @@ class RedisTest extends TestCase
$this->clearInstance($store, '\SimpleSAML\Store'); $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::get
* @covers \SimpleSAML\Store\Redis::set * @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