From 7df0dfff9d8dafbadbef619787b935b2eaf4e525 Mon Sep 17 00:00:00 2001 From: Andrew Millington Date: Sun, 24 Jun 2018 13:31:38 +0100 Subject: [PATCH 1/5] Remove double function calls --- src/Grant/AbstractGrant.php | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/Grant/AbstractGrant.php b/src/Grant/AbstractGrant.php index d020c6ad..ed05dfac 100644 --- a/src/Grant/AbstractGrant.php +++ b/src/Grant/AbstractGrant.php @@ -358,15 +358,9 @@ abstract class AbstractGrant implements GrantTypeInterface $maxGenerationAttempts = self::MAX_RANDOM_TOKEN_GENERATION_ATTEMPTS; $accessToken = $this->accessTokenRepository->getNewToken($client, $scopes, $userIdentifier); - $accessToken->setClient($client); - $accessToken->setUserIdentifier($userIdentifier); $accessToken->setExpiryDateTime((new \DateTime())->add($accessTokenTTL)); $accessToken->setPrivateKey($this->privateKey); - foreach ($scopes as $scope) { - $accessToken->addScope($scope); - } - while ($maxGenerationAttempts-- > 0) { $accessToken->setIdentifier($this->generateUniqueIdentifier()); try { From dad3b1e1c92701c916cf644e159ebdbeb872f0a1 Mon Sep 17 00:00:00 2001 From: Andrew Millington Date: Sun, 24 Jun 2018 13:32:49 +0100 Subject: [PATCH 2/5] Remove unused test --- tests/Grant/AbstractGrantTest.php | 8 -------- 1 file changed, 8 deletions(-) diff --git a/tests/Grant/AbstractGrantTest.php b/tests/Grant/AbstractGrantTest.php index a5916de7..64fde4f0 100644 --- a/tests/Grant/AbstractGrantTest.php +++ b/tests/Grant/AbstractGrantTest.php @@ -2,7 +2,6 @@ namespace LeagueTests\Grant; -use League\Event\Emitter; use League\OAuth2\Server\CryptKey; use League\OAuth2\Server\Entities\AccessTokenEntityInterface; use League\OAuth2\Server\Entities\AuthCodeEntityInterface; @@ -24,13 +23,6 @@ use Zend\Diactoros\ServerRequest; class AbstractGrantTest extends TestCase { - public function testGetSet() - { - /** @var AbstractGrant $grantMock */ - $grantMock = $this->getMockForAbstractClass(AbstractGrant::class); - $grantMock->setEmitter(new Emitter()); - } - public function testHttpBasicWithPassword() { /** @var AbstractGrant $grantMock */ From 574299d862b1dce56e840deeda23d307de0f2695 Mon Sep 17 00:00:00 2001 From: Andrew Millington Date: Sun, 24 Jun 2018 13:38:55 +0100 Subject: [PATCH 3/5] Fix tests --- tests/Grant/ImplicitGrantTest.php | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/tests/Grant/ImplicitGrantTest.php b/tests/Grant/ImplicitGrantTest.php index 0080548f..df7b6985 100644 --- a/tests/Grant/ImplicitGrantTest.php +++ b/tests/Grant/ImplicitGrantTest.php @@ -276,14 +276,20 @@ class ImplicitGrantTest extends TestCase public function testCompleteAuthorizationRequest() { + $client = new ClientEntity(); + $client->setIdentifier('identifier'); + $authRequest = new AuthorizationRequest(); $authRequest->setAuthorizationApproved(true); - $authRequest->setClient(new ClientEntity()); + $authRequest->setClient($client); $authRequest->setGrantTypeId('authorization_code'); $authRequest->setUser(new UserEntity()); + $accessToken = new AccessTokenEntity(); + $accessToken->setClient($client); + $accessTokenRepositoryMock = $this->getMockBuilder(AccessTokenRepositoryInterface::class)->getMock(); - $accessTokenRepositoryMock->method('getNewToken')->willReturn(new AccessTokenEntity()); + $accessTokenRepositoryMock->method('getNewToken')->willReturn($accessToken); $accessTokenRepositoryMock->method('persistNewAccessToken')->willReturnSelf(); $grant = new ImplicitGrant(new \DateInterval('PT10M')); @@ -318,15 +324,21 @@ class ImplicitGrantTest extends TestCase public function testAccessTokenRepositoryUniqueConstraintCheck() { + $client = new ClientEntity(); + $client->setIdentifier('identifier'); + $authRequest = new AuthorizationRequest(); $authRequest->setAuthorizationApproved(true); - $authRequest->setClient(new ClientEntity()); + $authRequest->setClient($client); $authRequest->setGrantTypeId('authorization_code'); $authRequest->setUser(new UserEntity()); + $accessToken = new AccessTokenEntity(); + $accessToken->setClient($client); + /** @var AccessTokenRepositoryInterface|\PHPUnit_Framework_MockObject_MockObject $accessTokenRepositoryMock */ $accessTokenRepositoryMock = $this->getMockBuilder(AccessTokenRepositoryInterface::class)->getMock(); - $accessTokenRepositoryMock->method('getNewToken')->willReturn(new AccessTokenEntity()); + $accessTokenRepositoryMock->method('getNewToken')->willReturn($accessToken); $accessTokenRepositoryMock->expects($this->at(0))->method('persistNewAccessToken')->willThrowException(UniqueTokenIdentifierConstraintViolationException::create()); $accessTokenRepositoryMock->expects($this->at(1))->method('persistNewAccessToken')->willReturnSelf(); From 2fcee76d1376df270b0d43580dff688186ca037a Mon Sep 17 00:00:00 2001 From: Andrew Millington Date: Sun, 24 Jun 2018 13:39:40 +0100 Subject: [PATCH 4/5] Remove unused stub function --- tests/Stubs/ClientEntity.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/tests/Stubs/ClientEntity.php b/tests/Stubs/ClientEntity.php index 0c6a4f9b..4cb79a0c 100644 --- a/tests/Stubs/ClientEntity.php +++ b/tests/Stubs/ClientEntity.php @@ -14,9 +14,4 @@ class ClientEntity implements ClientEntityInterface { $this->redirectUri = $uri; } - - public function setName($name) - { - $this->name = $name; - } } From 0cdd535f7db3204058a1f854c7959daecf566019 Mon Sep 17 00:00:00 2001 From: Andrew Millington Date: Sun, 24 Jun 2018 13:48:52 +0100 Subject: [PATCH 5/5] Add changes to changelog --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cfdfbcad..88d8f16f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ### Changed - Replace `convertToJWT()` interface with a more generic `__toString()` to improve extensibility (PR #874) -- The `invalidClient()` function accepts a PSR-7 compliant `$serverRequest` argument to avoid accessing the `$_SERVER` global variable and improve testing (PR #899) +- The `invalidClient()` function accepts a PSR-7 compliant `$serverRequest` argument to avoid accessing the `$_SERVER` global variable and improve testing (PR #899) +- `issueAccessToken()` in the Abstract Grant no longer sets access token client, user ID or scopes. These values should already have been set when calling `getNewToken()` (PR #919) ## [7.1.1] - released 2018-05-21