mirror of
https://github.com/elyby/oauth2-server.git
synced 2024-12-16 02:08:56 +05:30
100% test coverage
This commit is contained in:
parent
f24d1be3e9
commit
9af1d2a201
@ -153,10 +153,9 @@ abstract class AbstractTokenEntity
|
|||||||
*/
|
*/
|
||||||
public function __toString()
|
public function __toString()
|
||||||
{
|
{
|
||||||
if (is_null($this->token)) {
|
if ($this->token === null) {
|
||||||
throw new \BadMethodCallException('Token is null');
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->token;
|
return $this->token;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@ class UnauthorizedClientException extends OAuthException
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function __construct($parameter)
|
public function __construct()
|
||||||
{
|
{
|
||||||
parent::__construct('The client is not authorized to request an access token using this method.');
|
parent::__construct('The client is not authorized to request an access token using this method.');
|
||||||
}
|
}
|
||||||
|
@ -74,7 +74,7 @@ class AbstractTokenTest extends \PHPUnit_Framework_TestCase
|
|||||||
$accessTokenStorage->shouldReceive('getScopes')->andReturn(
|
$accessTokenStorage->shouldReceive('getScopes')->andReturn(
|
||||||
[]
|
[]
|
||||||
);
|
);
|
||||||
$accessTokenStorage->shouldReceive('setServer');
|
$accessTokenStorage''>shouldReceive('setServer');
|
||||||
|
|
||||||
$server->setAccessTokenStorage($accessTokenStorage);
|
$server->setAccessTokenStorage($accessTokenStorage);
|
||||||
|
|
||||||
@ -103,4 +103,14 @@ class AbstractTokenTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertTrue($result['scope1'] instanceof ScopeEntity);
|
$this->assertTrue($result['scope1'] instanceof ScopeEntity);
|
||||||
$this->assertTrue($result['scope2'] instanceof ScopeEntity);
|
$this->assertTrue($result['scope2'] instanceof ScopeEntity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function test__toString()
|
||||||
|
{
|
||||||
|
$server = M::mock('League\OAuth2\Server\AbstractServer');
|
||||||
|
|
||||||
|
$entity = new StubAbstractTokenEntity($server);
|
||||||
|
$this->assertEquals('', (string) $entity);
|
||||||
|
$entity->setToken('foobar');
|
||||||
|
$this->assertEquals('foobar', (string) $entity);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -198,4 +198,55 @@ class ClientCredentialsGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
$server->addGrantType($grant);
|
$server->addGrantType($grant);
|
||||||
$server->issueAccessToken();
|
$server->issueAccessToken();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testClientNotAuthorizedToUseGrant()
|
||||||
|
{
|
||||||
|
$this->setExpectedException('\League\OAuth2\Server\Exception\UnauthorizedClientException');
|
||||||
|
|
||||||
|
$_POST = [
|
||||||
|
'grant_type' => 'client_credentials',
|
||||||
|
'client_id' => 'testapp',
|
||||||
|
'client_secret' => 'foobar',
|
||||||
|
'scope' => 'foo'
|
||||||
|
];
|
||||||
|
|
||||||
|
$server = new AuthorizationServer;
|
||||||
|
$grant = new ClientCredentialsGrant;
|
||||||
|
|
||||||
|
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
||||||
|
$clientStorage->shouldReceive('setServer');
|
||||||
|
$clientStorage->shouldReceive('get')->andThrow(
|
||||||
|
new \League\OAuth2\Server\Exception\UnauthorizedClientException
|
||||||
|
);
|
||||||
|
|
||||||
|
$sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface');
|
||||||
|
$sessionStorage->shouldReceive('setServer');
|
||||||
|
// $sessionStorage->shouldReceive('create')->andreturn(123);
|
||||||
|
// $sessionStorage->shouldReceive('getScopes')->shouldReceive('getScopes')->andReturn([
|
||||||
|
// (new ScopeEntity($server))->setId('foo')
|
||||||
|
// ]);
|
||||||
|
// $sessionStorage->shouldReceive('associateScope');
|
||||||
|
|
||||||
|
$accessTokenStorage = M::mock('League\OAuth2\Server\Storage\AccessTokenInterface');
|
||||||
|
$accessTokenStorage->shouldReceive('setServer');
|
||||||
|
// $accessTokenStorage->shouldReceive('create');
|
||||||
|
// $accessTokenStorage->shouldReceive('getScopes')->andReturn([
|
||||||
|
// (new ScopeEntity($server))->setId('foo')
|
||||||
|
// ]);
|
||||||
|
// $accessTokenStorage->shouldReceive('associateScope');
|
||||||
|
|
||||||
|
$scopeStorage = M::mock('League\OAuth2\Server\Storage\ScopeInterface');
|
||||||
|
$scopeStorage->shouldReceive('setServer');
|
||||||
|
$scopeStorage->shouldReceive('get')->andReturn(
|
||||||
|
(new ScopeEntity($server))->setId('foo')
|
||||||
|
);
|
||||||
|
|
||||||
|
$server->setClientStorage($clientStorage);
|
||||||
|
$server->setScopeStorage($scopeStorage);
|
||||||
|
$server->setSessionStorage($sessionStorage);
|
||||||
|
$server->setAccessTokenStorage($accessTokenStorage);
|
||||||
|
|
||||||
|
$server->addGrantType($grant);
|
||||||
|
$server->issueAccessToken();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user