summaryrefslogtreecommitdiff
path: root/test/lib
diff options
context:
space:
mode:
Diffstat (limited to 'test/lib')
-rw-r--r--test/lib/OAuth2/Storage/Bootstrap.php35
-rw-r--r--test/lib/OAuth2/Storage/MockRedisClient.php96
2 files changed, 34 insertions, 97 deletions
diff --git a/test/lib/OAuth2/Storage/Bootstrap.php b/test/lib/OAuth2/Storage/Bootstrap.php
index 673a01a..d1e7818 100644
--- a/test/lib/OAuth2/Storage/Bootstrap.php
+++ b/test/lib/OAuth2/Storage/Bootstrap.php
@@ -8,6 +8,7 @@ class Bootstrap
private $mysql;
private $sqlite;
private $mongo;
+ private $redis;
private $configDir;
public function __construct()
@@ -45,7 +46,16 @@ class Bootstrap
public function getRedisStorage()
{
- return new Redis(new MockRedisClient());
+ if (!$this->redis) {
+ if (class_exists('Predis\Client')) {
+ $redis = new \Predis\Client();
+ $redis->flushdb();
+ $this->redis = new Redis($redis);
+ $this->createRedisDb($this->redis);
+ }
+ }
+
+ return $this->redis;
}
public function getMysqlPdo()
@@ -159,6 +169,29 @@ class Bootstrap
$db->oauth_users->insert(array('username' => "testuser", 'password' => "password"));
}
+ private function createRedisDb(Redis $storage)
+ {
+ $storage->setClientDetails("oauth_test_client", "testpass", "http://example.com", 'implicit password');
+ $storage->setAccessToken("testtoken", "Some Client", '', time() + 1000);
+ $storage->setAuthorizationCode("testcode", "Some Client", '', '', time() + 1000);
+ $storage->setUser("testuser", "password");
+
+ $storage->setScope('supportedscope1 supportedscope2 supportedscope3 supportedscope4');
+ $storage->setScope('defaultscope1 defaultscope2', null, 'default');
+
+ $storage->setScope('clientscope1 clientscope2', 'Test Client ID');
+ $storage->setScope('clientscope1 clientscope2', 'Test Client ID', 'default');
+
+ $storage->setScope('clientscope1 clientscope2 clientscope3', 'Test Client ID 2');
+ $storage->setScope('clientscope1 clientscope2', 'Test Client ID 2', 'default');
+
+ $storage->setScope('clientscope1 clientscope2', 'Test Default Scope Client ID');
+ $storage->setScope('clientscope1 clientscope2', 'Test Default Scope Client ID', 'default');
+
+ $storage->setScope('clientscope1 clientscope2 clientscope3', 'Test Default Scope Client ID 2');
+ $storage->setScope('clientscope3', 'Test Default Scope Client ID 2', 'default');
+ }
+
public function removeMongoDb(\MongoDB $db)
{
$db->drop();
diff --git a/test/lib/OAuth2/Storage/MockRedisClient.php b/test/lib/OAuth2/Storage/MockRedisClient.php
deleted file mode 100644
index dbfe264..0000000
--- a/test/lib/OAuth2/Storage/MockRedisClient.php
+++ /dev/null
@@ -1,96 +0,0 @@
-<?php
-
-namespace OAuth2\Storage;
-
-class MockRedisClient
-{
- public function __construct()
- {
- $data = array(
- 'oauth_clients:oauth_test_client' => array(
- 'client_id' => 'oauth_test_client',
- 'client_secret' => "testpass",
- 'redirect_uri' => '',
- 'grant_types' => 'implicit password',
- ),
- 'oauth_clients:Test Client ID' => array(
- 'client_id' => 'Test Client ID',
- 'client_secret' => "TestSecret"
- ),
- 'oauth_clients:Test Client ID 2' => array(
- 'client_id' => 'Test Client ID 2',
- 'client_secret' => "TestSecret",
- ),
- 'oauth_clients:Test Default Scope Client ID' => array(
- 'client_id' => 'Test Default Scope Client ID',
- 'client_secret' => "TestSecret",
- ),
- 'oauth_clients:Test Default Scope Client ID 2' => array(
- 'client_id' => 'Test Default Scope Client ID 2',
- 'client_secret' => "TestSecret",
- ),
- 'oauth_access_tokens:testtoken' => array(
- 'access_token' => 'testtoken',
- 'client_id' => "Some Client",
- 'user_id' => '',
- 'expires' => 0,
- 'scope' => ''
- ),
- 'oauth_authorization_codes:testcode' => array(
- 'client_id' => "Some Client",
- 'authorization_code' => 'testcode',
- 'user_id' => '',
- 'redirect_uri' => '',
- 'expires' => 0,
- 'scope' => ''
- ),
- 'oauth_users:testuser' => array(
- 'user_id' => 'testuser',
- 'password' => "password",
- 'first_name' => '',
- 'last_name' => ''
- ),
- 'oauth_scopes:supported:global' => 'supportedscope1 supportedscope2 supportedscope3 supportedscope4',
- 'oauth_scopes:default:global' => 'defaultscope1 defaultscope2',
- 'oauth_scopes:supported:Test Client ID' => 'clientscope1 clientscope2',
- 'oauth_scopes:default:Test Client ID' => 'clientscope1 clientscope2',
- 'oauth_scopes:supported:Test Client ID 2' => 'clientscope3',
- 'oauth_scopes:default:Test Client ID 2' => 'clientscope3',
- 'oauth_scopes:supported:Test Default Scope Client ID' => 'clientscope1 clientscope2',
- 'oauth_scopes:default:Test Default Scope Client ID' => 'clientscope1 clientscope2',
- 'oauth_scopes:supported:Test Default Scope Client ID 2' => 'clientscope3',
- 'oauth_scopes:default:Test Default Scope Client ID 2' => 'clientscope3',
- );
- foreach ($data as $name => $val) {
- $data[$name] = json_encode($val);
- }
- $this->data = $data;
- }
-
- public function get($key)
- {
- return isset($this->data[$key]) ? $this->data[$key] : null;
- }
-
- public function set ($key, $value)
- {
- $this->data[$key] = $value;
-
- return true;
- }
-
- public function setex($key, $expires, $value)
- {
-
- $this->data[$key] = $value;
-
- return true;
- }
-
- public function expire($key)
- {
- unset($this->data[$key]);
-
- return true;
- }
-}