diff options
| author | Brent Shaffer <betterbrent@google.com> | 2017-01-07 02:05:12 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-01-07 02:05:12 +0300 |
| commit | b24f30db3e66f455f4daca0b933fa748e1c45da6 (patch) | |
| tree | 85b0ddbb3073b79933c0d84d81f1efaa14ee29f9 /test | |
| parent | d9f23541fd1c26a316cf109b259ab885f8f58fa1 (diff) | |
| download | oauth2-server-php-b24f30db3e66f455f4daca0b933fa748e1c45da6.tar.xz | |
Add mongo db (#790)
* add mongodb extension for php 7.x to travis
* removes mongodb library for php5 from travis
* removes HHVM from travis
Diffstat (limited to 'test')
| -rwxr-xr-x | test/lib/OAuth2/Storage/BaseTest.php | 2 | ||||
| -rwxr-xr-x | test/lib/OAuth2/Storage/Bootstrap.php | 103 |
2 files changed, 93 insertions, 12 deletions
diff --git a/test/lib/OAuth2/Storage/BaseTest.php b/test/lib/OAuth2/Storage/BaseTest.php index 921d525..f0b1274 100755 --- a/test/lib/OAuth2/Storage/BaseTest.php +++ b/test/lib/OAuth2/Storage/BaseTest.php @@ -11,6 +11,7 @@ abstract class BaseTest extends \PHPUnit_Framework_TestCase $mysql = Bootstrap::getInstance()->getMysqlPdo(); $postgres = Bootstrap::getInstance()->getPostgresPdo(); $mongo = Bootstrap::getInstance()->getMongo(); + $mongoDb = Bootstrap::getInstance()->getMongoDB(); $redis = Bootstrap::getInstance()->getRedisStorage(); $cassandra = Bootstrap::getInstance()->getCassandraStorage(); $dynamodb = Bootstrap::getInstance()->getDynamoDbStorage(); @@ -25,6 +26,7 @@ abstract class BaseTest extends \PHPUnit_Framework_TestCase array($mysql), array($postgres), array($mongo), + array($mongoDb), array($redis), array($cassandra), array($dynamodb), diff --git a/test/lib/OAuth2/Storage/Bootstrap.php b/test/lib/OAuth2/Storage/Bootstrap.php index 4ac9022..3d7bdd4 100755 --- a/test/lib/OAuth2/Storage/Bootstrap.php +++ b/test/lib/OAuth2/Storage/Bootstrap.php @@ -11,6 +11,7 @@ class Bootstrap private $sqlite; private $postgres; private $mongo; + private $mongoDb; private $redis; private $cassandra; private $configDir; @@ -137,13 +138,12 @@ class Bootstrap public function getMongo() { if (!$this->mongo) { - $skipMongo = $this->getEnvVar('SKIP_MONGO_TESTS'); - if (!$skipMongo && class_exists('MongoClient')) { + if (class_exists('MongoClient')) { $mongo = new \MongoClient('mongodb://localhost:27017', array('connect' => false)); if ($this->testMongoConnection($mongo)) { - $db = $mongo->oauth2_server_php; - $this->removeMongoDb($db); - $this->createMongoDb($db); + $db = $mongo->oauth2_server_php_legacy; + $this->removeMongo($db); + $this->createMongo($db); $this->mongo = new Mongo($db); } else { @@ -157,6 +157,28 @@ class Bootstrap return $this->mongo; } + public function getMongoDb() + { + if (!$this->mongoDb) { + if (class_exists('MongoDB\Client')) { + $mongoDb = new \MongoDB\Client('mongodb://localhost:27017'); + if ($this->testMongoDBConnection($mongoDb)) { + $db = $mongoDb->oauth2_server_php; + $this->removeMongoDb($db); + $this->createMongoDb($db); + + $this->mongoDb = new MongoDB($db); + } else { + $this->mongoDb = new NullStorage('MongoDB', 'Unable to connect to mongo server on "localhost:27017"'); + } + } else { + $this->mongoDb = new NullStorage('MongoDB', 'Missing MongoDB php extension. Please install mongodb.so'); + } + } + + return $this->mongoDb; + } + private function testMongoConnection(\MongoClient $mongo) { try { @@ -168,6 +190,11 @@ class Bootstrap return true; } + private function testMongoDBConnection(\MongoDB\Client $mongo) + { + return true; + } + public function getCouchbase() { if (!$this->couchbase) { @@ -442,7 +469,7 @@ class Bootstrap $cb->delete('oauth_refresh_tokens-refreshtoken'); } - private function createMongoDb(\MongoDB $db) + private function createMongo(\MongoDB $db) { $db->oauth_clients->insert(array( 'client_id' => "oauth_test_client", @@ -468,13 +495,70 @@ class Bootstrap 'email_verified' => true, )); + $db->oauth_keys->insert(array( + 'client_id' => null, + 'public_key' => $this->getTestPublicKey(), + 'private_key' => $this->getTestPrivateKey(), + 'encryption_algorithm' => 'RS256' + )); + $db->oauth_jwt->insert(array( 'client_id' => 'oauth_test_client', - 'key' => $this->getTestPublicKey(), + 'key' => $this->getTestPublicKey(), 'subject' => 'test_subject', )); } + public function removeMongo(\MongoDB $db) + { + $db->drop(); + } + + private function createMongoDB(\MongoDB\Database $db) + { + $db->oauth_clients->insertOne(array( + 'client_id' => "oauth_test_client", + 'client_secret' => "testpass", + 'redirect_uri' => "http://example.com", + 'grant_types' => 'implicit password' + )); + + $db->oauth_access_tokens->insertOne(array( + 'access_token' => "testtoken", + 'client_id' => "Some Client" + )); + + $db->oauth_authorization_codes->insertOne(array( + 'authorization_code' => "testcode", + 'client_id' => "Some Client" + )); + + $db->oauth_users->insertOne(array( + 'username' => 'testuser', + 'password' => 'password', + 'email' => 'testuser@test.com', + 'email_verified' => true, + )); + + $db->oauth_keys->insertOne(array( + 'client_id' => null, + 'public_key' => $this->getTestPublicKey(), + 'private_key' => $this->getTestPrivateKey(), + 'encryption_algorithm' => 'RS256' + )); + + $db->oauth_jwt->insertOne(array( + 'client_id' => 'oauth_test_client', + 'key' => $this->getTestPublicKey(), + 'subject' => 'test_subject', + )); + } + + public function removeMongoDB(\MongoDB\Database $db) + { + $db->drop(); + } + private function createRedisDb(Redis $storage) { $storage->setClientDetails("oauth_test_client", "testpass", "http://example.com", 'implicit password'); @@ -500,11 +584,6 @@ class Bootstrap $storage->setClientKey('oauth_test_client', $this->getTestPublicKey(), 'test_subject'); } - public function removeMongoDb(\MongoDB $db) - { - $db->drop(); - } - public function getTestPublicKey() { return file_get_contents(__DIR__.'/../../../config/keys/id_rsa.pub'); |
