mirror of
https://github.com/elyby/oauth2-server.git
synced 2024-12-22 13:09:44 +05:30
Updated with new entity names
This commit is contained in:
parent
8fbbc7bd07
commit
97fd115530
@ -24,7 +24,7 @@ class RefreshTokenEntity extends AbstractTokenEntity
|
||||
{
|
||||
/**
|
||||
* Access token associated to refresh token
|
||||
* @var \League\OAuth2\Server\Entity\AccessToken
|
||||
* @var \League\OAuth2\Server\Entity\AccessTokenEntity
|
||||
*/
|
||||
protected $accessToken;
|
||||
|
||||
@ -61,11 +61,6 @@ class RefreshTokenEntity extends AbstractTokenEntity
|
||||
$this->getExpireTime(),
|
||||
$this->getAccessToken()->getToken()
|
||||
);
|
||||
|
||||
// Associate the scope with the token
|
||||
foreach ($this->getScopes() as $scope) {
|
||||
$this->server->getStorage('refresh_token')->associateScope($this->getToken(), $scope->getId());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -73,6 +68,6 @@ class RefreshTokenEntity extends AbstractTokenEntity
|
||||
*/
|
||||
public function expire()
|
||||
{
|
||||
$this->server->getStorage('refresh_token')->delete($this->getToken());
|
||||
$this->server->getStorage('refresh_token')->delete($this);
|
||||
}
|
||||
}
|
||||
|
@ -142,7 +142,7 @@ class SessionEntity
|
||||
public function getScopes()
|
||||
{
|
||||
if ($this->scopes === null) {
|
||||
$this->scopes = $this->formatScopes($this->server->getStorage('session')->getScopes($this->getId()));
|
||||
$this->scopes = $this->formatScopes($this->server->getStorage('session')->getScopes($this));
|
||||
}
|
||||
|
||||
return $this->scopes;
|
||||
@ -263,7 +263,7 @@ class SessionEntity
|
||||
|
||||
// Associate the scope with the session
|
||||
foreach ($this->getScopes() as $scope) {
|
||||
$this->server->getStorage('session')->associateScope($this->getId(), $scope->getId());
|
||||
$this->server->getStorage('session')->associateScope($this, $scope);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -12,7 +12,7 @@
|
||||
namespace League\OAuth2\Server\Grant;
|
||||
|
||||
use League\OAuth2\Server\AuthorizationServer;
|
||||
use League\OAuth2\Server\Entity\Scope;
|
||||
use League\OAuth2\Server\Entity\ScopeEntity;
|
||||
use League\OAuth2\Server\Exception;
|
||||
|
||||
/**
|
||||
@ -138,7 +138,7 @@ abstract class AbstractGrant implements GrantTypeInterface
|
||||
$this->getIdentifier()
|
||||
);
|
||||
|
||||
if (($scope instanceof Scope) === false) {
|
||||
if (($scope instanceof ScopeEntity) === false) {
|
||||
throw new Exception\InvalidScopeException($scopeItem);
|
||||
}
|
||||
|
||||
@ -150,14 +150,14 @@ abstract class AbstractGrant implements GrantTypeInterface
|
||||
|
||||
/**
|
||||
* Format the local scopes array
|
||||
* @param array $unformated Array of Array of \League\OAuth2\Server\Entity\Scope
|
||||
* @param array $unformated Array of Array of \League\OAuth2\Server\Entity\ScopeEntity
|
||||
* @return array
|
||||
*/
|
||||
protected function formatScopes($unformated = [])
|
||||
{
|
||||
$scopes = [];
|
||||
foreach ($unformated as $scope) {
|
||||
if ($scope instanceof Scope) {
|
||||
if ($scope instanceof ScopeEntity) {
|
||||
$scopes[$scope->getId()] = $scope;
|
||||
}
|
||||
}
|
||||
|
@ -14,12 +14,12 @@ namespace League\OAuth2\Server\Grant;
|
||||
use League\OAuth2\Server\AuthorizationServer;
|
||||
use League\OAuth2\Server\Request;
|
||||
use League\OAuth2\Server\Exception;
|
||||
use League\OAuth2\Server\Entity\Client;
|
||||
use League\OAuth2\Server\Entity\RefreshToken;
|
||||
use League\OAuth2\Server\Entity\Session;
|
||||
use League\OAuth2\Server\Entity\AccessToken;
|
||||
use League\OAuth2\Server\Entity\Scope;
|
||||
use League\OAuth2\Server\Entity\AuthCode as AC;
|
||||
use League\OAuth2\Server\Entity\ClientEntity;
|
||||
use League\OAuth2\Server\Entity\RefreshTokenEntity;
|
||||
use League\OAuth2\Server\Entity\SessionEntity;
|
||||
use League\OAuth2\Server\Entity\AccessTokenEntity;
|
||||
use League\OAuth2\Server\Entity\ScopeEntity;
|
||||
use League\OAuth2\Server\Entity\AuthCodeEntity;
|
||||
use League\OAuth2\Server\Util\SecureKey;
|
||||
use League\OAuth2\Server\Storage\SessionInterface;
|
||||
use League\OAuth2\Server\Storage\ClientInterface;
|
||||
@ -100,7 +100,7 @@ class AuthCode extends AbstractGrant
|
||||
}
|
||||
|
||||
// Ensure response type is one that is recognised
|
||||
if ( ! in_array($responseType, $this->server->getResponseTypes())) {
|
||||
if (!in_array($responseType, $this->server->getResponseTypes())) {
|
||||
throw new Exception\UnsupportedResponseTypeException($responseType);
|
||||
}
|
||||
|
||||
@ -112,7 +112,7 @@ class AuthCode extends AbstractGrant
|
||||
$this->getIdentifier()
|
||||
);
|
||||
|
||||
if (($client instanceof Client) === false) {
|
||||
if (($client instanceof ClientEntity) === false) {
|
||||
throw new Exception\InvalidClientException();
|
||||
}
|
||||
|
||||
@ -140,13 +140,13 @@ class AuthCode extends AbstractGrant
|
||||
public function newAuthoriseRequest($type, $typeId, $authParams = [])
|
||||
{
|
||||
// Create a new session
|
||||
$session = new Session($this->server);
|
||||
$session = new SessionEntity($this->server);
|
||||
$session->setOwner($type, $typeId);
|
||||
$session->associateClient($authParams['client']);
|
||||
$session->save();
|
||||
|
||||
// Create a new auth code
|
||||
$authCode = new AC($this->server);
|
||||
$authCode = new AuthCodeEntity($this->server);
|
||||
$authCode->setToken(SecureKey::generate());
|
||||
$authCode->setRedirectUri($authParams['redirect_uri']);
|
||||
|
||||
@ -191,7 +191,7 @@ class AuthCode extends AbstractGrant
|
||||
$this->getIdentifier()
|
||||
);
|
||||
|
||||
if (($client instanceof Client) === false) {
|
||||
if (($client instanceof ClientEntity) === false) {
|
||||
throw new Exception\InvalidClientException();
|
||||
}
|
||||
|
||||
@ -202,7 +202,7 @@ class AuthCode extends AbstractGrant
|
||||
}
|
||||
|
||||
$code = $this->server->getStorage('auth_code')->get($authCode);
|
||||
if (($code instanceof AC) === false) {
|
||||
if (($code instanceof AuthCodeEntity) === false) {
|
||||
throw new Exception\InvalidRequestException('code');
|
||||
}
|
||||
|
||||
@ -215,7 +215,7 @@ class AuthCode extends AbstractGrant
|
||||
$authCodeScopes = $code->getScopes();
|
||||
|
||||
// Generate the access token
|
||||
$accessToken = new AccessToken($this->server);
|
||||
$accessToken = new AccessTokenEntity($this->server);
|
||||
$accessToken->setToken(SecureKey::generate());
|
||||
$accessToken->setExpireTime($this->server->getAccessTokenTTL() + time());
|
||||
|
||||
@ -232,7 +232,7 @@ class AuthCode extends AbstractGrant
|
||||
|
||||
// Associate a refresh token if set
|
||||
if ($this->server->hasGrantType('refresh_token')) {
|
||||
$refreshToken = new RefreshToken($this->server);
|
||||
$refreshToken = new RefreshTokenEntity($this->server);
|
||||
$refreshToken->setToken(SecureKey::generate());
|
||||
$refreshToken->setExpireTime($this->server->getGrantType('refresh_token')->getRefreshTokenTTL() + time());
|
||||
$response['refresh_token'] = $refreshToken->getToken();
|
||||
|
@ -12,10 +12,10 @@
|
||||
namespace League\OAuth2\Server\Grant;
|
||||
|
||||
use League\OAuth2\Server\AuthorizationServer;
|
||||
use League\OAuth2\Server\Entity\AccessToken;
|
||||
use League\OAuth2\Server\Entity\Client;
|
||||
use League\OAuth2\Server\Entity\Session;
|
||||
use League\OAuth2\Server\Entity\Scope;
|
||||
use League\OAuth2\Server\Entity\AccessTokenEntity;
|
||||
use League\OAuth2\Server\Entity\ClientEntity;
|
||||
use League\OAuth2\Server\Entity\SessionEntity;
|
||||
use League\OAuth2\Server\Entity\ScopeEntity;
|
||||
use League\OAuth2\Server\Exception;
|
||||
use League\OAuth2\Server\Util\SecureKey;
|
||||
use League\OAuth2\Server\Storage\SessionInterface;
|
||||
@ -77,7 +77,7 @@ class ClientCredentials extends AbstractGrant
|
||||
$this->getIdentifier()
|
||||
);
|
||||
|
||||
if (($client instanceof Client) === false) {
|
||||
if (($client instanceof ClientEntity) === false) {
|
||||
throw new Exception\InvalidClientException();
|
||||
}
|
||||
|
||||
@ -86,12 +86,12 @@ class ClientCredentials extends AbstractGrant
|
||||
$scopes = $this->validateScopes($scopeParam);
|
||||
|
||||
// Create a new session
|
||||
$session = new Session($this->server);
|
||||
$session = new SessionEntity($this->server);
|
||||
$session->setOwner('client', $client->getId());
|
||||
$session->associateClient($client);
|
||||
|
||||
// Generate an access token
|
||||
$accessToken = new AccessToken($this->server);
|
||||
$accessToken = new AccessTokenEntity($this->server);
|
||||
$accessToken->setToken(SecureKey::generate());
|
||||
$accessToken->setExpireTime($this->server->getAccessTokenTTL() + time());
|
||||
|
||||
|
@ -12,11 +12,11 @@
|
||||
namespace League\OAuth2\Server\Grant;
|
||||
|
||||
use League\OAuth2\Server\AuthorizationServer;
|
||||
use League\OAuth2\Server\Entity\AccessToken;
|
||||
use League\OAuth2\Server\Entity\Client;
|
||||
use League\OAuth2\Server\Entity\RefreshToken as RT;
|
||||
use League\OAuth2\Server\Entity\Session;
|
||||
use League\OAuth2\Server\Entity\Scope;
|
||||
use League\OAuth2\Server\Entity\ClientEntity;
|
||||
use League\OAuth2\Server\Entity\AccessTokenEntity;
|
||||
use League\OAuth2\Server\Entity\RefreshTokenEntity;
|
||||
use League\OAuth2\Server\Entity\SessionEntity;
|
||||
use League\OAuth2\Server\Entity\ScopeEntity;
|
||||
use League\OAuth2\Server\Exception;
|
||||
use League\OAuth2\Server\Util\SecureKey;
|
||||
use League\OAuth2\Server\Storage\SessionInterface;
|
||||
@ -101,7 +101,7 @@ class Password extends AbstractGrant
|
||||
$this->getIdentifier()
|
||||
);
|
||||
|
||||
if (($client instanceof Client) === false) {
|
||||
if (($client instanceof ClientEntity) === false) {
|
||||
throw new Exception\InvalidClientException();
|
||||
}
|
||||
|
||||
@ -127,12 +127,12 @@ class Password extends AbstractGrant
|
||||
$scopes = $this->validateScopes($scopeParam);
|
||||
|
||||
// Create a new session
|
||||
$session = new Session($this->server);
|
||||
$session = new SessionEntity($this->server);
|
||||
$session->setOwner('user', $userId);
|
||||
$session->associateClient($client);
|
||||
|
||||
// Generate an access token
|
||||
$accessToken = new AccessToken($this->server);
|
||||
$accessToken = new AccessTokenEntity($this->server);
|
||||
$accessToken->setToken(SecureKey::generate());
|
||||
$accessToken->setExpireTime($this->server->getAccessTokenTTL() + time());
|
||||
|
||||
@ -151,7 +151,7 @@ class Password extends AbstractGrant
|
||||
|
||||
// Associate a refresh token if set
|
||||
if ($this->server->hasGrantType('refresh_token')) {
|
||||
$refreshToken = new RT($this->server);
|
||||
$refreshToken = new RefreshTokenEntity($this->server);
|
||||
$refreshToken->setToken(SecureKey::generate());
|
||||
$refreshToken->setExpireTime($this->server->getGrantType('refresh_token')->getRefreshTokenTTL() + time());
|
||||
$response['refresh_token'] = $refreshToken->getToken();
|
||||
|
@ -18,9 +18,10 @@ use League\OAuth2\Server\Util\SecureKey;
|
||||
use League\OAuth2\Server\Storage\SessionInterface;
|
||||
use League\OAuth2\Server\Storage\ClientInterface;
|
||||
use League\OAuth2\Server\Storage\ScopeInterface;
|
||||
use League\OAuth2\Server\Entity\RefreshToken as RT;
|
||||
use League\OAuth2\Server\Entity\AccessToken;
|
||||
use League\OAuth2\Server\Entity\Session;
|
||||
use League\OAuth2\Server\Entity\RefreshTokenEntity;
|
||||
use League\OAuth2\Server\Entity\AccessTokenEntity;
|
||||
use League\OAuth2\Server\Entity\SessionEntity;
|
||||
use League\OAuth2\Server\Entity\ClientEntity;
|
||||
|
||||
/**
|
||||
* Referesh token grant
|
||||
@ -80,7 +81,7 @@ class RefreshToken extends AbstractGrant
|
||||
$this->getIdentifier()
|
||||
);
|
||||
|
||||
if ($client === null) {
|
||||
if (($client instanceof ClientEntity) === false) {
|
||||
throw new Exception\InvalidClientException();
|
||||
}
|
||||
|
||||
@ -92,7 +93,7 @@ class RefreshToken extends AbstractGrant
|
||||
// Validate refresh token
|
||||
$oldRefreshToken = $this->server->getStorage('refresh_token')->get($oldRefreshTokenParam);
|
||||
|
||||
if (($oldRefreshToken instanceof RT) === false) {
|
||||
if (($oldRefreshToken instanceof RefreshTokenEntity) === false) {
|
||||
throw new Exception\InvalidRefreshException();
|
||||
}
|
||||
|
||||
@ -122,7 +123,7 @@ class RefreshToken extends AbstractGrant
|
||||
}
|
||||
|
||||
// Generate a new access token and assign it the correct sessions
|
||||
$newAccessToken = new AccessToken($this->server);
|
||||
$newAccessToken = new AccessTokenEntity($this->server);
|
||||
$newAccessToken->setToken(SecureKey::generate());
|
||||
$newAccessToken->setExpireTime($this->server->getAccessTokenTTL() + time());
|
||||
$newAccessToken->setSession($session);
|
||||
@ -146,7 +147,7 @@ class RefreshToken extends AbstractGrant
|
||||
$oldRefreshToken->expire($this->server->getStorage('refresh_token'));
|
||||
|
||||
// Generate a new refresh token
|
||||
$newRefreshToken = new RT($this->server);
|
||||
$newRefreshToken = new RefreshTokenEntity($this->server);
|
||||
$newRefreshToken->setToken(SecureKey::generate());
|
||||
$newRefreshToken->setExpireTime($this->getRefreshTokenTTL() + time());
|
||||
$newRefreshToken->setAccessToken($newAccessToken);
|
||||
|
@ -17,7 +17,7 @@ use League\OAuth2\Server\Storage\AccessTokenInterface;
|
||||
use League\OAuth2\Server\Storage\AuthCodeInterface;
|
||||
use League\OAuth2\Server\Storage\SessionInterface;
|
||||
use League\OAuth2\Server\Storage\ScopeInterface;
|
||||
use League\OAuth2\Server\Entity\AccessToken;
|
||||
use League\OAuth2\Server\Entity\AccessTokenEntity;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
/**
|
||||
@ -135,24 +135,6 @@ class ResourceServer extends AbstractServer
|
||||
return $this->accessToken->getSession()->getClient()->getId();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the access token is valid or not
|
||||
* @param $headersOnly Limit Access Token to Authorization header only
|
||||
* @return bool
|
||||
*/
|
||||
public function isValidRequest($headersOnly = true, $accessToken = null)
|
||||
{
|
||||
try {
|
||||
$accessTokenString = ($accessToken !== null) ? $accessToken : $this->determineAccessToken($headersOnly, $accessToken);
|
||||
} catch (\Exception $e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Set the access token
|
||||
$this->accessToken = $this->storages['access_token']->get($accessTokenString);
|
||||
return ($this->accessToken instanceof AccessToken);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the session scopes
|
||||
* @return array
|
||||
@ -183,6 +165,20 @@ class ResourceServer extends AbstractServer
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the access token is valid or not
|
||||
* @param $headersOnly Limit Access Token to Authorization header only
|
||||
* @return bool
|
||||
*/
|
||||
public function isValidRequest($headersOnly = true, $accessToken = null)
|
||||
{
|
||||
$accessTokenString = ($accessToken !== null) ? $accessToken : $this->determineAccessToken($headersOnly, $accessToken);
|
||||
|
||||
// Set the access token
|
||||
$this->accessToken = $this->storages['access_token']->get($accessTokenString);
|
||||
return ($this->accessToken instanceof AccessTokenEntity);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads in the access token from the headers
|
||||
* @param $headersOnly Limit Access Token to Authorization header only
|
||||
@ -195,7 +191,9 @@ class ResourceServer extends AbstractServer
|
||||
$accessToken = trim(preg_replace('/^(?:\s+)?Bearer\s/', '', $header));
|
||||
$accessToken = ($accessToken === 'Bearer') ? '' : $accessToken;
|
||||
} elseif ($headersOnly === false) {
|
||||
$accessToken = $this->getRequest()->request->get($this->tokenKey);
|
||||
$accessToken = ($this->getRequest()->server->get('REQUEST_METHOD') === 'GET') ?
|
||||
$this->getRequest()->query->get($this->tokenKey) :
|
||||
$this->getRequest()->request->get($this->tokenKey);
|
||||
}
|
||||
|
||||
if (empty($accessToken)) {
|
||||
|
@ -10,7 +10,7 @@ class ClientTest extends \PHPUnit_Framework_TestCase
|
||||
public function testSetGet()
|
||||
{
|
||||
$server = M::mock('League\OAuth2\Server\AbstractServer');
|
||||
$client = new Client($server);
|
||||
$client = new ClientEntity($server);
|
||||
$client->setId('foobar');
|
||||
$client->setSecret('barfoo');
|
||||
$client->setName('Test Client');
|
||||
|
@ -14,58 +14,69 @@ class RefreshTokenTests extends \PHPUnit_Framework_TestCase
|
||||
function testSetAccessToken()
|
||||
{
|
||||
$server = M::mock('League\OAuth2\Server\AbstractServer');
|
||||
$entity = new RefreshToken($server);
|
||||
$entity->setAccessToken((new AccessToken($server)));
|
||||
$entity = new RefreshTokenEntity($server);
|
||||
$entity->setAccessToken((new AccessTokenEntity($server)));
|
||||
|
||||
$reflector = new \ReflectionClass($entity);
|
||||
$accessTokenProperty = $reflector->getProperty('accessToken');
|
||||
$accessTokenProperty->setAccessible(true);
|
||||
|
||||
$this->assertTrue($accessTokenProperty->getValue($entity) instanceof AccessToken);
|
||||
$this->assertTrue($accessTokenProperty->getValue($entity) instanceof AccessTokenEntity);
|
||||
}
|
||||
|
||||
function testSave()
|
||||
{
|
||||
$server = new Authorization();
|
||||
$server = M::mock('League\OAuth2\Server\AbstractServer');
|
||||
$server->shouldReceive('setAccessTokenStorage');
|
||||
$server->shouldReceive('setRefreshTokenStorage');
|
||||
|
||||
$refreshTokenStorage = M::mock('League\OAuth2\Server\Storage\RefreshTokenInterface');
|
||||
$refreshTokenStorage->shouldReceive('create');
|
||||
$refreshTokenStorage->shouldReceive('setServer');
|
||||
$refreshTokenStorage->shouldReceive('associateScope');
|
||||
|
||||
$server->shouldReceive('getStorage')->with('refresh_token')->andReturn($refreshTokenStorage);
|
||||
|
||||
$accessTokenStorage = M::mock('League\OAuth2\Server\Storage\AccessTokenInterface');
|
||||
$accessTokenStorage->shouldReceive('setServer');
|
||||
$accessTokenStorage->shouldReceive('getByRefreshToken')->andReturn(
|
||||
(new AccessToken($server))->setToken('foobar')
|
||||
(new AccessTokenEntity($server))->setToken('foobar')
|
||||
);
|
||||
$accessTokenStorage->shouldReceive('getScopes')->andReturn([
|
||||
(new Scope($server))->setId('foo')
|
||||
(new ScopeEntity($server))->setId('foo')
|
||||
]);
|
||||
|
||||
$server->shouldReceive('getStorage')->with('access_token')->andReturn($accessTokenStorage);
|
||||
|
||||
$sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface');
|
||||
$sessionStorage->shouldReceive('getByAccessToken')->andReturn(
|
||||
(new Session($server))
|
||||
(new SessionEntity($server))
|
||||
);
|
||||
$sessionStorage->shouldReceive('setServer');
|
||||
|
||||
$server->shouldReceive('getStorage')->with('session')->andReturn($sessionStorage);
|
||||
|
||||
$server->setAccessTokenStorage($accessTokenStorage);
|
||||
$server->setRefreshTokenStorage($refreshTokenStorage);
|
||||
|
||||
$entity = new RefreshToken($server);
|
||||
$entity = new RefreshTokenEntity($server);
|
||||
$this->assertSame(null, $entity->save());
|
||||
}
|
||||
|
||||
function testExpire()
|
||||
{
|
||||
$server = new Authorization();
|
||||
$server = M::mock('League\OAuth2\Server\AbstractServer');
|
||||
$server->shouldReceive('setRefreshTokenStorage');
|
||||
|
||||
$refreshTokenStorage = M::mock('League\OAuth2\Server\Storage\RefreshTokenInterface');
|
||||
$refreshTokenStorage->shouldReceive('delete');
|
||||
$refreshTokenStorage->shouldReceive('setServer');
|
||||
|
||||
$server->shouldReceive('getStorage')->with('refresh_token')->andReturn($refreshTokenStorage);
|
||||
|
||||
$server->setRefreshTokenStorage($refreshTokenStorage);
|
||||
|
||||
$entity = new RefreshToken($server);
|
||||
$entity = new RefreshTokenEntity($server);
|
||||
$this->assertSame($entity->expire(), null);
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ class ScopeTests extends \PHPUnit_Framework_TestCase
|
||||
public function testSetGet()
|
||||
{
|
||||
$server = M::mock('League\OAuth2\Server\AbstractServer');
|
||||
$scope = new Scope($server);
|
||||
$scope = new ScopeEntity($server);
|
||||
$scope->setId('foobar');
|
||||
$scope->setDescription('barfoo');
|
||||
|
||||
|
@ -8,7 +8,7 @@ use League\OAuth2\Server\Entity\ClientEntity;
|
||||
use League\OAuth2\Server\Entity\RefreshTokenEntity;
|
||||
use League\OAuth2\Server\Entity\SessionEntity;
|
||||
use League\OAuth2\Server\Entity\ScopeEntity;
|
||||
use League\OAuth2\Server\AuthorizationServer as Authorization;
|
||||
use League\OAuth2\Server\AuthorizationServer;
|
||||
use \Mockery as M;
|
||||
|
||||
class SessionTests extends \PHPUnit_Framework_TestCase
|
||||
@ -16,19 +16,19 @@ class SessionTests extends \PHPUnit_Framework_TestCase
|
||||
public function testSetGet()
|
||||
{
|
||||
$server = M::mock('League\OAuth2\Server\AbstractServer');
|
||||
$entity = new Session($server);
|
||||
$entity = new SessionEntity($server);
|
||||
$entity->setId('foobar');
|
||||
$entity->setOwner('user', 123);
|
||||
$entity->associateAccessToken((new AccessToken($server)));
|
||||
$entity->associateRefreshToken((new RefreshToken($server)));
|
||||
$entity->associateClient((new Client($server)));
|
||||
$entity->associateScope((new Scope($server))->setId('foo'));
|
||||
$entity->associateAccessToken((new AccessTokenEntity($server)));
|
||||
$entity->associateRefreshToken((new RefreshTokenEntity($server)));
|
||||
$entity->associateClient((new ClientEntity($server)));
|
||||
$entity->associateScope((new ScopeEntity($server))->setId('foo'));
|
||||
// $entity->associateAuthCode((new AuthCode($server)));
|
||||
|
||||
$this->assertEquals('foobar', $entity->getId());
|
||||
$this->assertEquals('user', $entity->getOwnerType());
|
||||
$this->assertEquals(123, $entity->getOwnerId());
|
||||
$this->assertTrue($entity->getClient() instanceof Client);
|
||||
$this->assertTrue($entity->getClient() instanceof ClientEntity);
|
||||
$this->assertTrue($entity->hasScope('foo'));
|
||||
|
||||
$reflector = new \ReflectionClass($entity);
|
||||
@ -37,8 +37,8 @@ class SessionTests extends \PHPUnit_Framework_TestCase
|
||||
$refreshTokenProperty = $reflector->getProperty('refreshToken');
|
||||
$refreshTokenProperty->setAccessible(true);
|
||||
|
||||
$this->assertTrue($accessTokenProperty->getValue($entity) instanceof AccessToken);
|
||||
$this->assertTrue($refreshTokenProperty->getValue($entity) instanceof RefreshToken);
|
||||
$this->assertTrue($accessTokenProperty->getValue($entity) instanceof AccessTokenEntity);
|
||||
$this->assertTrue($refreshTokenProperty->getValue($entity) instanceof RefreshTokenEntity);
|
||||
// $this->assertTrue($reader($entity, 'authCode') instanceof AuthCode);
|
||||
}
|
||||
|
||||
@ -46,32 +46,36 @@ class SessionTests extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
$server = M::mock('League\OAuth2\Server\AbstractServer');
|
||||
|
||||
$entity = new Session($server);
|
||||
$reflectedEntity = new \ReflectionClass('League\OAuth2\Server\Entity\Session');
|
||||
$entity = new SessionEntity($server);
|
||||
$reflectedEntity = new \ReflectionClass('League\OAuth2\Server\Entity\SessionEntity');
|
||||
$method = $reflectedEntity->getMethod('formatScopes');
|
||||
$method->setAccessible(true);
|
||||
|
||||
$scopes = [
|
||||
(new Scope($server))->setId('scope1')->setDescription('foo'),
|
||||
(new Scope($server))->setId('scope2')->setDescription('bar')
|
||||
(new ScopeEntity($server))->setId('scope1')->setDescription('foo'),
|
||||
(new ScopeEntity($server))->setId('scope2')->setDescription('bar')
|
||||
];
|
||||
|
||||
$result = $method->invokeArgs($entity, [$scopes]);
|
||||
|
||||
$this->assertTrue(isset($result['scope1']));
|
||||
$this->assertTrue(isset($result['scope2']));
|
||||
$this->assertTrue($result['scope1'] instanceof Scope);
|
||||
$this->assertTrue($result['scope2'] instanceof Scope);
|
||||
$this->assertTrue($result['scope1'] instanceof ScopeEntity);
|
||||
$this->assertTrue($result['scope2'] instanceof ScopeEntity);
|
||||
}
|
||||
|
||||
public function testGetScopes()
|
||||
{
|
||||
$server = new Authorization();
|
||||
$server = M::mock('League\OAuth2\Server\AuthorizationServer');
|
||||
$server->shouldReceive('setAccessTokenStorage');
|
||||
$server->shouldReceive('setSessionStorage');
|
||||
|
||||
$accessTokenStorage = M::mock('League\OAuth2\Server\Storage\AccessTokenInterface');
|
||||
$accessTokenStorage->shouldReceive('setServer');
|
||||
$server->setAccessTokenStorage($accessTokenStorage);
|
||||
|
||||
$server->shouldReceive('getStorage')->with('access_token')->andReturn($accessTokenStorage);
|
||||
|
||||
$sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface');
|
||||
$sessionStorage->shouldReceive('getScopes')->andReturn(
|
||||
[]
|
||||
@ -79,18 +83,24 @@ class SessionTests extends \PHPUnit_Framework_TestCase
|
||||
$sessionStorage->shouldReceive('setServer');
|
||||
$server->setSessionStorage($sessionStorage);
|
||||
|
||||
$entity = new Session($server);
|
||||
$server->shouldReceive('getStorage')->with('session')->andReturn($sessionStorage);
|
||||
|
||||
$entity = new SessionEntity($server);
|
||||
$this->assertEquals($entity->getScopes(), []);
|
||||
}
|
||||
|
||||
public function testHasScopes()
|
||||
{
|
||||
$server = new Authorization();
|
||||
$server = M::mock('League\OAuth2\Server\AuthorizationServer');
|
||||
$server->shouldReceive('setAccessTokenStorage');
|
||||
$server->shouldReceive('setSessionStorage');
|
||||
|
||||
$accessTokenStorage = M::mock('League\OAuth2\Server\Storage\AccessTokenInterface');
|
||||
$accessTokenStorage->shouldReceive('setServer');
|
||||
$server->setAccessTokenStorage($accessTokenStorage);
|
||||
|
||||
$server->shouldReceive('getStorage')->with('access_token')->andReturn($accessTokenStorage);
|
||||
|
||||
$sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface');
|
||||
$sessionStorage->shouldReceive('getScopes')->andReturn(
|
||||
[]
|
||||
@ -98,32 +108,40 @@ class SessionTests extends \PHPUnit_Framework_TestCase
|
||||
$sessionStorage->shouldReceive('setServer');
|
||||
$server->setSessionStorage($sessionStorage);
|
||||
|
||||
$entity = new Session($server);
|
||||
$server->shouldReceive('getStorage')->with('session')->andReturn($sessionStorage);
|
||||
|
||||
$entity = new SessionEntity($server);
|
||||
$this->assertFalse($entity->hasScope('foo'));
|
||||
}
|
||||
|
||||
function testSave()
|
||||
{
|
||||
$server = new Authorization();
|
||||
$server = M::mock('League\OAuth2\Server\AuthorizationServer');
|
||||
$server->shouldReceive('setSessionStorage');
|
||||
$server->shouldReceive('setClientStorage');
|
||||
|
||||
$sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface');
|
||||
$sessionStorage->shouldReceive('create');
|
||||
$sessionStorage->shouldReceive('associateScope');
|
||||
$sessionStorage->shouldReceive('setServer');
|
||||
$sessionStorage->shouldReceive('getScopes')->andReturn([
|
||||
(new Scope($server))->setId('foo')
|
||||
(new ScopeEntity($server))->setId('foo')
|
||||
]);
|
||||
|
||||
$server->shouldReceive('getStorage')->with('session')->andReturn($sessionStorage);
|
||||
|
||||
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
||||
$clientStorage->shouldReceive('getBySession')->andReturn(
|
||||
(new Client($server))->setId('foo')
|
||||
(new ClientEntity($server))->setId('foo')
|
||||
);
|
||||
$clientStorage->shouldReceive('setServer');
|
||||
|
||||
$server->shouldReceive('getStorage')->with('client')->andReturn($clientStorage);
|
||||
|
||||
$server->setSessionStorage($sessionStorage);
|
||||
$server->setClientStorage($clientStorage);
|
||||
|
||||
$entity = new Session($server);
|
||||
$entity = new SessionEntity($server);
|
||||
$this->assertEquals(null, $entity->save());
|
||||
}
|
||||
}
|
@ -36,16 +36,16 @@ class AbstractGrantTest extends \PHPUnit_Framework_TestCase
|
||||
$method->setAccessible(true);
|
||||
|
||||
$scopes = [
|
||||
(new Scope($server))->setId('scope1')->setDescription('foo'),
|
||||
(new Scope($server))->setId('scope2')->setDescription('bar')
|
||||
(new ScopeEntity($server))->setId('scope1')->setDescription('foo'),
|
||||
(new ScopeEntity($server))->setId('scope2')->setDescription('bar')
|
||||
];
|
||||
|
||||
$result = $method->invokeArgs($grant, [$scopes]);
|
||||
|
||||
$this->assertTrue(isset($result['scope1']));
|
||||
$this->assertTrue(isset($result['scope2']));
|
||||
$this->assertTrue($result['scope1'] instanceof Scope);
|
||||
$this->assertTrue($result['scope2'] instanceof Scope);
|
||||
$this->assertTrue($result['scope1'] instanceof ScopeEntity);
|
||||
$this->assertTrue($result['scope2'] instanceof ScopeEntity);
|
||||
}
|
||||
|
||||
public function testValidateScopes()
|
||||
@ -55,7 +55,7 @@ class AbstractGrantTest extends \PHPUnit_Framework_TestCase
|
||||
$scopeStorage = M::mock('League\OAuth2\Server\Storage\ScopeInterface');
|
||||
$scopeStorage->shouldReceive('setServer');
|
||||
$scopeStorage->shouldReceive('get')->andReturn(
|
||||
(new Scope($server))->setId('foo')
|
||||
(new ScopeEntity($server))->setId('foo')
|
||||
);
|
||||
|
||||
$server->setScopeStorage($scopeStorage);
|
||||
@ -65,7 +65,7 @@ class AbstractGrantTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
$this->assertEquals(
|
||||
[
|
||||
'foo' => (new Scope($server))->setId('foo')
|
||||
'foo' => (new ScopeEntity($server))->setId('foo')
|
||||
],
|
||||
|
||||
$grant->validateScopes('foo')
|
||||
@ -113,7 +113,7 @@ class AbstractGrantTest extends \PHPUnit_Framework_TestCase
|
||||
$scopeStorage = M::mock('League\OAuth2\Server\Storage\ScopeInterface');
|
||||
$scopeStorage->shouldReceive('setServer');
|
||||
$scopeStorage->shouldReceive('get')->andReturn(
|
||||
(new Scope($server))->setId('foo')
|
||||
(new ScopeEntity($server))->setId('foo')
|
||||
);
|
||||
$server->setScopeStorage($scopeStorage);
|
||||
|
||||
@ -134,7 +134,7 @@ class AbstractGrantTest extends \PHPUnit_Framework_TestCase
|
||||
$scopeStorage = M::mock('League\OAuth2\Server\Storage\ScopeInterface');
|
||||
$scopeStorage->shouldReceive('setServer');
|
||||
$scopeStorage->shouldReceive('get')->andReturn(
|
||||
(new Scope($server))->setId('foo')
|
||||
(new ScopeEntity($server))->setId('foo')
|
||||
);
|
||||
$server->setScopeStorage($scopeStorage);
|
||||
|
||||
|
@ -7,8 +7,8 @@ use League\OAuth2\Server\Grant\RefreshToken;
|
||||
use League\OAuth2\Server\Entity\ScopeEntity;
|
||||
use League\OAuth2\Server\Entity\ClientEntity;
|
||||
use League\OAuth2\Server\Entity\SessionEntity;
|
||||
use League\OAuth2\Server\Entity\AuthCode as AC;
|
||||
use League\OAuth2\Server\AuthorizationServer as Authorization;
|
||||
use League\OAuth2\Server\Entity\AuthCodeEntity;
|
||||
use League\OAuth2\Server\AuthorizationServer;
|
||||
use League\OAuth2\Server\Exception\InvalidRequestException;
|
||||
use Mockery as M;
|
||||
|
||||
@ -30,8 +30,8 @@ class AuthCodeTest extends \PHPUnit_Framework_TestCase
|
||||
$this->setExpectedException('League\OAuth2\Server\Exception\InvalidRequestException');
|
||||
|
||||
$_POST = [];
|
||||
$server = new AuthorizationServer;
|
||||
|
||||
$server = new Authorization;
|
||||
$grant = new AuthCode;
|
||||
|
||||
$server->addGrantType($grant);
|
||||
@ -43,11 +43,11 @@ class AuthCodeTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
$this->setExpectedException('League\OAuth2\Server\Exception\InvalidRequestException');
|
||||
|
||||
$server = new AuthorizationServer;
|
||||
$_POST = [
|
||||
'client_id' => 'testapp'
|
||||
];
|
||||
|
||||
$server = new Authorization;
|
||||
$grant = new AuthCode;
|
||||
|
||||
$server->addGrantType($grant);
|
||||
@ -62,10 +62,10 @@ class AuthCodeTest extends \PHPUnit_Framework_TestCase
|
||||
'client_id' => 'testapp',
|
||||
'redirect_uri' => 'http://foo/bar'
|
||||
];
|
||||
$server = new AuthorizationServer;
|
||||
|
||||
$server = new Authorization;
|
||||
$server->requireStateParam(true);
|
||||
$grant = new AuthCode;
|
||||
$server->requireStateParam(true);
|
||||
|
||||
$server->addGrantType($grant);
|
||||
$grant->checkAuthoriseParams();
|
||||
@ -79,8 +79,8 @@ class AuthCodeTest extends \PHPUnit_Framework_TestCase
|
||||
'client_id' => 'testapp',
|
||||
'redirect_uri' => 'http://foo/bar'
|
||||
];
|
||||
$server = new AuthorizationServer;
|
||||
|
||||
$server = new Authorization;
|
||||
$grant = new AuthCode;
|
||||
|
||||
$server->addGrantType($grant);
|
||||
@ -96,8 +96,8 @@ class AuthCodeTest extends \PHPUnit_Framework_TestCase
|
||||
'redirect_uri' => 'http://foo/bar',
|
||||
'response_type' => 'foobar'
|
||||
];
|
||||
$server = new AuthorizationServer;
|
||||
|
||||
$server = new Authorization;
|
||||
$grant = new AuthCode;
|
||||
|
||||
$server->addGrantType($grant);
|
||||
@ -113,14 +113,15 @@ class AuthCodeTest extends \PHPUnit_Framework_TestCase
|
||||
'redirect_uri' => 'http://foo/bar',
|
||||
'response_type' => 'code'
|
||||
];
|
||||
$server = new AuthorizationServer;
|
||||
|
||||
$server = new Authorization;
|
||||
$grant = new AuthCode;
|
||||
|
||||
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
||||
$clientStorage->shouldReceive('setServer');
|
||||
$clientStorage->shouldReceive('get')->andReturn(null);
|
||||
|
||||
|
||||
$server->setClientStorage($clientStorage);
|
||||
|
||||
$server->addGrantType($grant);
|
||||
@ -138,13 +139,13 @@ class AuthCodeTest extends \PHPUnit_Framework_TestCase
|
||||
'scope' => 'foo'
|
||||
];
|
||||
|
||||
$server = new Authorization;
|
||||
$server = new AuthorizationServer;
|
||||
$grant = new AuthCode;
|
||||
|
||||
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
||||
$clientStorage->shouldReceive('setServer');
|
||||
$clientStorage->shouldReceive('get')->andReturn(
|
||||
(new Client($server))->setId('testapp')
|
||||
(new ClientEntity($server))->setId('testapp')
|
||||
);
|
||||
|
||||
$sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface');
|
||||
@ -179,20 +180,20 @@ class AuthCodeTest extends \PHPUnit_Framework_TestCase
|
||||
'scope' => 'foo'
|
||||
];
|
||||
|
||||
$server = new Authorization;
|
||||
$server = new AuthorizationServer;
|
||||
$grant = new AuthCode;
|
||||
|
||||
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
||||
$clientStorage->shouldReceive('setServer');
|
||||
$clientStorage->shouldReceive('get')->andReturn(
|
||||
(new Client($server))->setId('testapp')
|
||||
(new ClientEntity($server))->setId('testapp')
|
||||
);
|
||||
|
||||
$sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface');
|
||||
$sessionStorage->shouldReceive('setServer');
|
||||
$sessionStorage->shouldReceive('create')->andreturn(123);
|
||||
$sessionStorage->shouldReceive('getScopes')->shouldReceive('getScopes')->andReturn([
|
||||
(new Scope($server))->setId('foo')
|
||||
(new ScopeEntity($server))->setId('foo')
|
||||
]);
|
||||
$sessionStorage->shouldReceive('associateScope');
|
||||
|
||||
@ -200,14 +201,14 @@ class AuthCodeTest extends \PHPUnit_Framework_TestCase
|
||||
$accessTokenStorage->shouldReceive('setServer');
|
||||
$accessTokenStorage->shouldReceive('create');
|
||||
$accessTokenStorage->shouldReceive('getScopes')->andReturn([
|
||||
(new Scope($server))->setId('foo')
|
||||
(new ScopeEntity($server))->setId('foo')
|
||||
]);
|
||||
$accessTokenStorage->shouldReceive('associateScope');
|
||||
|
||||
$scopeStorage = M::mock('League\OAuth2\Server\Storage\ScopeInterface');
|
||||
$scopeStorage->shouldReceive('setServer');
|
||||
$scopeStorage->shouldReceive('get')->andReturn(
|
||||
(new Scope($server))->setId('foo')
|
||||
(new ScopeEntity($server))->setId('foo')
|
||||
);
|
||||
|
||||
$server->setClientStorage($clientStorage);
|
||||
@ -219,19 +220,19 @@ class AuthCodeTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
$result = $grant->checkAuthoriseParams();
|
||||
|
||||
$this->assertTrue($result['client'] instanceof Client);
|
||||
$this->assertTrue($result['client'] instanceof ClientEntity);
|
||||
$this->assertTrue($result['redirect_uri'] === $_POST['redirect_uri']);
|
||||
$this->assertTrue($result['state'] === null);
|
||||
$this->assertTrue($result['response_type'] === 'code');
|
||||
$this->assertTrue($result['scopes']['foo'] instanceof Scope);
|
||||
$this->assertTrue($result['scopes']['foo'] instanceof ScopeEntity);
|
||||
}
|
||||
|
||||
public function testNewAuthoriseRequest()
|
||||
{
|
||||
$server = new Authorization;
|
||||
$server = new AuthorizationServer;
|
||||
|
||||
$client = (new Client($server))->setId('testapp');
|
||||
$scope = (new Scope($server))->setId('foo');
|
||||
$client = (new ClientEntity($server))->setId('testapp');
|
||||
$scope = (new ScopeEntity($server))->setId('foo');
|
||||
|
||||
$grant = new AuthCode;
|
||||
$server->addGrantType($grant);
|
||||
@ -264,7 +265,7 @@ class AuthCodeTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
$_POST['grant_type'] = 'authorization_code';
|
||||
|
||||
$server = new Authorization;
|
||||
$server = new AuthorizationServer;
|
||||
$grant = new AuthCode;
|
||||
|
||||
$server->addGrantType($grant);
|
||||
@ -281,7 +282,7 @@ class AuthCodeTest extends \PHPUnit_Framework_TestCase
|
||||
'client_id' => 'testapp'
|
||||
];
|
||||
|
||||
$server = new Authorization;
|
||||
$server = new AuthorizationServer;
|
||||
$grant = new AuthCode;
|
||||
|
||||
$server->addGrantType($grant);
|
||||
@ -298,7 +299,7 @@ class AuthCodeTest extends \PHPUnit_Framework_TestCase
|
||||
'client_secret' => 'foobar'
|
||||
];
|
||||
|
||||
$server = new Authorization;
|
||||
$server = new AuthorizationServer;
|
||||
$grant = new AuthCode;
|
||||
|
||||
$server->addGrantType($grant);
|
||||
@ -316,7 +317,7 @@ class AuthCodeTest extends \PHPUnit_Framework_TestCase
|
||||
'redirect_uri' => 'http://foo/bar'
|
||||
];
|
||||
|
||||
$server = new Authorization;
|
||||
$server = new AuthorizationServer;
|
||||
$grant = new AuthCode;
|
||||
|
||||
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
||||
@ -340,13 +341,13 @@ class AuthCodeTest extends \PHPUnit_Framework_TestCase
|
||||
'redirect_uri' => 'http://foo/bar'
|
||||
];
|
||||
|
||||
$server = new Authorization;
|
||||
$server = new AuthorizationServer;
|
||||
$grant = new AuthCode;
|
||||
|
||||
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
||||
$clientStorage->shouldReceive('setServer');
|
||||
$clientStorage->shouldReceive('get')->andReturn(
|
||||
(new Client($server))->setId('testapp')
|
||||
(new ClientEntity($server))->setId('testapp')
|
||||
);
|
||||
|
||||
$sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface');
|
||||
@ -389,13 +390,13 @@ class AuthCodeTest extends \PHPUnit_Framework_TestCase
|
||||
'code' => 'foobar'
|
||||
];
|
||||
|
||||
$server = new Authorization;
|
||||
$server = new AuthorizationServer;
|
||||
$grant = new AuthCode;
|
||||
|
||||
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
||||
$clientStorage->shouldReceive('setServer');
|
||||
$clientStorage->shouldReceive('get')->andReturn(
|
||||
(new Client($server))->setId('testapp')
|
||||
(new ClientEntity($server))->setId('testapp')
|
||||
);
|
||||
|
||||
$sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface');
|
||||
@ -438,13 +439,13 @@ class AuthCodeTest extends \PHPUnit_Framework_TestCase
|
||||
'code' => 'foobar'
|
||||
];
|
||||
|
||||
$server = new Authorization;
|
||||
$server = new AuthorizationServer;
|
||||
$grant = new AuthCode;
|
||||
|
||||
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
||||
$clientStorage->shouldReceive('setServer');
|
||||
$clientStorage->shouldReceive('get')->andReturn(
|
||||
(new Client($server))->setId('testapp')
|
||||
(new ClientEntity($server))->setId('testapp')
|
||||
);
|
||||
|
||||
$sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface');
|
||||
@ -464,7 +465,7 @@ class AuthCodeTest extends \PHPUnit_Framework_TestCase
|
||||
$authCodeStorage = M::mock('League\OAuth2\Server\Storage\AuthCodeInterface');
|
||||
$authCodeStorage->shouldReceive('setServer');
|
||||
$authCodeStorage->shouldReceive('get')->andReturn(
|
||||
(new AC($server))->setToken('foobar')->setRedirectUri('http://fail/face')
|
||||
(new AuthCodeEntity($server))->setToken('foobar')->setRedirectUri('http://fail/face')
|
||||
);
|
||||
|
||||
$server->setClientStorage($clientStorage);
|
||||
@ -487,16 +488,16 @@ class AuthCodeTest extends \PHPUnit_Framework_TestCase
|
||||
'code' => 'foo'
|
||||
];
|
||||
|
||||
$server = new Authorization;
|
||||
$server = new AuthorizationServer;
|
||||
$grant = new AuthCode;
|
||||
|
||||
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
||||
$clientStorage->shouldReceive('setServer');
|
||||
$clientStorage->shouldReceive('getBySession')->andReturn(
|
||||
(new Client($server))->setId('testapp')
|
||||
(new ClientEntity($server))->setId('testapp')
|
||||
);
|
||||
$clientStorage->shouldReceive('get')->andReturn(
|
||||
(new Client($server))->setId('testapp')
|
||||
(new ClientEntity($server))->setId('testapp')
|
||||
);
|
||||
|
||||
$sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface');
|
||||
@ -504,7 +505,7 @@ class AuthCodeTest extends \PHPUnit_Framework_TestCase
|
||||
$sessionStorage->shouldReceive('create')->andreturn(123);
|
||||
$sessionStorage->shouldReceive('associateScope');
|
||||
$sessionStorage->shouldReceive('getByAuthCode')->andReturn(
|
||||
(new Session($server))->setId('foobar')
|
||||
(new SessionEntity($server))->setId('foobar')
|
||||
);
|
||||
|
||||
$accessTokenStorage = M::mock('League\OAuth2\Server\Storage\AccessTokenInterface');
|
||||
@ -512,23 +513,23 @@ class AuthCodeTest extends \PHPUnit_Framework_TestCase
|
||||
$accessTokenStorage->shouldReceive('create');
|
||||
$accessTokenStorage->shouldReceive('associateScope');
|
||||
$accessTokenStorage->shouldReceive('getScopes')->andReturn([
|
||||
(new Scope($server))->setId('foo')
|
||||
(new ScopeEntity($server))->setId('foo')
|
||||
]);
|
||||
|
||||
$scopeStorage = M::mock('League\OAuth2\Server\Storage\ScopeInterface');
|
||||
$scopeStorage->shouldReceive('setServer');
|
||||
$scopeStorage->shouldReceive('get')->andReturn(
|
||||
(new Scope($server))->setId('foo')
|
||||
(new ScopeEntity($server))->setId('foo')
|
||||
);
|
||||
|
||||
$authCodeStorage = M::mock('League\OAuth2\Server\Storage\AuthCodeInterface');
|
||||
$authCodeStorage->shouldReceive('setServer');
|
||||
$authCodeStorage->shouldReceive('delete');
|
||||
$authCodeStorage->shouldReceive('get')->andReturn(
|
||||
(new AC($server))->setToken('foobar')->setRedirectUri('http://foo/bar')
|
||||
(new AuthCodeEntity($server))->setToken('foobar')->setRedirectUri('http://foo/bar')
|
||||
);
|
||||
$authCodeStorage->shouldReceive('getScopes')->andReturn([
|
||||
(new Scope($server))->setId('foo')
|
||||
(new ScopeEntity($server))->setId('foo')
|
||||
]);
|
||||
|
||||
$server->setClientStorage($clientStorage);
|
||||
@ -551,17 +552,17 @@ class AuthCodeTest extends \PHPUnit_Framework_TestCase
|
||||
'code' => 'foo'
|
||||
];
|
||||
|
||||
$server = new Authorization;
|
||||
$server = new AuthorizationServer;
|
||||
$grant = new AuthCode;
|
||||
$rtgrant = new RefreshToken;
|
||||
|
||||
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
||||
$clientStorage->shouldReceive('setServer');
|
||||
$clientStorage->shouldReceive('getBySession')->andReturn(
|
||||
(new Client($server))->setId('testapp')
|
||||
(new ClientEntity($server))->setId('testapp')
|
||||
);
|
||||
$clientStorage->shouldReceive('get')->andReturn(
|
||||
(new Client($server))->setId('testapp')
|
||||
(new ClientEntity($server))->setId('testapp')
|
||||
);
|
||||
|
||||
$sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface');
|
||||
@ -569,7 +570,7 @@ class AuthCodeTest extends \PHPUnit_Framework_TestCase
|
||||
$sessionStorage->shouldReceive('create')->andreturn(123);
|
||||
$sessionStorage->shouldReceive('associateScope');
|
||||
$sessionStorage->shouldReceive('getByAuthCode')->andReturn(
|
||||
(new Session($server))->setId('foobar')
|
||||
(new SessionEntity($server))->setId('foobar')
|
||||
);
|
||||
|
||||
$accessTokenStorage = M::mock('League\OAuth2\Server\Storage\AccessTokenInterface');
|
||||
@ -577,23 +578,23 @@ class AuthCodeTest extends \PHPUnit_Framework_TestCase
|
||||
$accessTokenStorage->shouldReceive('create');
|
||||
$accessTokenStorage->shouldReceive('associateScope');
|
||||
$accessTokenStorage->shouldReceive('getScopes')->andReturn([
|
||||
(new Scope($server))->setId('foo')
|
||||
(new ScopeEntity($server))->setId('foo')
|
||||
]);
|
||||
|
||||
$scopeStorage = M::mock('League\OAuth2\Server\Storage\ScopeInterface');
|
||||
$scopeStorage->shouldReceive('setServer');
|
||||
$scopeStorage->shouldReceive('get')->andReturn(
|
||||
(new Scope($server))->setId('foo')
|
||||
(new ScopeEntity($server))->setId('foo')
|
||||
);
|
||||
|
||||
$authCodeStorage = M::mock('League\OAuth2\Server\Storage\AuthCodeInterface');
|
||||
$authCodeStorage->shouldReceive('setServer');
|
||||
$authCodeStorage->shouldReceive('delete');
|
||||
$authCodeStorage->shouldReceive('get')->andReturn(
|
||||
(new AC($server))->setToken('foobar')->setRedirectUri('http://foo/bar')
|
||||
(new AuthCodeEntity($server))->setToken('foobar')->setRedirectUri('http://foo/bar')
|
||||
);
|
||||
$authCodeStorage->shouldReceive('getScopes')->andReturn([
|
||||
(new Scope($server))->setId('foo')
|
||||
(new ScopeEntity($server))->setId('foo')
|
||||
]);
|
||||
|
||||
$refreshTokenStorage = M::mock('League\OAuth2\Server\Storage\RefreshTokenInterface');
|
||||
|
@ -5,7 +5,7 @@ namespace LeagueTests\Grant;
|
||||
use League\OAuth2\Server\Grant\ClientCredentials;
|
||||
use League\OAuth2\Server\Entity\ScopeEntity;
|
||||
use League\OAuth2\Server\Entity\ClientEntity;
|
||||
use League\OAuth2\Server\AuthorizationServer as Authorization;
|
||||
use League\OAuth2\Server\AuthorizationServer;
|
||||
use League\OAuth2\Server\Grant\ClientException;
|
||||
use Mockery as M;
|
||||
|
||||
@ -17,7 +17,7 @@ class ClientCredentialsTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
$_POST['grant_type'] = 'client_credentials';
|
||||
|
||||
$server = new Authorization;
|
||||
$server = new AuthorizationServer;
|
||||
$grant = new ClientCredentials;
|
||||
|
||||
$server->addGrantType($grant);
|
||||
@ -34,7 +34,7 @@ class ClientCredentialsTest extends \PHPUnit_Framework_TestCase
|
||||
'client_id' => 'testapp'
|
||||
];
|
||||
|
||||
$server = new Authorization;
|
||||
$server = new AuthorizationServer;
|
||||
$grant = new ClientCredentials;
|
||||
|
||||
$server->addGrantType($grant);
|
||||
@ -51,7 +51,7 @@ class ClientCredentialsTest extends \PHPUnit_Framework_TestCase
|
||||
'client_secret' => 'foobar'
|
||||
];
|
||||
|
||||
$server = new Authorization;
|
||||
$server = new AuthorizationServer;
|
||||
$grant = new ClientCredentials;
|
||||
|
||||
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
||||
@ -75,13 +75,13 @@ class ClientCredentialsTest extends \PHPUnit_Framework_TestCase
|
||||
'scope' => 'foo'
|
||||
];
|
||||
|
||||
$server = new Authorization;
|
||||
$server = new AuthorizationServer;
|
||||
$grant = new ClientCredentials;
|
||||
|
||||
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
||||
$clientStorage->shouldReceive('setServer');
|
||||
$clientStorage->shouldReceive('get')->andReturn(
|
||||
(new Client($server))->setId('testapp')
|
||||
(new ClientEntity($server))->setId('testapp')
|
||||
);
|
||||
|
||||
$sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface');
|
||||
@ -115,13 +115,13 @@ class ClientCredentialsTest extends \PHPUnit_Framework_TestCase
|
||||
'client_secret' => 'foobar'
|
||||
];
|
||||
|
||||
$server = new Authorization;
|
||||
$server = new AuthorizationServer;
|
||||
$grant = new ClientCredentials;
|
||||
|
||||
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
||||
$clientStorage->shouldReceive('setServer');
|
||||
$clientStorage->shouldReceive('get')->andReturn(
|
||||
(new Client($server))->setId('testapp')
|
||||
(new ClientEntity($server))->setId('testapp')
|
||||
);
|
||||
|
||||
$sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface');
|
||||
@ -139,7 +139,7 @@ class ClientCredentialsTest extends \PHPUnit_Framework_TestCase
|
||||
$scopeStorage = M::mock('League\OAuth2\Server\Storage\ScopeInterface');
|
||||
$scopeStorage->shouldReceive('setServer');
|
||||
// $scopeStorage->shouldReceive('get')->andReturn(
|
||||
// // (new Scope($server))->setId('foo')
|
||||
// // (new ScopeEntity($server))->setId('foo')
|
||||
// );
|
||||
|
||||
$server->setClientStorage($clientStorage);
|
||||
@ -160,20 +160,20 @@ class ClientCredentialsTest extends \PHPUnit_Framework_TestCase
|
||||
'scope' => 'foo'
|
||||
];
|
||||
|
||||
$server = new Authorization;
|
||||
$server = new AuthorizationServer;
|
||||
$grant = new ClientCredentials;
|
||||
|
||||
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
||||
$clientStorage->shouldReceive('setServer');
|
||||
$clientStorage->shouldReceive('get')->andReturn(
|
||||
(new Client($server))->setId('testapp')
|
||||
(new ClientEntity($server))->setId('testapp')
|
||||
);
|
||||
|
||||
$sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface');
|
||||
$sessionStorage->shouldReceive('setServer');
|
||||
$sessionStorage->shouldReceive('create')->andreturn(123);
|
||||
$sessionStorage->shouldReceive('getScopes')->shouldReceive('getScopes')->andReturn([
|
||||
(new Scope($server))->setId('foo')
|
||||
(new ScopeEntity($server))->setId('foo')
|
||||
]);
|
||||
$sessionStorage->shouldReceive('associateScope');
|
||||
|
||||
@ -181,14 +181,14 @@ class ClientCredentialsTest extends \PHPUnit_Framework_TestCase
|
||||
$accessTokenStorage->shouldReceive('setServer');
|
||||
$accessTokenStorage->shouldReceive('create');
|
||||
$accessTokenStorage->shouldReceive('getScopes')->andReturn([
|
||||
(new Scope($server))->setId('foo')
|
||||
(new ScopeEntity($server))->setId('foo')
|
||||
]);
|
||||
$accessTokenStorage->shouldReceive('associateScope');
|
||||
|
||||
$scopeStorage = M::mock('League\OAuth2\Server\Storage\ScopeInterface');
|
||||
$scopeStorage->shouldReceive('setServer');
|
||||
$scopeStorage->shouldReceive('get')->andReturn(
|
||||
(new Scope($server))->setId('foo')
|
||||
(new ScopeEntity($server))->setId('foo')
|
||||
);
|
||||
|
||||
$server->setClientStorage($clientStorage);
|
||||
|
@ -5,6 +5,8 @@ namespace LeagueTests\Grant;
|
||||
use League\OAuth2\Server\Grant\Password;
|
||||
use League\OAuth2\Server\Grant\RefreshToken;
|
||||
use League\OAuth2\Server\Entity\ScopeEntity;
|
||||
use League\OAuth2\Server\Entity\AccessTokenEntity;
|
||||
use League\OAuth2\Server\Entity\RefreshTokenEntity;
|
||||
use League\OAuth2\Server\Entity\ClientEntity;
|
||||
use League\OAuth2\Server\AuthorizationServer;
|
||||
use Mockery as M;
|
||||
@ -80,7 +82,7 @@ class PasswordTest extends \PHPUnit_Framework_TestCase
|
||||
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
||||
$clientStorage->shouldReceive('setServer');
|
||||
$clientStorage->shouldReceive('get')->andReturn(
|
||||
(new Client($server))->setId('testapp')
|
||||
(new ClientEntity($server))->setId('testapp')
|
||||
);
|
||||
|
||||
$sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface');
|
||||
@ -123,7 +125,7 @@ class PasswordTest extends \PHPUnit_Framework_TestCase
|
||||
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
||||
$clientStorage->shouldReceive('setServer');
|
||||
$clientStorage->shouldReceive('get')->andReturn(
|
||||
(new Client($server))->setId('testapp')
|
||||
(new ClientEntity($server))->setId('testapp')
|
||||
);
|
||||
|
||||
$sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface');
|
||||
@ -167,7 +169,7 @@ class PasswordTest extends \PHPUnit_Framework_TestCase
|
||||
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
||||
$clientStorage->shouldReceive('setServer');
|
||||
$clientStorage->shouldReceive('get')->andReturn(
|
||||
(new Client($server))->setId('testapp')
|
||||
(new ClientEntity($server))->setId('testapp')
|
||||
);
|
||||
|
||||
$sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface');
|
||||
@ -212,7 +214,7 @@ class PasswordTest extends \PHPUnit_Framework_TestCase
|
||||
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
||||
$clientStorage->shouldReceive('setServer');
|
||||
$clientStorage->shouldReceive('get')->andReturn(
|
||||
(new Client($server))->setId('testapp')
|
||||
(new ClientEntity($server))->setId('testapp')
|
||||
);
|
||||
|
||||
$sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface');
|
||||
@ -259,7 +261,7 @@ class PasswordTest extends \PHPUnit_Framework_TestCase
|
||||
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
||||
$clientStorage->shouldReceive('setServer');
|
||||
$clientStorage->shouldReceive('get')->andReturn(
|
||||
(new Client($server))->setId('testapp')
|
||||
(new ClientEntity($server))->setId('testapp')
|
||||
);
|
||||
|
||||
$sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface');
|
||||
@ -309,14 +311,14 @@ class PasswordTest extends \PHPUnit_Framework_TestCase
|
||||
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
||||
$clientStorage->shouldReceive('setServer');
|
||||
$clientStorage->shouldReceive('get')->andReturn(
|
||||
(new Client($server))->setId('testapp')
|
||||
(new ClientEntity($server))->setId('testapp')
|
||||
);
|
||||
|
||||
$sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface');
|
||||
$sessionStorage->shouldReceive('setServer');
|
||||
$sessionStorage->shouldReceive('create')->andreturn(123);
|
||||
$sessionStorage->shouldReceive('getScopes')->shouldReceive('getScopes')->andReturn([
|
||||
(new Scope($server))->setId('foo')
|
||||
(new ScopeEntity($server))->setId('foo')
|
||||
]);
|
||||
$sessionStorage->shouldReceive('associateScope');
|
||||
|
||||
@ -324,14 +326,14 @@ class PasswordTest extends \PHPUnit_Framework_TestCase
|
||||
$accessTokenStorage->shouldReceive('setServer');
|
||||
$accessTokenStorage->shouldReceive('create');
|
||||
$accessTokenStorage->shouldReceive('getScopes')->andReturn([
|
||||
(new Scope($server))->setId('foo')
|
||||
(new ScopeEntity($server))->setId('foo')
|
||||
]);
|
||||
$accessTokenStorage->shouldReceive('associateScope');
|
||||
|
||||
$scopeStorage = M::mock('League\OAuth2\Server\Storage\ScopeInterface');
|
||||
$scopeStorage->shouldReceive('setServer');
|
||||
$scopeStorage->shouldReceive('get')->andReturn(
|
||||
(new Scope($server))->setId('foo')
|
||||
(new ScopeEntity($server))->setId('foo')
|
||||
);
|
||||
|
||||
$server->setClientStorage($clientStorage);
|
||||
@ -363,14 +365,14 @@ class PasswordTest extends \PHPUnit_Framework_TestCase
|
||||
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
||||
$clientStorage->shouldReceive('setServer');
|
||||
$clientStorage->shouldReceive('get')->andReturn(
|
||||
(new Client($server))->setId('testapp')
|
||||
(new ClientEntity($server))->setId('testapp')
|
||||
);
|
||||
|
||||
$sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface');
|
||||
$sessionStorage->shouldReceive('setServer');
|
||||
$sessionStorage->shouldReceive('create')->andreturn(123);
|
||||
$sessionStorage->shouldReceive('getScopes')->shouldReceive('getScopes')->andReturn([
|
||||
(new Scope($server))->setId('foo')
|
||||
(new ScopeEntity($server))->setId('foo')
|
||||
]);
|
||||
$sessionStorage->shouldReceive('associateScope');
|
||||
|
||||
@ -378,14 +380,14 @@ class PasswordTest extends \PHPUnit_Framework_TestCase
|
||||
$accessTokenStorage->shouldReceive('setServer');
|
||||
$accessTokenStorage->shouldReceive('create');
|
||||
$accessTokenStorage->shouldReceive('getScopes')->andReturn([
|
||||
(new Scope($server))->setId('foo')
|
||||
(new ScopeEntity($server))->setId('foo')
|
||||
]);
|
||||
$accessTokenStorage->shouldReceive('associateScope');
|
||||
|
||||
$scopeStorage = M::mock('League\OAuth2\Server\Storage\ScopeInterface');
|
||||
$scopeStorage->shouldReceive('setServer');
|
||||
$scopeStorage->shouldReceive('get')->andReturn(
|
||||
(new Scope($server))->setId('foo')
|
||||
(new ScopeEntity($server))->setId('foo')
|
||||
);
|
||||
|
||||
$server->setClientStorage($clientStorage);
|
||||
@ -422,14 +424,14 @@ class PasswordTest extends \PHPUnit_Framework_TestCase
|
||||
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
||||
$clientStorage->shouldReceive('setServer');
|
||||
$clientStorage->shouldReceive('get')->andReturn(
|
||||
(new Client($server))->setId('testapp')
|
||||
(new ClientEntity($server))->setId('testapp')
|
||||
);
|
||||
|
||||
$sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface');
|
||||
$sessionStorage->shouldReceive('setServer');
|
||||
$sessionStorage->shouldReceive('create')->andreturn(123);
|
||||
$sessionStorage->shouldReceive('getScopes')->shouldReceive('getScopes')->andReturn([
|
||||
(new Scope($server))->setId('foo')
|
||||
(new ScopeEntity($server))->setId('foo')
|
||||
]);
|
||||
$sessionStorage->shouldReceive('associateScope');
|
||||
|
||||
@ -437,14 +439,14 @@ class PasswordTest extends \PHPUnit_Framework_TestCase
|
||||
$accessTokenStorage->shouldReceive('setServer');
|
||||
$accessTokenStorage->shouldReceive('create');
|
||||
$accessTokenStorage->shouldReceive('getScopes')->andReturn([
|
||||
(new Scope($server))->setId('foo')
|
||||
(new ScopeEntity($server))->setId('foo')
|
||||
]);
|
||||
$accessTokenStorage->shouldReceive('associateScope');
|
||||
|
||||
$scopeStorage = M::mock('League\OAuth2\Server\Storage\ScopeInterface');
|
||||
$scopeStorage->shouldReceive('setServer');
|
||||
$scopeStorage->shouldReceive('get')->andReturn(
|
||||
(new Scope($server))->setId('foo')
|
||||
(new ScopeEntity($server))->setId('foo')
|
||||
);
|
||||
|
||||
$refreshTokenStorage = M::mock('League\OAuth2\Server\Storage\RefreshTokenInterface');
|
||||
|
@ -7,7 +7,7 @@ use League\OAuth2\Server\Entity\ScopeEntity;
|
||||
use League\OAuth2\Server\Entity\ClientEntity;
|
||||
use League\OAuth2\Server\Entity\AccessTokenEntity;
|
||||
use League\OAuth2\Server\Entity\SessionEntity;
|
||||
use League\OAuth2\Server\Entity\RefreshToken as RT;
|
||||
use League\OAuth2\Server\Entity\RefreshTokenEntity;
|
||||
use League\OAuth2\Server\AuthorizationServer;
|
||||
use Mockery as M;
|
||||
|
||||
@ -92,7 +92,7 @@ class RefreshTokenTest extends \PHPUnit_Framework_TestCase
|
||||
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
||||
$clientStorage->shouldReceive('setServer');
|
||||
$clientStorage->shouldReceive('get')->andReturn(
|
||||
(new Client($server))->setId('testapp')
|
||||
(new ClientEntity($server))->setId('testapp')
|
||||
);
|
||||
|
||||
$sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface');
|
||||
@ -127,7 +127,7 @@ class RefreshTokenTest extends \PHPUnit_Framework_TestCase
|
||||
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
||||
$clientStorage->shouldReceive('setServer');
|
||||
$clientStorage->shouldReceive('get')->andReturn(
|
||||
(new Client($server))->setId('testapp')
|
||||
(new ClientEntity($server))->setId('testapp')
|
||||
);
|
||||
|
||||
$refreshTokenStorage = M::mock('League\OAuth2\Server\Storage\RefreshTokenInterface');
|
||||
@ -161,7 +161,7 @@ class RefreshTokenTest extends \PHPUnit_Framework_TestCase
|
||||
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
||||
$clientStorage->shouldReceive('setServer');
|
||||
$clientStorage->shouldReceive('get')->andReturn(
|
||||
(new Client($server))->setId('testapp')
|
||||
(new ClientEntity($server))->setId('testapp')
|
||||
);
|
||||
|
||||
$sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface');
|
||||
@ -169,18 +169,18 @@ class RefreshTokenTest extends \PHPUnit_Framework_TestCase
|
||||
$sessionStorage->shouldReceive('getScopes')->shouldReceive('getScopes')->andReturn([]);
|
||||
$sessionStorage->shouldReceive('associateScope');
|
||||
$sessionStorage->shouldReceive('getByAccessToken')->andReturn(
|
||||
(new Session($server))
|
||||
(new SessionEntity($server))
|
||||
);
|
||||
|
||||
$accessTokenStorage = M::mock('League\OAuth2\Server\Storage\AccessTokenInterface');
|
||||
$accessTokenStorage->shouldReceive('setServer');
|
||||
$accessTokenStorage->shouldReceive('getByRefreshToken')->andReturn(
|
||||
(new AccessToken($server))
|
||||
(new AccessTokenEntity($server))
|
||||
);
|
||||
$accessTokenStorage->shouldReceive('delete');
|
||||
$accessTokenStorage->shouldReceive('create');
|
||||
$accessTokenStorage->shouldReceive('getScopes')->andReturn([
|
||||
(new Scope($server))->setId('foo')
|
||||
(new ScopeEntity($server))->setId('foo')
|
||||
]);
|
||||
$accessTokenStorage->shouldReceive('associateScope');
|
||||
|
||||
@ -190,13 +190,13 @@ class RefreshTokenTest extends \PHPUnit_Framework_TestCase
|
||||
$refreshTokenStorage->shouldReceive('delete');
|
||||
$refreshTokenStorage->shouldReceive('create');
|
||||
$refreshTokenStorage->shouldReceive('get')->andReturn(
|
||||
(new RT($server))
|
||||
(new RefreshTokenEntity($server))
|
||||
);
|
||||
|
||||
$scopeStorage = M::mock('League\OAuth2\Server\Storage\ScopeInterface');
|
||||
$scopeStorage->shouldReceive('setServer');
|
||||
$scopeStorage->shouldReceive('get')->andReturn(
|
||||
(new Scope($server))->setId('foo')
|
||||
(new ScopeEntity($server))->setId('foo')
|
||||
);
|
||||
|
||||
$server->setClientStorage($clientStorage);
|
||||
@ -228,12 +228,12 @@ class RefreshTokenTest extends \PHPUnit_Framework_TestCase
|
||||
$server = new AuthorizationServer;
|
||||
$grant = new RefreshToken;
|
||||
|
||||
$oldSession = (new Session($server))->associateScope((new Scope($server))->setId('foo'));
|
||||
$oldSession = (new SessionEntity($server))->associateScope((new ScopeEntity($server))->setId('foo'));
|
||||
|
||||
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
||||
$clientStorage->shouldReceive('setServer');
|
||||
$clientStorage->shouldReceive('get')->andReturn(
|
||||
(new Client($server))->setId('testapp')
|
||||
(new ClientEntity($server))->setId('testapp')
|
||||
);
|
||||
|
||||
$sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface');
|
||||
@ -247,12 +247,12 @@ class RefreshTokenTest extends \PHPUnit_Framework_TestCase
|
||||
$accessTokenStorage = M::mock('League\OAuth2\Server\Storage\AccessTokenInterface');
|
||||
$accessTokenStorage->shouldReceive('setServer');
|
||||
$accessTokenStorage->shouldReceive('getByRefreshToken')->andReturn(
|
||||
(new AccessToken($server))
|
||||
(new AccessTokenEntity($server))
|
||||
);
|
||||
$accessTokenStorage->shouldReceive('delete');
|
||||
$accessTokenStorage->shouldReceive('create');
|
||||
$accessTokenStorage->shouldReceive('getScopes')->andReturn([
|
||||
(new Scope($server))->setId('foo')
|
||||
(new ScopeEntity($server))->setId('foo')
|
||||
]);
|
||||
$accessTokenStorage->shouldReceive('associateScope');
|
||||
|
||||
@ -262,13 +262,13 @@ class RefreshTokenTest extends \PHPUnit_Framework_TestCase
|
||||
$refreshTokenStorage->shouldReceive('delete');
|
||||
$refreshTokenStorage->shouldReceive('create');
|
||||
$refreshTokenStorage->shouldReceive('get')->andReturn(
|
||||
(new RT($server))
|
||||
(new RefreshTokenEntity($server))
|
||||
);
|
||||
|
||||
$scopeStorage = M::mock('League\OAuth2\Server\Storage\ScopeInterface');
|
||||
$scopeStorage->shouldReceive('setServer');
|
||||
$scopeStorage->shouldReceive('get')->andReturn(
|
||||
(new Scope($server))->setId('foo')
|
||||
(new ScopeEntity($server))->setId('foo')
|
||||
);
|
||||
|
||||
$server->setClientStorage($clientStorage);
|
||||
@ -300,12 +300,12 @@ class RefreshTokenTest extends \PHPUnit_Framework_TestCase
|
||||
$server = new AuthorizationServer;
|
||||
$grant = new RefreshToken;
|
||||
|
||||
$oldSession = (new Session($server))->associateScope((new Scope($server))->setId('foo'));
|
||||
$oldSession = (new SessionEntity($server))->associateScope((new ScopeEntity($server))->setId('foo'));
|
||||
|
||||
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
||||
$clientStorage->shouldReceive('setServer');
|
||||
$clientStorage->shouldReceive('get')->andReturn(
|
||||
(new Client($server))->setId('testapp')
|
||||
(new ClientEntity($server))->setId('testapp')
|
||||
);
|
||||
|
||||
$sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface');
|
||||
@ -319,12 +319,12 @@ class RefreshTokenTest extends \PHPUnit_Framework_TestCase
|
||||
$accessTokenStorage = M::mock('League\OAuth2\Server\Storage\AccessTokenInterface');
|
||||
$accessTokenStorage->shouldReceive('setServer');
|
||||
$accessTokenStorage->shouldReceive('getByRefreshToken')->andReturn(
|
||||
(new AccessToken($server))
|
||||
(new AccessTokenEntity($server))
|
||||
);
|
||||
$accessTokenStorage->shouldReceive('delete');
|
||||
$accessTokenStorage->shouldReceive('create');
|
||||
$accessTokenStorage->shouldReceive('getScopes')->andReturn([
|
||||
(new Scope($server))->setId('foo')
|
||||
(new ScopeEntity($server))->setId('foo')
|
||||
]);
|
||||
$accessTokenStorage->shouldReceive('associateScope');
|
||||
|
||||
@ -334,13 +334,13 @@ class RefreshTokenTest extends \PHPUnit_Framework_TestCase
|
||||
$refreshTokenStorage->shouldReceive('delete');
|
||||
$refreshTokenStorage->shouldReceive('create');
|
||||
$refreshTokenStorage->shouldReceive('get')->andReturn(
|
||||
(new RT($server))
|
||||
(new RefreshTokenEntity($server))
|
||||
);
|
||||
|
||||
$scopeStorage = M::mock('League\OAuth2\Server\Storage\ScopeInterface');
|
||||
$scopeStorage->shouldReceive('setServer');
|
||||
$scopeStorage->shouldReceive('get')->andReturn(
|
||||
(new Scope($server))->setId('blah')
|
||||
(new ScopeEntity($server))->setId('blah')
|
||||
);
|
||||
|
||||
$server->setClientStorage($clientStorage);
|
||||
|
@ -139,20 +139,20 @@ class ResourceServerTest extends \PHPUnit_Framework_TestCase
|
||||
$server->setTokenKey('at');
|
||||
|
||||
$accessTokenStorage->shouldReceive('get')->andReturn(
|
||||
(new AccessToken($server))->setToken('abcdef')
|
||||
(new AccessTokenEntity($server))->setToken('abcdef')
|
||||
);
|
||||
|
||||
$accessTokenStorage->shouldReceive('getScopes')->andReturn([
|
||||
(new Scope($server))->setId('foo'),
|
||||
(new Scope($server))->setId('bar')
|
||||
(new ScopeEntity($server))->setId('foo'),
|
||||
(new ScopeEntity($server))->setId('bar')
|
||||
]);
|
||||
|
||||
$sessionStorage->shouldReceive('getByAccessToken')->andReturn(
|
||||
(new Session($server))->setId('foobar')->setOwner('user', 123)
|
||||
(new SessionEntity($server))->setId('foobar')->setOwner('user', 123)
|
||||
);
|
||||
|
||||
$clientStorage->shouldReceive('getBySession')->andReturn(
|
||||
(new Client($server))->setId('testapp')
|
||||
(new ClientEntity($server))->setId('testapp')
|
||||
);
|
||||
|
||||
$request = new \Symfony\Component\HttpFoundation\Request();
|
||||
|
Loading…
Reference in New Issue
Block a user