mirror of
https://github.com/elyby/oauth2-server.git
synced 2024-12-29 00:10:43 +05:30
Fix more tests to support default scope setting
This commit is contained in:
parent
8c788e9fc8
commit
24f29b6382
@ -9,11 +9,14 @@ use League\OAuth2\Server\Repositories\ClientRepositoryInterface;
|
|||||||
use League\OAuth2\Server\Repositories\ScopeRepositoryInterface;
|
use League\OAuth2\Server\Repositories\ScopeRepositoryInterface;
|
||||||
use LeagueTests\Stubs\AccessTokenEntity;
|
use LeagueTests\Stubs\AccessTokenEntity;
|
||||||
use LeagueTests\Stubs\ClientEntity;
|
use LeagueTests\Stubs\ClientEntity;
|
||||||
|
use LeagueTests\Stubs\ScopeEntity;
|
||||||
use LeagueTests\Stubs\StubResponseType;
|
use LeagueTests\Stubs\StubResponseType;
|
||||||
use Zend\Diactoros\ServerRequest;
|
use Zend\Diactoros\ServerRequest;
|
||||||
|
|
||||||
class ClientCredentialsGrantTest extends \PHPUnit_Framework_TestCase
|
class ClientCredentialsGrantTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
|
const DEFAULT_SCOPE = 'basic';
|
||||||
|
|
||||||
public function testGetIdentifier()
|
public function testGetIdentifier()
|
||||||
{
|
{
|
||||||
$grant = new ClientCredentialsGrant();
|
$grant = new ClientCredentialsGrant();
|
||||||
@ -30,13 +33,16 @@ class ClientCredentialsGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
$accessTokenRepositoryMock->method('getNewToken')->willReturn(new AccessTokenEntity());
|
$accessTokenRepositoryMock->method('getNewToken')->willReturn(new AccessTokenEntity());
|
||||||
$accessTokenRepositoryMock->method('persistNewAccessToken')->willReturnSelf();
|
$accessTokenRepositoryMock->method('persistNewAccessToken')->willReturnSelf();
|
||||||
|
|
||||||
|
$scope = new ScopeEntity();
|
||||||
$scopeRepositoryMock = $this->getMockBuilder(ScopeRepositoryInterface::class)->getMock();
|
$scopeRepositoryMock = $this->getMockBuilder(ScopeRepositoryInterface::class)->getMock();
|
||||||
|
$scopeRepositoryMock->method('getScopeEntityByIdentifier')->willReturn($scope);
|
||||||
$scopeRepositoryMock->method('finalizeScopes')->willReturnArgument(0);
|
$scopeRepositoryMock->method('finalizeScopes')->willReturnArgument(0);
|
||||||
|
|
||||||
$grant = new ClientCredentialsGrant();
|
$grant = new ClientCredentialsGrant();
|
||||||
$grant->setClientRepository($clientRepositoryMock);
|
$grant->setClientRepository($clientRepositoryMock);
|
||||||
$grant->setAccessTokenRepository($accessTokenRepositoryMock);
|
$grant->setAccessTokenRepository($accessTokenRepositoryMock);
|
||||||
$grant->setScopeRepository($scopeRepositoryMock);
|
$grant->setScopeRepository($scopeRepositoryMock);
|
||||||
|
$grant->setDefaultScope(self::DEFAULT_SCOPE);
|
||||||
|
|
||||||
$serverRequest = new ServerRequest();
|
$serverRequest = new ServerRequest();
|
||||||
$serverRequest = $serverRequest->withParsedBody(
|
$serverRequest = $serverRequest->withParsedBody(
|
||||||
|
@ -22,6 +22,8 @@ use Zend\Diactoros\ServerRequest;
|
|||||||
|
|
||||||
class ImplicitGrantTest extends \PHPUnit_Framework_TestCase
|
class ImplicitGrantTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
|
const DEFAULT_SCOPE = 'basic';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* CryptTrait stub
|
* CryptTrait stub
|
||||||
*/
|
*/
|
||||||
@ -96,6 +98,7 @@ class ImplicitGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
$grant = new ImplicitGrant(new \DateInterval('PT10M'));
|
$grant = new ImplicitGrant(new \DateInterval('PT10M'));
|
||||||
$grant->setClientRepository($clientRepositoryMock);
|
$grant->setClientRepository($clientRepositoryMock);
|
||||||
$grant->setScopeRepository($scopeRepositoryMock);
|
$grant->setScopeRepository($scopeRepositoryMock);
|
||||||
|
$grant->setDefaultScope(self::DEFAULT_SCOPE);
|
||||||
|
|
||||||
$request = new ServerRequest(
|
$request = new ServerRequest(
|
||||||
[],
|
[],
|
||||||
@ -130,6 +133,7 @@ class ImplicitGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
$grant = new ImplicitGrant(new \DateInterval('PT10M'));
|
$grant = new ImplicitGrant(new \DateInterval('PT10M'));
|
||||||
$grant->setClientRepository($clientRepositoryMock);
|
$grant->setClientRepository($clientRepositoryMock);
|
||||||
$grant->setScopeRepository($scopeRepositoryMock);
|
$grant->setScopeRepository($scopeRepositoryMock);
|
||||||
|
$grant->setDefaultScope(self::DEFAULT_SCOPE);
|
||||||
|
|
||||||
$request = new ServerRequest(
|
$request = new ServerRequest(
|
||||||
[],
|
[],
|
||||||
|
@ -13,12 +13,15 @@ use League\OAuth2\Server\Repositories\UserRepositoryInterface;
|
|||||||
use LeagueTests\Stubs\AccessTokenEntity;
|
use LeagueTests\Stubs\AccessTokenEntity;
|
||||||
use LeagueTests\Stubs\ClientEntity;
|
use LeagueTests\Stubs\ClientEntity;
|
||||||
use LeagueTests\Stubs\RefreshTokenEntity;
|
use LeagueTests\Stubs\RefreshTokenEntity;
|
||||||
|
use LeagueTests\Stubs\ScopeEntity;
|
||||||
use LeagueTests\Stubs\StubResponseType;
|
use LeagueTests\Stubs\StubResponseType;
|
||||||
use LeagueTests\Stubs\UserEntity;
|
use LeagueTests\Stubs\UserEntity;
|
||||||
use Zend\Diactoros\ServerRequest;
|
use Zend\Diactoros\ServerRequest;
|
||||||
|
|
||||||
class PasswordGrantTest extends \PHPUnit_Framework_TestCase
|
class PasswordGrantTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
|
const DEFAULT_SCOPE = 'basic';
|
||||||
|
|
||||||
public function testGetIdentifier()
|
public function testGetIdentifier()
|
||||||
{
|
{
|
||||||
$userRepositoryMock = $this->getMockBuilder(UserRepositoryInterface::class)->getMock();
|
$userRepositoryMock = $this->getMockBuilder(UserRepositoryInterface::class)->getMock();
|
||||||
@ -46,13 +49,16 @@ class PasswordGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
$refreshTokenRepositoryMock->method('persistNewRefreshToken')->willReturnSelf();
|
$refreshTokenRepositoryMock->method('persistNewRefreshToken')->willReturnSelf();
|
||||||
$refreshTokenRepositoryMock->method('getNewRefreshToken')->willReturn(new RefreshTokenEntity());
|
$refreshTokenRepositoryMock->method('getNewRefreshToken')->willReturn(new RefreshTokenEntity());
|
||||||
|
|
||||||
|
$scope = new ScopeEntity();
|
||||||
$scopeRepositoryMock = $this->getMockBuilder(ScopeRepositoryInterface::class)->getMock();
|
$scopeRepositoryMock = $this->getMockBuilder(ScopeRepositoryInterface::class)->getMock();
|
||||||
|
$scopeRepositoryMock->method('getScopeEntityByIdentifier')->willReturn($scope);
|
||||||
$scopeRepositoryMock->method('finalizeScopes')->willReturnArgument(0);
|
$scopeRepositoryMock->method('finalizeScopes')->willReturnArgument(0);
|
||||||
|
|
||||||
$grant = new PasswordGrant($userRepositoryMock, $refreshTokenRepositoryMock);
|
$grant = new PasswordGrant($userRepositoryMock, $refreshTokenRepositoryMock);
|
||||||
$grant->setClientRepository($clientRepositoryMock);
|
$grant->setClientRepository($clientRepositoryMock);
|
||||||
$grant->setAccessTokenRepository($accessTokenRepositoryMock);
|
$grant->setAccessTokenRepository($accessTokenRepositoryMock);
|
||||||
$grant->setScopeRepository($scopeRepositoryMock);
|
$grant->setScopeRepository($scopeRepositoryMock);
|
||||||
|
$grant->setDefaultScope(self::DEFAULT_SCOPE);
|
||||||
|
|
||||||
$serverRequest = new ServerRequest();
|
$serverRequest = new ServerRequest();
|
||||||
$serverRequest = $serverRequest->withParsedBody(
|
$serverRequest = $serverRequest->withParsedBody(
|
||||||
|
@ -20,6 +20,8 @@ use Zend\Diactoros\ServerRequest;
|
|||||||
|
|
||||||
class RefreshTokenGrantTest extends \PHPUnit_Framework_TestCase
|
class RefreshTokenGrantTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
|
const DEFAULT_SCOPE = 'basic';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var CryptTraitStub
|
* @var CryptTraitStub
|
||||||
*/
|
*/
|
||||||
@ -61,12 +63,17 @@ class RefreshTokenGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('persistNewRefreshToken')->willReturnSelf();
|
->method('persistNewRefreshToken')->willReturnSelf();
|
||||||
|
|
||||||
|
$oldRefreshTokenCheckResult = ['scopes' => $scopeEntity->getIdentifier()];
|
||||||
|
|
||||||
|
$refreshTokenRepositoryMock->method('validateOldRefreshToken')->willReturn($oldRefreshTokenCheckResult);
|
||||||
|
|
||||||
$grant = new RefreshTokenGrant($refreshTokenRepositoryMock);
|
$grant = new RefreshTokenGrant($refreshTokenRepositoryMock);
|
||||||
$grant->setClientRepository($clientRepositoryMock);
|
$grant->setClientRepository($clientRepositoryMock);
|
||||||
$grant->setScopeRepository($scopeRepositoryMock);
|
$grant->setScopeRepository($scopeRepositoryMock);
|
||||||
$grant->setAccessTokenRepository($accessTokenRepositoryMock);
|
$grant->setAccessTokenRepository($accessTokenRepositoryMock);
|
||||||
$grant->setEncryptionKey($this->cryptStub->getKey());
|
$grant->setEncryptionKey($this->cryptStub->getKey());
|
||||||
$grant->setPrivateKey(new CryptKey('file://' . __DIR__ . '/../Stubs/private.key'));
|
$grant->setPrivateKey(new CryptKey('file://' . __DIR__ . '/../Stubs/private.key'));
|
||||||
|
$grant->setDefaultScope(self::DEFAULT_SCOPE);
|
||||||
|
|
||||||
$oldRefreshToken = $this->cryptStub->doEncrypt(
|
$oldRefreshToken = $this->cryptStub->doEncrypt(
|
||||||
json_encode(
|
json_encode(
|
||||||
|
Loading…
Reference in New Issue
Block a user