summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorBrent Shaffer <bshafs@gmail.com>2012-10-10 20:35:42 +0400
committerBrent Shaffer <bshafs@gmail.com>2012-10-10 20:35:42 +0400
commitd64bc79dbfee776db37fa162f49f7a0a847423d9 (patch)
treea68145f8480c6a2a1e33ea63fcf9ce18c9236b9e /test
parent278efc365a46c7ec0f321f35680339fa3927797a (diff)
downloadoauth2-server-php-d64bc79dbfee776db37fa162f49f7a0a847423d9.tar.xz
adds support for authorization codes in PDO storage, adds tests for this
Diffstat (limited to 'test')
-rw-r--r--test/OAuth2/Storage/PdoTest.php50
1 files changed, 50 insertions, 0 deletions
diff --git a/test/OAuth2/Storage/PdoTest.php b/test/OAuth2/Storage/PdoTest.php
index fa16cfa..0f20168 100644
--- a/test/OAuth2/Storage/PdoTest.php
+++ b/test/OAuth2/Storage/PdoTest.php
@@ -48,6 +48,10 @@ class OAuth2_Storage_PdoTest extends PHPUnit_Framework_TestCase
/** @dataProvider provideStorage */
public function testSetAccessToken($storage)
{
+ // assert token we are about to add does not exist
+ $token = $storage->getAccessToken('newtoken');
+ $this->assertFalse($token);
+
// add new token
$success = $storage->setAccessToken('newtoken', 'client ID', 'SOMEUSERID', time() + 20);
$this->assertTrue($success);
@@ -71,6 +75,50 @@ class OAuth2_Storage_PdoTest extends PHPUnit_Framework_TestCase
$this->assertEquals($token['user_id'], 'SOMEOTHERID');
}
+ /** @dataProvider provideStorage */
+ public function testGetAuthorizationCode($storage)
+ {
+ // nonexistant client_id
+ $details = $storage->getAuthorizationCode('faketoken');
+ $this->assertFalse($details);
+
+ // valid client_id
+ $details = $storage->getAuthorizationCode('testtoken');
+ $this->assertNotNull($details);
+ }
+
+ /** @dataProvider provideStorage */
+ public function testSetAuthorizationCode($storage)
+ {
+ // assert code we are about to add does not exist
+ $code = $storage->getAuthorizationCode('newcode');
+ $this->assertFalse($code);
+
+ // add new code
+ $success = $storage->setAuthorizationCode('newcode', 'client ID', 'SOMEUSERID', 'http://adobe.com', time() + 20);
+ $this->assertTrue($success);
+
+ $code = $storage->getAuthorizationCode('newcode');
+ $this->assertNotNull($code);
+ $this->arrayHasKey('access_token', $code);
+ $this->arrayHasKey('client_id', $code);
+ $this->arrayHasKey('user_id', $code);
+ $this->assertEquals($code['user_id'], 'SOMEUSERID');
+ $this->arrayHasKey('redirect_uri', $code);
+
+ // change existing code
+ $success = $storage->setAuthorizationCode('newcode', 'client ID', 'SOMEOTHERID', 'http://adobe.com', time() + 20);
+ $this->assertTrue($success);
+
+ $code = $storage->getAuthorizationCode('newcode');
+ $this->assertNotNull($code);
+ $this->arrayHasKey('access_token', $code);
+ $this->arrayHasKey('client_id', $code);
+ $this->arrayHasKey('user_id', $code);
+ $this->assertEquals($code['user_id'], 'SOMEOTHERID');
+ $this->arrayHasKey('redirect_uri', $code);
+ }
+
public function provideStorage()
{
$this->removeSqliteDb(); // remove db to be safe
@@ -92,10 +140,12 @@ class OAuth2_Storage_PdoTest extends PHPUnit_Framework_TestCase
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$db->exec('CREATE TABLE oauth_clients (client_id TEXT, client_secret TEXT, redirect_uri TEXT)');
$db->exec('CREATE TABLE oauth_access_tokens (access_token TEXT, client_id TEXT, user_id TEXT, expires TIMESTAMP, scope TEXT)');
+ $db->exec('CREATE TABLE oauth_authorization_codes (authorization_code TEXT, client_id TEXT, user_id TEXT, redirect_uri TEXT, expires TIMESTAMP, scope TEXT)');
// test data
$db->exec('INSERT INTO oauth_clients (client_id, client_secret) VALUES ("oauth_test_client", "testpass")');
$db->exec('INSERT INTO oauth_access_tokens (access_token, client_id) VALUES ("testtoken", "Some Client")');
+ $db->exec('INSERT INTO oauth_authorization_codes (authorization_code, client_id) VALUES ("testcode", "Some Client")');
}
private function removeSqliteDb()