add composer's vendor directory

This commit is contained in:
Marcel Kapfer (mmk2410) 2016-05-07 12:59:40 +02:00
parent 01a3860d73
commit 60b094d5fa
745 changed files with 56017 additions and 1 deletions

View file

@ -0,0 +1,82 @@
<?php
namespace OAuth2\Storage;
class AccessTokenTest extends BaseTest
{
/** @dataProvider provideStorage */
public function testSetAccessToken(AccessTokenInterface $storage)
{
if ($storage instanceof NullStorage) {
$this->markTestSkipped('Skipped Storage: ' . $storage->getMessage());
return;
}
// assert token we are about to add does not exist
$token = $storage->getAccessToken('newtoken');
$this->assertFalse($token);
// add new token
$expires = time() + 20;
$success = $storage->setAccessToken('newtoken', 'client ID', 'SOMEUSERID', $expires);
$this->assertTrue($success);
$token = $storage->getAccessToken('newtoken');
$this->assertNotNull($token);
$this->assertArrayHasKey('access_token', $token);
$this->assertArrayHasKey('client_id', $token);
$this->assertArrayHasKey('user_id', $token);
$this->assertArrayHasKey('expires', $token);
$this->assertEquals($token['access_token'], 'newtoken');
$this->assertEquals($token['client_id'], 'client ID');
$this->assertEquals($token['user_id'], 'SOMEUSERID');
$this->assertEquals($token['expires'], $expires);
// change existing token
$expires = time() + 42;
$success = $storage->setAccessToken('newtoken', 'client ID2', 'SOMEOTHERID', $expires);
$this->assertTrue($success);
$token = $storage->getAccessToken('newtoken');
$this->assertNotNull($token);
$this->assertArrayHasKey('access_token', $token);
$this->assertArrayHasKey('client_id', $token);
$this->assertArrayHasKey('user_id', $token);
$this->assertArrayHasKey('expires', $token);
$this->assertEquals($token['access_token'], 'newtoken');
$this->assertEquals($token['client_id'], 'client ID2');
$this->assertEquals($token['user_id'], 'SOMEOTHERID');
$this->assertEquals($token['expires'], $expires);
// add token with scope having an empty string value
$expires = time() + 42;
$success = $storage->setAccessToken('newtoken', 'client ID', 'SOMEOTHERID', $expires, '');
$this->assertTrue($success);
}
/** @dataProvider provideStorage */
public function testUnsetAccessToken(AccessTokenInterface $storage)
{
if ($storage instanceof NullStorage || !method_exists($storage, 'unsetAccessToken')) {
$this->markTestSkipped('Skipped Storage: ' . $storage->getMessage());
return;
}
// assert token we are unset does not exist
$token = $storage->getAccessToken('revokabletoken');
$this->assertFalse($token);
// add new token
$expires = time() + 20;
$success = $storage->setAccessToken('revokabletoken', 'client ID', 'SOMEUSERID', $expires);
$this->assertTrue($success);
$storage->unsetAccessToken('revokabletoken');
// assert token we are unset does not exist
$token = $storage->getAccessToken('revokabletoken');
$this->assertFalse($token);
}
}

View file

@ -0,0 +1,106 @@
<?php
namespace OAuth2\Storage;
class AuthorizationCodeTest extends BaseTest
{
/** @dataProvider provideStorage */
public function testGetAuthorizationCode(AuthorizationCodeInterface $storage)
{
if ($storage instanceof NullStorage) {
$this->markTestSkipped('Skipped Storage: ' . $storage->getMessage());
return;
}
// 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(AuthorizationCodeInterface $storage)
{
if ($storage instanceof NullStorage) {
$this->markTestSkipped('Skipped Storage: ' . $storage->getMessage());
return;
}
// assert code we are about to add does not exist
$code = $storage->getAuthorizationCode('newcode');
$this->assertFalse($code);
// add new code
$expires = time() + 20;
$success = $storage->setAuthorizationCode('newcode', 'client ID', 'SOMEUSERID', 'http://example.com', $expires);
$this->assertTrue($success);
$code = $storage->getAuthorizationCode('newcode');
$this->assertNotNull($code);
$this->assertArrayHasKey('authorization_code', $code);
$this->assertArrayHasKey('client_id', $code);
$this->assertArrayHasKey('user_id', $code);
$this->assertArrayHasKey('redirect_uri', $code);
$this->assertArrayHasKey('expires', $code);
$this->assertEquals($code['authorization_code'], 'newcode');
$this->assertEquals($code['client_id'], 'client ID');
$this->assertEquals($code['user_id'], 'SOMEUSERID');
$this->assertEquals($code['redirect_uri'], 'http://example.com');
$this->assertEquals($code['expires'], $expires);
// change existing code
$expires = time() + 42;
$success = $storage->setAuthorizationCode('newcode', 'client ID2', 'SOMEOTHERID', 'http://example.org', $expires);
$this->assertTrue($success);
$code = $storage->getAuthorizationCode('newcode');
$this->assertNotNull($code);
$this->assertArrayHasKey('authorization_code', $code);
$this->assertArrayHasKey('client_id', $code);
$this->assertArrayHasKey('user_id', $code);
$this->assertArrayHasKey('redirect_uri', $code);
$this->assertArrayHasKey('expires', $code);
$this->assertEquals($code['authorization_code'], 'newcode');
$this->assertEquals($code['client_id'], 'client ID2');
$this->assertEquals($code['user_id'], 'SOMEOTHERID');
$this->assertEquals($code['redirect_uri'], 'http://example.org');
$this->assertEquals($code['expires'], $expires);
// add new code with scope having an empty string value
$expires = time() + 20;
$success = $storage->setAuthorizationCode('newcode', 'client ID', 'SOMEUSERID', 'http://example.com', $expires, '');
$this->assertTrue($success);
}
/** @dataProvider provideStorage */
public function testExpireAccessToken(AccessTokenInterface $storage)
{
if ($storage instanceof NullStorage) {
$this->markTestSkipped('Skipped Storage: ' . $storage->getMessage());
return;
}
// create a valid code
$expires = time() + 20;
$success = $storage->setAuthorizationCode('code-to-expire', 'client ID', 'SOMEUSERID', 'http://example.com', time() + 20);
$this->assertTrue($success);
// verify the new code exists
$code = $storage->getAuthorizationCode('code-to-expire');
$this->assertNotNull($code);
$this->assertArrayHasKey('authorization_code', $code);
$this->assertEquals($code['authorization_code'], 'code-to-expire');
// now expire the code and ensure it's no longer available
$storage->expireAuthorizationCode('code-to-expire');
$code = $storage->getAuthorizationCode('code-to-expire');
$this->assertFalse($code);
}
}

View file

@ -0,0 +1,28 @@
<?php
namespace OAuth2\Storage;
class ClientCredentialsTest extends BaseTest
{
/** @dataProvider provideStorage */
public function testCheckClientCredentials(ClientCredentialsInterface $storage)
{
if ($storage instanceof NullStorage) {
$this->markTestSkipped('Skipped Storage: ' . $storage->getMessage());
return;
}
// nonexistant client_id
$pass = $storage->checkClientCredentials('fakeclient', 'testpass');
$this->assertFalse($pass);
// invalid password
$pass = $storage->checkClientCredentials('oauth_test_client', 'invalidcredentials');
$this->assertFalse($pass);
// valid credentials
$pass = $storage->checkClientCredentials('oauth_test_client', 'testpass');
$this->assertTrue($pass);
}
}

View file

@ -0,0 +1,87 @@
<?php
namespace OAuth2\Storage;
class ClientTest extends BaseTest
{
/** @dataProvider provideStorage */
public function testGetClientDetails(ClientInterface $storage)
{
if ($storage instanceof NullStorage) {
$this->markTestSkipped('Skipped Storage: ' . $storage->getMessage());
return;
}
// nonexistant client_id
$details = $storage->getClientDetails('fakeclient');
$this->assertFalse($details);
// valid client_id
$details = $storage->getClientDetails('oauth_test_client');
$this->assertNotNull($details);
$this->assertArrayHasKey('client_id', $details);
$this->assertArrayHasKey('client_secret', $details);
$this->assertArrayHasKey('redirect_uri', $details);
}
/** @dataProvider provideStorage */
public function testCheckRestrictedGrantType(ClientInterface $storage)
{
if ($storage instanceof NullStorage) {
$this->markTestSkipped('Skipped Storage: ' . $storage->getMessage());
return;
}
// Check invalid
$pass = $storage->checkRestrictedGrantType('oauth_test_client', 'authorization_code');
$this->assertFalse($pass);
// Check valid
$pass = $storage->checkRestrictedGrantType('oauth_test_client', 'implicit');
$this->assertTrue($pass);
}
/** @dataProvider provideStorage */
public function testGetAccessToken(ClientInterface $storage)
{
if ($storage instanceof NullStorage) {
$this->markTestSkipped('Skipped Storage: ' . $storage->getMessage());
return;
}
// nonexistant client_id
$details = $storage->getAccessToken('faketoken');
$this->assertFalse($details);
// valid client_id
$details = $storage->getAccessToken('testtoken');
$this->assertNotNull($details);
}
/** @dataProvider provideStorage */
public function testSaveClient(ClientInterface $storage)
{
if ($storage instanceof NullStorage) {
$this->markTestSkipped('Skipped Storage: ' . $storage->getMessage());
return;
}
$clientId = 'some-client-'.rand();
// create a new client
$success = $storage->setClientDetails($clientId, 'somesecret', 'http://test.com', 'client_credentials', 'clientscope1', 'brent@brentertainment.com');
$this->assertTrue($success);
// valid client_id
$details = $storage->getClientDetails($clientId);
$this->assertEquals($details['client_secret'], 'somesecret');
$this->assertEquals($details['redirect_uri'], 'http://test.com');
$this->assertEquals($details['grant_types'], 'client_credentials');
$this->assertEquals($details['scope'], 'clientscope1');
$this->assertEquals($details['user_id'], 'brent@brentertainment.com');
}
}

View file

@ -0,0 +1,40 @@
<?php
namespace OAuth2\Storage;
class DynamoDBTest extends BaseTest
{
public function testGetDefaultScope()
{
$client = $this->getMockBuilder('\Aws\DynamoDb\DynamoDbClient')
->disableOriginalConstructor()
->setMethods(array('query'))
->getMock();
$return = $this->getMockBuilder('\Guzzle\Service\Resource\Model')
->setMethods(array('count', 'toArray'))
->getMock();
$data = array(
'Items' => array(),
'Count' => 0,
'ScannedCount'=> 0
);
$return->expects($this->once())
->method('count')
->will($this->returnValue(count($data)));
$return->expects($this->once())
->method('toArray')
->will($this->returnValue($data));
// should return null default scope if none is set in database
$client->expects($this->once())
->method('query')
->will($this->returnValue($return));
$storage = new DynamoDB($client);
$this->assertNull($storage->getDefaultScope());
}
}

View file

@ -0,0 +1,41 @@
<?php
namespace OAuth2\Storage;
use OAuth2\Encryption\Jwt;
class JwtAccessTokenTest extends BaseTest
{
/** @dataProvider provideStorage */
public function testSetAccessToken($storage)
{
if (!$storage instanceof PublicKey) {
// incompatible storage
return;
}
$crypto = new jwtAccessToken($storage);
$publicKeyStorage = Bootstrap::getInstance()->getMemoryStorage();
$encryptionUtil = new Jwt();
$jwtAccessToken = array(
'access_token' => rand(),
'expires' => time() + 100,
'scope' => 'foo',
);
$token = $encryptionUtil->encode($jwtAccessToken, $storage->getPrivateKey(), $storage->getEncryptionAlgorithm());
$this->assertNotNull($token);
$tokenData = $crypto->getAccessToken($token);
$this->assertTrue(is_array($tokenData));
/* assert the decoded token is the same */
$this->assertEquals($tokenData['access_token'], $jwtAccessToken['access_token']);
$this->assertEquals($tokenData['expires'], $jwtAccessToken['expires']);
$this->assertEquals($tokenData['scope'], $jwtAccessToken['scope']);
}
}

View file

@ -0,0 +1,25 @@
<?php
namespace OAuth2\Storage;
class JwtBearerTest extends BaseTest
{
/** @dataProvider provideStorage */
public function testGetClientKey(JwtBearerInterface $storage)
{
if ($storage instanceof NullStorage) {
$this->markTestSkipped('Skipped Storage: ' . $storage->getMessage());
return;
}
// nonexistant client_id
$key = $storage->getClientKey('this-is-not-real', 'nor-is-this');
$this->assertFalse($key);
// valid client_id and subject
$key = $storage->getClientKey('oauth_test_client', 'test_subject');
$this->assertNotNull($key);
$this->assertEquals($key, Bootstrap::getInstance()->getTestPublicKey());
}
}

View file

@ -0,0 +1,39 @@
<?php
namespace OAuth2\Storage;
class PdoTest extends BaseTest
{
public function testCreatePdoStorageUsingPdoClass()
{
$pdo = new \PDO(sprintf('sqlite://%s', Bootstrap::getInstance()->getSqliteDir()));
$storage = new Pdo($pdo);
$this->assertNotNull($storage->getClientDetails('oauth_test_client'));
}
public function testCreatePdoStorageUsingDSN()
{
$dsn = sprintf('sqlite://%s', Bootstrap::getInstance()->getSqliteDir());
$storage = new Pdo($dsn);
$this->assertNotNull($storage->getClientDetails('oauth_test_client'));
}
public function testCreatePdoStorageUsingConfig()
{
$config = array('dsn' => sprintf('sqlite://%s', Bootstrap::getInstance()->getSqliteDir()));
$storage = new Pdo($config);
$this->assertNotNull($storage->getClientDetails('oauth_test_client'));
}
/**
* @expectedException InvalidArgumentException dsn
*/
public function testCreatePdoStorageWithoutDSNThrowsException()
{
$config = array('username' => 'brent', 'password' => 'brentisaballer');
$storage = new Pdo($config);
}
}

View file

@ -0,0 +1,29 @@
<?php
namespace OAuth2\Storage;
class PublicKeyTest extends BaseTest
{
/** @dataProvider provideStorage */
public function testSetAccessToken($storage)
{
if ($storage instanceof NullStorage) {
$this->markTestSkipped('Skipped Storage: ' . $storage->getMessage());
return;
}
if (!$storage instanceof PublicKeyInterface) {
// incompatible storage
return;
}
$configDir = Bootstrap::getInstance()->getConfigDir();
$globalPublicKey = file_get_contents($configDir.'/keys/id_rsa.pub');
$globalPrivateKey = file_get_contents($configDir.'/keys/id_rsa');
/* assert values from storage */
$this->assertEquals($storage->getPublicKey(), $globalPublicKey);
$this->assertEquals($storage->getPrivateKey(), $globalPrivateKey);
}
}

View file

@ -0,0 +1,41 @@
<?php
namespace OAuth2\Storage;
class RefreshTokenTest extends BaseTest
{
/** @dataProvider provideStorage */
public function testSetRefreshToken(RefreshTokenInterface $storage)
{
if ($storage instanceof NullStorage) {
$this->markTestSkipped('Skipped Storage: ' . $storage->getMessage());
return;
}
// assert token we are about to add does not exist
$token = $storage->getRefreshToken('refreshtoken');
$this->assertFalse($token);
// add new token
$expires = time() + 20;
$success = $storage->setRefreshToken('refreshtoken', 'client ID', 'SOMEUSERID', $expires);
$this->assertTrue($success);
$token = $storage->getRefreshToken('refreshtoken');
$this->assertNotNull($token);
$this->assertArrayHasKey('refresh_token', $token);
$this->assertArrayHasKey('client_id', $token);
$this->assertArrayHasKey('user_id', $token);
$this->assertArrayHasKey('expires', $token);
$this->assertEquals($token['refresh_token'], 'refreshtoken');
$this->assertEquals($token['client_id'], 'client ID');
$this->assertEquals($token['user_id'], 'SOMEUSERID');
$this->assertEquals($token['expires'], $expires);
// add token with scope having an empty string value
$expires = time() + 20;
$success = $storage->setRefreshToken('refreshtoken2', 'client ID', 'SOMEUSERID', $expires, '');
$this->assertTrue($success);
}
}

View file

@ -0,0 +1,53 @@
<?php
namespace OAuth2\Storage;
use OAuth2\Scope;
class ScopeTest extends BaseTest
{
/** @dataProvider provideStorage */
public function testScopeExists($storage)
{
if ($storage instanceof NullStorage) {
$this->markTestSkipped('Skipped Storage: ' . $storage->getMessage());
return;
}
if (!$storage instanceof ScopeInterface) {
// incompatible storage
return;
}
//Test getting scopes
$scopeUtil = new Scope($storage);
$this->assertTrue($scopeUtil->scopeExists('supportedscope1'));
$this->assertTrue($scopeUtil->scopeExists('supportedscope1 supportedscope2 supportedscope3'));
$this->assertFalse($scopeUtil->scopeExists('fakescope'));
$this->assertFalse($scopeUtil->scopeExists('supportedscope1 supportedscope2 supportedscope3 fakescope'));
}
/** @dataProvider provideStorage */
public function testGetDefaultScope($storage)
{
if ($storage instanceof NullStorage) {
$this->markTestSkipped('Skipped Storage: ' . $storage->getMessage());
return;
}
if (!$storage instanceof ScopeInterface) {
// incompatible storage
return;
}
// test getting default scope
$scopeUtil = new Scope($storage);
$expected = explode(' ', $scopeUtil->getDefaultScope());
$actual = explode(' ', 'defaultscope1 defaultscope2');
sort($expected);
sort($actual);
$this->assertEquals($expected, $actual);
}
}

View file

@ -0,0 +1,40 @@
<?php
namespace OAuth2\Storage;
class UserCredentialsTest extends BaseTest
{
/** @dataProvider provideStorage */
public function testCheckUserCredentials(UserCredentialsInterface $storage)
{
if ($storage instanceof NullStorage) {
$this->markTestSkipped('Skipped Storage: ' . $storage->getMessage());
return;
}
// create a new user for testing
$success = $storage->setUser('testusername', 'testpass', 'Test', 'User');
$this->assertTrue($success);
// correct credentials
$this->assertTrue($storage->checkUserCredentials('testusername', 'testpass'));
// invalid password
$this->assertFalse($storage->checkUserCredentials('testusername', 'fakepass'));
// invalid username
$this->assertFalse($storage->checkUserCredentials('fakeusername', 'testpass'));
// invalid username
$this->assertFalse($storage->getUserDetails('fakeusername'));
// ensure all properties are set
$user = $storage->getUserDetails('testusername');
$this->assertTrue($user !== false);
$this->assertArrayHasKey('user_id', $user);
$this->assertArrayHasKey('first_name', $user);
$this->assertArrayHasKey('last_name', $user);
$this->assertEquals($user['user_id'], 'testusername');
$this->assertEquals($user['first_name'], 'Test');
$this->assertEquals($user['last_name'], 'User');
}
}