|
5 | 5 | namespace LeagueTests\Grant;
|
6 | 6 |
|
7 | 7 | use DateInterval;
|
| 8 | +use Laminas\Diactoros\Response; |
8 | 9 | use Laminas\Diactoros\ServerRequest;
|
9 | 10 | use League\OAuth2\Server\CryptKey;
|
10 | 11 | use League\OAuth2\Server\Entities\RefreshTokenEntityInterface;
|
|
14 | 15 | use League\OAuth2\Server\Repositories\ClientRepositoryInterface;
|
15 | 16 | use League\OAuth2\Server\Repositories\RefreshTokenRepositoryInterface;
|
16 | 17 | use League\OAuth2\Server\Repositories\ScopeRepositoryInterface;
|
| 18 | +use League\OAuth2\Server\ResponseTypes\BearerTokenResponse; |
17 | 19 | use LeagueTests\Stubs\AccessTokenEntity;
|
18 | 20 | use LeagueTests\Stubs\ClientEntity;
|
19 | 21 | use LeagueTests\Stubs\CryptTraitStub;
|
@@ -688,11 +690,15 @@ public function testUnrevokedRefreshToken(): void
|
688 | 690 | $scopeRepositoryMock->method('getScopeEntityByIdentifier')->willReturn($scopeEntity);
|
689 | 691 | $scopeRepositoryMock->method('finalizeScopes')->willReturn([$scopeEntity]);
|
690 | 692 |
|
| 693 | + $accessTokenEntity = new AccessTokenEntity(); |
| 694 | + $accessTokenEntity->setClient($client); |
| 695 | + |
691 | 696 | $accessTokenRepositoryMock = $this->getMockBuilder(AccessTokenRepositoryInterface::class)->getMock();
|
692 |
| - $accessTokenRepositoryMock->method('getNewToken')->willReturn(new AccessTokenEntity()); |
| 697 | + $accessTokenRepositoryMock->method('getNewToken')->willReturn($accessTokenEntity); |
693 | 698 | $accessTokenRepositoryMock->expects(self::once())->method('persistNewAccessToken')->willReturnSelf();
|
694 | 699 |
|
695 | 700 | $refreshTokenRepositoryMock = $this->getMockBuilder(RefreshTokenRepositoryInterface::class)->getMock();
|
| 701 | + $refreshTokenRepositoryMock->method('getNewRefreshToken')->willReturn(new RefreshTokenEntity()); |
696 | 702 | $refreshTokenRepositoryMock->method('isRefreshTokenRevoked')->willReturn(false);
|
697 | 703 | $refreshTokenRepositoryMock->expects(self::never())->method('revokeRefreshToken');
|
698 | 704 |
|
@@ -727,11 +733,22 @@ public function testUnrevokedRefreshToken(): void
|
727 | 733 | $grant->setScopeRepository($scopeRepositoryMock);
|
728 | 734 | $grant->setAccessTokenRepository($accessTokenRepositoryMock);
|
729 | 735 | $grant->setEncryptionKey($this->cryptStub->getKey());
|
730 |
| - $grant->setPrivateKey(new CryptKey('file://' . __DIR__ . '/../Stubs/private.key')); |
| 736 | + $grant->setPrivateKey($privateKey = new CryptKey('file://' . __DIR__ . '/../Stubs/private.key')); |
731 | 737 | $grant->revokeRefreshTokens(false);
|
732 | 738 |
|
733 |
| - $grant->respondToAccessTokenRequest($serverRequest, new StubResponseType(), new DateInterval('PT5M')); |
| 739 | + $responseType = new BearerTokenResponse(); |
| 740 | + $responseType->setPrivateKey($privateKey); |
| 741 | + $responseType->setEncryptionKey($this->cryptStub->getKey()); |
| 742 | + |
| 743 | + $response = $grant->respondToAccessTokenRequest($serverRequest, $responseType, new DateInterval('PT5M')) |
| 744 | + ->generateHttpResponse(new Response()); |
| 745 | + |
| 746 | + $json = json_decode((string) $response->getBody()); |
734 | 747 |
|
735 | 748 | self::assertFalse($refreshTokenRepositoryMock->isRefreshTokenRevoked($refreshTokenId));
|
| 749 | + self::assertEquals('Bearer', $json->token_type); |
| 750 | + self::assertObjectHasProperty('expires_in', $json); |
| 751 | + self::assertObjectHasProperty('access_token', $json); |
| 752 | + self::assertObjectHasProperty('refresh_token', $json); |
736 | 753 | }
|
737 | 754 | }
|
0 commit comments