Skip to content

Commit

Permalink
tests: Fix missing redirect uri test, add redirect uri mismatch test
Browse files Browse the repository at this point in the history
  • Loading branch information
lookyman committed Jul 8, 2016
1 parent 54422a2 commit 17b6e2a
Showing 1 changed file with 83 additions and 27 deletions.
110 changes: 83 additions & 27 deletions tests/Grant/AuthCodeGrantTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ public function testValidateAuthorizationRequest()
null,
null,
'php://input',
$headers = [],
$cookies = [],
$queryParams = [
[],
[],
[
'response_type' => 'code',
'client_id' => 'foo',
'redirect_uri' => 'http://foo/bar',
Expand Down Expand Up @@ -125,9 +125,9 @@ public function testValidateAuthorizationRequestRedirectUriArray()
null,
null,
'php://input',
$headers = [],
$cookies = [],
$queryParams = [
[],
[],
[
'response_type' => 'code',
'client_id' => 'foo',
'redirect_uri' => 'http://foo/bar',
Expand Down Expand Up @@ -159,9 +159,9 @@ public function testValidateAuthorizationRequestCodeChallenge()
null,
null,
'php://input',
$headers = [],
$cookies = [],
$queryParams = [
[],
[],
[
'response_type' => 'code',
'client_id' => 'foo',
'redirect_uri' => 'http://foo/bar',
Expand Down Expand Up @@ -260,9 +260,9 @@ public function testValidateAuthorizationRequestBadRedirectUriString()
null,
null,
'php://input',
$headers = [],
$cookies = [],
$queryParams = [
[],
[],
[
'response_type' => 'code',
'client_id' => 'foo',
'redirect_uri' => 'http://bar',
Expand Down Expand Up @@ -296,9 +296,9 @@ public function testValidateAuthorizationRequestBadRedirectUriArray()
null,
null,
'php://input',
$headers = [],
$cookies = [],
$queryParams = [
[],
[],
[
'response_type' => 'code',
'client_id' => 'foo',
'redirect_uri' => 'http://bar',
Expand Down Expand Up @@ -333,9 +333,9 @@ public function testValidateAuthorizationRequestMissingCodeChallenge()
null,
null,
'php://input',
$headers = [],
$cookies = [],
$queryParams = [
[],
[],
[
'response_type' => 'code',
'client_id' => 'foo',
'redirect_uri' => 'http://foo/bar',
Expand Down Expand Up @@ -370,9 +370,9 @@ public function testValidateAuthorizationRequestInvalidCodeChallengeMethod()
null,
null,
'php://input',
$headers = [],
$cookies = [],
$queryParams = [
[],
[],
[
'response_type' => 'code',
'client_id' => 'foo',
'redirect_uri' => 'http://foo/bar',
Expand Down Expand Up @@ -652,20 +652,65 @@ public function testRespondToAccessTokenRequestCodeChallengeS256()
*/
public function testRespondToAccessTokenRequestMissingRedirectUri()
{
$client = new ClientEntity();
$client->setIdentifier('foo');
$clientRepositoryMock = $this->getMockBuilder(ClientRepositoryInterface::class)->getMock();
$accessTokenRepositoryMock = $this->getMockBuilder(AccessTokenRepositoryInterface::class)->getMock();
$refreshTokenRepositoryMock = $this->getMockBuilder(RefreshTokenRepositoryInterface::class)->getMock();
$clientRepositoryMock->method('getClientEntity')->willReturn($client);

$grant = new AuthCodeGrant(
$this->getMockBuilder(AuthCodeRepositoryInterface::class)->getMock(),
$this->getMockBuilder(RefreshTokenRepositoryInterface::class)->getMock(),
new \DateInterval('PT10M')
);
$grant->setClientRepository($clientRepositoryMock);
$grant->setPublicKey(new CryptKey('file://' . __DIR__ . '/../Stubs/public.key'));

$request = new ServerRequest(
[],
[],
null,
'POST',
'php://input',
[],
[],
[],
[
'client_id' => 'foo',
'grant_type' => 'authorization_code',
'code' => $this->cryptStub->doEncrypt(
json_encode(
[
'auth_code_id' => uniqid(),
'expire_time' => time() + 3600,
'client_id' => 'foo',
'redirect_uri' => 'http://foo/bar',
]
)
),
]
);

$grant->respondToAccessTokenRequest($request, new StubResponseType(), new \DateInterval('PT10M'));
}

/**
* @expectedException \League\OAuth2\Server\Exception\OAuthServerException
* @expectedExceptionCode 3
*/
public function testRespondToAccessTokenRequestRedirectUriMismatch()
{
$client = new ClientEntity();
$client->setIdentifier('foo');
$clientRepositoryMock = $this->getMockBuilder(ClientRepositoryInterface::class)->getMock();
$clientRepositoryMock->method('getClientEntity')->willReturn($client);

$grant = new AuthCodeGrant(
$this->getMockBuilder(AuthCodeRepositoryInterface::class)->getMock(),
$this->getMockBuilder(RefreshTokenRepositoryInterface::class)->getMock(),
new \DateInterval('PT10M')
);
$grant->setClientRepository($clientRepositoryMock);
$grant->setAccessTokenRepository($accessTokenRepositoryMock);
$grant->setRefreshTokenRepository($refreshTokenRepositoryMock);
$grant->setPublicKey(new CryptKey('file://' . __DIR__ . '/../Stubs/public.key'));
$grant->setPrivateKey(new CryptKey('file://' . __DIR__ . '/../Stubs/private.key'));

$request = new ServerRequest(
[],
Expand All @@ -677,11 +722,22 @@ public function testRespondToAccessTokenRequestMissingRedirectUri()
[],
[],
[
'client_id' => 'foo',
'grant_type' => 'authorization_code',
'redirect_uri' => 'http://bar/foo',
'code' => $this->cryptStub->doEncrypt(
json_encode(
[
'auth_code_id' => uniqid(),
'expire_time' => time() + 3600,
'client_id' => 'foo',
'redirect_uri' => 'http://foo/bar',
]
)
),
]
);

/* @var StubResponseType $response */
$grant->respondToAccessTokenRequest($request, new StubResponseType(), new \DateInterval('PT10M'));
}

Expand Down

0 comments on commit 17b6e2a

Please sign in to comment.