Updated unit tests

This commit is contained in:
Alex Bilbie 2014-11-08 17:16:17 +00:00
parent 7dc5a8090f
commit 583c21e7db
2 changed files with 61 additions and 1 deletions

View File

@ -22,4 +22,13 @@ class OAuthExceptionTest extends \PHPUnit_Framework_TestCase
$exception->httpStatusCode = 501; $exception->httpStatusCode = 501;
$this->assertSame($exception->getHttpHeaders(), ['HTTP/1.1 501 Not Implemented']); $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());
}
} }

View File

@ -446,6 +446,57 @@ class AuthCodeGrantTest extends \PHPUnit_Framework_TestCase
$server->issueAccessToken(); $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() public function testCompleteFlowRedirectUriMismatch()
{ {
$this->setExpectedException('League\OAuth2\Server\Exception\InvalidRequestException'); $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 = M::mock('League\OAuth2\Server\Storage\AuthCodeInterface');
$authCodeStorage->shouldReceive('setServer'); $authCodeStorage->shouldReceive('setServer');
$authCodeStorage->shouldReceive('get')->andReturn( $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); $server->setClientStorage($clientStorage);