@@ -289,6 +289,32 @@ public function testValidateClientBadClient(): void
289289 $ validateClientMethod ->invoke ($ grantMock , $ serverRequest , true );
290290 }
291291
292+ public function testUnauthorizedClient (): void
293+ {
294+ $ client = $ this ->getMockBuilder (ClientEntity::class)->getMock ();
295+ $ client ->method ('supportsGrantType ' )->willReturn (false );
296+
297+ $ clientRepositoryMock = $ this ->getMockBuilder (ClientRepositoryInterface::class)->getMock ();
298+ $ clientRepositoryMock
299+ ->expects (self ::once ())
300+ ->method ('getClientEntity ' )
301+ ->with ('foo ' )
302+ ->willReturn ($ client );
303+
304+ /** @var AbstractGrant $grantMock */
305+ $ grantMock = $ this ->getMockForAbstractClass (AbstractGrant::class);
306+ $ grantMock ->setClientRepository ($ clientRepositoryMock );
307+
308+ $ abstractGrantReflection = new ReflectionClass ($ grantMock );
309+
310+ $ getClientEntityOrFailMethod = $ abstractGrantReflection ->getMethod ('getClientEntityOrFail ' );
311+ $ getClientEntityOrFailMethod ->setAccessible (true );
312+
313+ $ this ->expectException (OAuthServerException::class);
314+
315+ $ getClientEntityOrFailMethod ->invoke ($ grantMock , 'foo ' , new ServerRequest ());
316+ }
317+
292318 public function testCanRespondToRequest (): void
293319 {
294320 $ grantMock = $ this ->getMockForAbstractClass (AbstractGrant::class);
@@ -350,6 +376,33 @@ public function testIssueNullRefreshToken(): void
350376 self ::assertNull ($ issueRefreshTokenMethod ->invoke ($ grantMock , $ accessToken ));
351377 }
352378
379+ public function testIssueNullRefreshTokenUnauthorizedClient (): void
380+ {
381+ $ client = $ this ->getMockBuilder (ClientEntity::class)->getMock ();
382+ $ client
383+ ->expects (self ::once ())
384+ ->method ('supportsGrantType ' )
385+ ->with ('refresh_token ' )
386+ ->willReturn (false );
387+
388+ $ refreshTokenRepoMock = $ this ->getMockBuilder (RefreshTokenRepositoryInterface::class)->getMock ();
389+ $ refreshTokenRepoMock ->expects (self ::never ())->method ('getNewRefreshToken ' );
390+
391+ /** @var AbstractGrant $grantMock */
392+ $ grantMock = $ this ->getMockForAbstractClass (AbstractGrant::class);
393+ $ grantMock ->setRefreshTokenTTL (new DateInterval ('PT1M ' ));
394+ $ grantMock ->setRefreshTokenRepository ($ refreshTokenRepoMock );
395+
396+ $ abstractGrantReflection = new ReflectionClass ($ grantMock );
397+ $ issueRefreshTokenMethod = $ abstractGrantReflection ->getMethod ('issueRefreshToken ' );
398+ $ issueRefreshTokenMethod ->setAccessible (true );
399+
400+ $ accessToken = new AccessTokenEntity ();
401+ $ accessToken ->setClient ($ client );
402+
403+ self ::assertNull ($ issueRefreshTokenMethod ->invoke ($ grantMock , $ accessToken ));
404+ }
405+
353406 public function testIssueAccessToken (): void
354407 {
355408 $ accessTokenRepoMock = $ this ->getMockBuilder (AccessTokenRepositoryInterface::class)->getMock ();
0 commit comments