summaryrefslogtreecommitdiff
path: root/test/lib
diff options
context:
space:
mode:
Diffstat (limited to 'test/lib')
-rw-r--r--test/lib/OAuth2/Request/TestRequest.php1
-rw-r--r--test/lib/OAuth2/Storage/BaseTest.php29
-rw-r--r--test/lib/OAuth2/Storage/Bootstrap.php67
-rw-r--r--test/lib/OAuth2/Storage/MockRedisClient.php41
4 files changed, 115 insertions, 23 deletions
diff --git a/test/lib/OAuth2/Request/TestRequest.php b/test/lib/OAuth2/Request/TestRequest.php
index aa471f2..5e0d081 100644
--- a/test/lib/OAuth2/Request/TestRequest.php
+++ b/test/lib/OAuth2/Request/TestRequest.php
@@ -58,6 +58,7 @@ class TestRequest implements RequestInterface
{
$request = new self();
$request->setPost($params);
+
return $request;
}
}
diff --git a/test/lib/OAuth2/Storage/BaseTest.php b/test/lib/OAuth2/Storage/BaseTest.php
new file mode 100644
index 0000000..2b09265
--- /dev/null
+++ b/test/lib/OAuth2/Storage/BaseTest.php
@@ -0,0 +1,29 @@
+<?php
+
+namespace OAuth2\Storage;
+
+abstract class BaseTest extends \PHPUnit_Framework_TestCase
+{
+ public function provideStorage()
+ {
+ $mysql = Bootstrap::getInstance()->getMysqlPdo();
+ $sqlite = Bootstrap::getInstance()->getSqlitePdo();
+ $mongo = Bootstrap::getInstance()->getMongo();
+ $redis = Bootstrap::getInstance()->getRedisStorage();
+
+ /* hack until we can fix "default_scope" dependencies in other tests */
+ // $memory = Bootstrap::getInstance()->getMemoryStorage();
+ $memoryConfig = json_decode(file_get_contents(__DIR__.'/../../../config/storage.json'), true);
+ $memoryConfig['default_scope'] = 'defaultscope1 defaultscope2';
+ $memory = new Memory($memoryConfig);
+
+ // will add multiple storage types later
+ return array(
+ array($memory),
+ array($sqlite),
+ array($mysql),
+ array($mongo),
+ array($redis)
+ );
+ }
+}
diff --git a/test/lib/OAuth2/Storage/Bootstrap.php b/test/lib/OAuth2/Storage/Bootstrap.php
index 9b0839f..673a01a 100644
--- a/test/lib/OAuth2/Storage/Bootstrap.php
+++ b/test/lib/OAuth2/Storage/Bootstrap.php
@@ -8,12 +8,19 @@ class Bootstrap
private $mysql;
private $sqlite;
private $mongo;
+ private $configDir;
+
+ public function __construct()
+ {
+ $this->configDir = __DIR__.'/../../../config';
+ }
public static function getInstance()
{
if (!self::$instance) {
self::$instance = new self();
}
+
return self::$instance;
}
@@ -27,12 +34,13 @@ class Bootstrap
$this->sqlite = new Pdo($pdo);
}
+
return $this->sqlite;
}
public function getMemoryStorage()
{
- return new Memory(json_decode(file_get_contents(dirname(__FILE__).'/../../../config/storage.json'), true));
+ return new Memory(json_decode(file_get_contents($this->configDir. '/storage.json'), true));
}
public function getRedisStorage()
@@ -50,6 +58,7 @@ class Bootstrap
$this->mysql = new Pdo($pdo);
}
+
return $this->mysql;
}
@@ -66,22 +75,13 @@ class Bootstrap
$this->mongo = new Mongo($db);
}
}
+
return $this->mongo;
}
private function createSqliteDb(\PDO $pdo)
{
- $pdo->exec('CREATE TABLE oauth_clients (client_id TEXT, client_secret TEXT, redirect_uri TEXT, grant_types TEXT)');
- $pdo->exec('CREATE TABLE oauth_access_tokens (access_token TEXT, client_id TEXT, user_id TEXT, expires TIMESTAMP, scope TEXT)');
- $pdo->exec('CREATE TABLE oauth_authorization_codes (authorization_code TEXT, client_id TEXT, user_id TEXT, redirect_uri TEXT, expires TIMESTAMP, scope TEXT)');
- $pdo->exec('CREATE TABLE oauth_users (username TEXT, password TEXT, first_name TEXT, last_name TEXT)');
- $pdo->exec('CREATE TABLE oauth_refresh_tokens (refresh_token TEXT, client_id TEXT, user_id TEXT, expires TIMESTAMP, scope TEXT)');
-
- // test data
- $pdo->exec('INSERT INTO oauth_clients (client_id, client_secret, grant_types) VALUES ("oauth_test_client", "testpass", "implicit password")');
- $pdo->exec('INSERT INTO oauth_access_tokens (access_token, client_id) VALUES ("testtoken", "Some Client")');
- $pdo->exec('INSERT INTO oauth_authorization_codes (authorization_code, client_id) VALUES ("testcode", "Some Client")');
- $pdo->exec('INSERT INTO oauth_users (username, password) VALUES ("testuser", "password")');
+ $this->runPdoSql($pdo);
}
private function removeSqliteDb()
@@ -95,17 +95,45 @@ class Bootstrap
{
$pdo->exec('CREATE DATABASE oauth2_server_php');
$pdo->exec('USE oauth2_server_php');
- $pdo->exec('CREATE TABLE oauth_clients (client_id TEXT, client_secret TEXT, redirect_uri TEXT, grant_types TEXT)');
+ $this->runPdoSql($pdo);
+ }
+
+ public function runPdoSql(\PDO $pdo)
+ {
+ $pdo->exec('CREATE TABLE oauth_clients (client_id TEXT, client_secret TEXT, redirect_uri TEXT, grant_types TEXT, user_id TEXT)');
$pdo->exec('CREATE TABLE oauth_access_tokens (access_token TEXT, client_id TEXT, user_id TEXT, expires DATETIME, scope TEXT)');
$pdo->exec('CREATE TABLE oauth_authorization_codes (authorization_code TEXT, client_id TEXT, user_id TEXT, redirect_uri TEXT, expires DATETIME, scope TEXT)');
$pdo->exec('CREATE TABLE oauth_users (username TEXT, password TEXT, first_name TEXT, last_name TEXT)');
$pdo->exec('CREATE TABLE oauth_refresh_tokens (refresh_token TEXT, client_id TEXT, user_id TEXT, expires DATETIME, scope TEXT)');
-
- // test data
+ $pdo->exec('CREATE TABLE oauth_scopes (type TEXT, scope TEXT, client_id TEXT)');
+ $pdo->exec('CREATE TABLE oauth_public_keys (client_id TEXT, public_key TEXT, private_key TEXT, encryption_algorithm VARCHAR(100) DEFAULT "RS256")');
+
+ // set up scopes
+ $pdo->exec('INSERT INTO oauth_scopes (type, scope) VALUES ("supported", "supportedscope1 supportedscope2 supportedscope3 supportedscope4")');
+ $pdo->exec('INSERT INTO oauth_scopes (type, scope) VALUES ("default", "defaultscope1 defaultscope2")');
+ $pdo->exec('INSERT INTO oauth_scopes (type, scope, client_id) VALUES ("supported", "clientscope1 clientscope2", "Test Client ID")');
+ $pdo->exec('INSERT INTO oauth_scopes (type, scope, client_id) VALUES ("default", "clientscope1 clientscope2", "Test Client ID")');
+ $pdo->exec('INSERT INTO oauth_scopes (type, scope, client_id) VALUES ("supported", "clientscope1 clientscope2 clientscope3", "Test Client ID 2")');
+ $pdo->exec('INSERT INTO oauth_scopes (type, scope, client_id) VALUES ("default", "clientscope1 clientscope2", "Test Client ID 2")');
+ $pdo->exec('INSERT INTO oauth_scopes (type, scope, client_id) VALUES ("supported", "clientscope1 clientscope2", "Test Default Scope Client ID")');
+ $pdo->exec('INSERT INTO oauth_scopes (type, scope, client_id) VALUES ("default", "clientscope1 clientscope2", "Test Default Scope Client ID")');
+ $pdo->exec('INSERT INTO oauth_scopes (type, scope, client_id) VALUES ("supported", "clientscope1 clientscope2 clientscope3", "Test Default Scope Client ID 2")');
+ $pdo->exec('INSERT INTO oauth_scopes (type, scope, client_id) VALUES ("default", "clientscope3", "Test Default Scope Client ID 2")');
+
+ // set up clients
+ $pdo->exec('INSERT INTO oauth_clients (client_id, client_secret) VALUES ("Test Client ID", "TestSecret")');
+ $pdo->exec('INSERT INTO oauth_clients (client_id, client_secret) VALUES ("Test Client ID 2", "TestSecret")');
+ $pdo->exec('INSERT INTO oauth_clients (client_id, client_secret) VALUES ("Test Default Scope Client ID", "TestSecret")');
+ $pdo->exec('INSERT INTO oauth_clients (client_id, client_secret) VALUES ("Test Default Scope Client ID 2", "TestSecret")');
$pdo->exec('INSERT INTO oauth_clients (client_id, client_secret, grant_types) VALUES ("oauth_test_client", "testpass", "implicit password")');
+
+ // set up misc
$pdo->exec('INSERT INTO oauth_access_tokens (access_token, client_id) VALUES ("testtoken", "Some Client")');
$pdo->exec('INSERT INTO oauth_authorization_codes (authorization_code, client_id) VALUES ("testcode", "Some Client")');
$pdo->exec('INSERT INTO oauth_users (username, password) VALUES ("testuser", "password")');
+ $pdo->exec('INSERT INTO oauth_public_keys (client_id, public_key, private_key, encryption_algorithm) VALUES ("ClientID_One", "client_1_public", "client_1_private", "RS256")');
+ $pdo->exec('INSERT INTO oauth_public_keys (client_id, public_key, private_key, encryption_algorithm) VALUES ("ClientID_Two", "client_2_public", "client_2_private", "RS256")');
+ $pdo->exec(sprintf('INSERT INTO oauth_public_keys (client_id, public_key, private_key, encryption_algorithm) VALUES (NULL, "%s", "%s", "RS256")', file_get_contents($this->configDir.'/keys/id_rsa.pub'), file_get_contents($this->configDir.'/keys/id_rsa')));
}
public function removeMysqlDb(\PDO $pdo)
@@ -113,9 +141,14 @@ class Bootstrap
$pdo->exec('DROP DATABASE IF EXISTS oauth2_server_php');
}
- private function getSqliteDir()
+ public function getSqliteDir()
+ {
+ return $this->configDir. '/test.sqlite';
+ }
+
+ public function getConfigDir()
{
- return dirname(__FILE__).'/../../../config/test.sqlite';
+ return $this->configDir;
}
private function createMongoDb(\MongoDB $db)
diff --git a/test/lib/OAuth2/Storage/MockRedisClient.php b/test/lib/OAuth2/Storage/MockRedisClient.php
index 75dde33..dbfe264 100644
--- a/test/lib/OAuth2/Storage/MockRedisClient.php
+++ b/test/lib/OAuth2/Storage/MockRedisClient.php
@@ -13,6 +13,22 @@ class MockRedisClient
'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",
@@ -33,35 +49,48 @@ class MockRedisClient
'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 ) {
+ foreach ($data as $name => $val) {
$data[$name] = json_encode($val);
}
$this->data = $data;
}
- function get($key)
+ public function get($key)
{
return isset($this->data[$key]) ? $this->data[$key] : null;
}
- function set ($key, $value)
+ public function set ($key, $value)
{
$this->data[$key] = $value;
+
return true;
}
- function setex($key, $expires, $value)
+ public function setex($key, $expires, $value)
{
$this->data[$key] = $value;
+
return true;
}
- function expire($key)
+ public function expire($key)
{
unset($this->data[$key]);
+
return true;
}
}