mirror of
https://github.com/elyby/oauth2-server.git
synced 2024-11-30 02:33:14 +05:30
Updated unit tests
This commit is contained in:
parent
7dc5a8090f
commit
583c21e7db
@ -22,4 +22,13 @@ class OAuthExceptionTest extends \PHPUnit_Framework_TestCase
|
||||
$exception->httpStatusCode = 501;
|
||||
$this->assertSame($exception->getHttpHeaders(), ['HTTP/1.1 501 Not Implemented']);
|
||||
}
|
||||
|
||||
public function testShouldRedirect()
|
||||
{
|
||||
$exception = new \League\OAuth2\Server\Exception\OAuthException();
|
||||
$exception->redirectUri = 'http://example.com/';
|
||||
$exception->errorType = 'Error';
|
||||
$this->assertTrue($exception->shouldRedirect());
|
||||
$this->assertEquals('http://example.com/?error=Error&message=An+error+occured', $exception->getRedirectUri());
|
||||
}
|
||||
}
|
||||
|
@ -446,6 +446,57 @@ class AuthCodeGrantTest extends \PHPUnit_Framework_TestCase
|
||||
$server->issueAccessToken();
|
||||
}
|
||||
|
||||
public function testCompleteFlowExpiredCode()
|
||||
{
|
||||
$this->setExpectedException('League\OAuth2\Server\Exception\InvalidRequestException');
|
||||
|
||||
$_POST = [
|
||||
'grant_type' => 'authorization_code',
|
||||
'client_id' => 'testapp',
|
||||
'client_secret' => 'foobar',
|
||||
'redirect_uri' => 'http://foo/bar',
|
||||
'code' => 'foobar'
|
||||
];
|
||||
|
||||
$server = new AuthorizationServer;
|
||||
$grant = new AuthCodeGrant;
|
||||
|
||||
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
||||
$clientStorage->shouldReceive('setServer');
|
||||
$clientStorage->shouldReceive('get')->andReturn(
|
||||
(new ClientEntity($server))->hydrate(['id' => 'testapp'])
|
||||
);
|
||||
|
||||
$sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface');
|
||||
$sessionStorage->shouldReceive('setServer');
|
||||
$sessionStorage->shouldReceive('create');
|
||||
$sessionStorage->shouldReceive('getScopes')->andReturn([]);
|
||||
|
||||
$accessTokenStorage = M::mock('League\OAuth2\Server\Storage\AccessTokenInterface');
|
||||
$accessTokenStorage->shouldReceive('setServer');
|
||||
$accessTokenStorage->shouldReceive('create');
|
||||
$accessTokenStorage->shouldReceive('getScopes')->andReturn([]);
|
||||
|
||||
$scopeStorage = M::mock('League\OAuth2\Server\Storage\ScopeInterface');
|
||||
$scopeStorage->shouldReceive('setServer');
|
||||
$scopeStorage->shouldReceive('get')->andReturn(null);
|
||||
|
||||
$authCodeStorage = M::mock('League\OAuth2\Server\Storage\AuthCodeInterface');
|
||||
$authCodeStorage->shouldReceive('setServer');
|
||||
$authCodeStorage->shouldReceive('get')->andReturn(
|
||||
(new AuthCodeEntity($server))->setId('foobar')->setExpireTime(time() - 300)->setRedirectUri('http://foo/bar')
|
||||
);
|
||||
|
||||
$server->setClientStorage($clientStorage);
|
||||
$server->setScopeStorage($scopeStorage);
|
||||
$server->setSessionStorage($sessionStorage);
|
||||
$server->setAccessTokenStorage($accessTokenStorage);
|
||||
$server->setAuthCodeStorage($authCodeStorage);
|
||||
|
||||
$server->addGrantType($grant);
|
||||
$server->issueAccessToken();
|
||||
}
|
||||
|
||||
public function testCompleteFlowRedirectUriMismatch()
|
||||
{
|
||||
$this->setExpectedException('League\OAuth2\Server\Exception\InvalidRequestException');
|
||||
@ -484,7 +535,7 @@ class AuthCodeGrantTest extends \PHPUnit_Framework_TestCase
|
||||
$authCodeStorage = M::mock('League\OAuth2\Server\Storage\AuthCodeInterface');
|
||||
$authCodeStorage->shouldReceive('setServer');
|
||||
$authCodeStorage->shouldReceive('get')->andReturn(
|
||||
(new AuthCodeEntity($server))->setId('foobar')->setRedirectUri('http://fail/face')
|
||||
(new AuthCodeEntity($server))->setId('foobar')->setExpireTime(time() + 300)->setRedirectUri('http://fail/face')
|
||||
);
|
||||
|
||||
$server->setClientStorage($clientStorage);
|
||||
|
Loading…
Reference in New Issue
Block a user