@@ -265,84 +265,6 @@ public function testValidateClientInvalidClientSecret(): void
265
265
$ validateClientMethod ->invoke ($ grantMock , $ serverRequest , true , true );
266
266
}
267
267
268
- public function testValidateClientInvalidRedirectUri (): void
269
- {
270
- $ client = new ClientEntity ();
271
- $ client ->setRedirectUri ('http://foo/bar ' );
272
- $ clientRepositoryMock = $ this ->getMockBuilder (ClientRepositoryInterface::class)->getMock ();
273
- $ clientRepositoryMock ->method ('getClientEntity ' )->willReturn ($ client );
274
-
275
- /** @var AbstractGrant $grantMock */
276
- $ grantMock = $ this ->getMockForAbstractClass (AbstractGrant::class);
277
- $ grantMock ->setClientRepository ($ clientRepositoryMock );
278
-
279
- $ abstractGrantReflection = new ReflectionClass ($ grantMock );
280
-
281
- $ serverRequest = (new ServerRequest ())->withParsedBody ([
282
- 'client_id ' => 'foo ' ,
283
- 'redirect_uri ' => 'http://bar/foo ' ,
284
- ]);
285
-
286
- $ validateClientMethod = $ abstractGrantReflection ->getMethod ('validateClient ' );
287
- $ validateClientMethod ->setAccessible (true );
288
-
289
- $ this ->expectException (OAuthServerException::class);
290
-
291
- $ validateClientMethod ->invoke ($ grantMock , $ serverRequest , true , true );
292
- }
293
-
294
- public function testValidateClientInvalidRedirectUriArray (): void
295
- {
296
- $ client = new ClientEntity ();
297
- $ client ->setRedirectUri (['http://foo/bar ' ]);
298
- $ clientRepositoryMock = $ this ->getMockBuilder (ClientRepositoryInterface::class)->getMock ();
299
- $ clientRepositoryMock ->method ('getClientEntity ' )->willReturn ($ client );
300
-
301
- /** @var AbstractGrant $grantMock */
302
- $ grantMock = $ this ->getMockForAbstractClass (AbstractGrant::class);
303
- $ grantMock ->setClientRepository ($ clientRepositoryMock );
304
-
305
- $ abstractGrantReflection = new ReflectionClass ($ grantMock );
306
-
307
- $ serverRequest = (new ServerRequest ())->withParsedBody ([
308
- 'client_id ' => 'foo ' ,
309
- 'redirect_uri ' => 'http://bar/foo ' ,
310
- ]);
311
-
312
- $ validateClientMethod = $ abstractGrantReflection ->getMethod ('validateClient ' );
313
- $ validateClientMethod ->setAccessible (true );
314
-
315
- $ this ->expectException (OAuthServerException::class);
316
-
317
- $ validateClientMethod ->invoke ($ grantMock , $ serverRequest , true , true );
318
- }
319
-
320
- public function testValidateClientMalformedRedirectUri (): void
321
- {
322
- $ client = new ClientEntity ();
323
- $ client ->setRedirectUri ('http://foo/bar ' );
324
- $ clientRepositoryMock = $ this ->getMockBuilder (ClientRepositoryInterface::class)->getMock ();
325
- $ clientRepositoryMock ->method ('getClientEntity ' )->willReturn ($ client );
326
-
327
- /** @var AbstractGrant $grantMock */
328
- $ grantMock = $ this ->getMockForAbstractClass (AbstractGrant::class);
329
- $ grantMock ->setClientRepository ($ clientRepositoryMock );
330
-
331
- $ abstractGrantReflection = new ReflectionClass ($ grantMock );
332
-
333
- $ serverRequest = (new ServerRequest ())->withParsedBody ([
334
- 'client_id ' => 'foo ' ,
335
- 'redirect_uri ' => ['not ' , 'a ' , 'string ' ],
336
- ]);
337
-
338
- $ validateClientMethod = $ abstractGrantReflection ->getMethod ('validateClient ' );
339
- $ validateClientMethod ->setAccessible (true );
340
-
341
- $ this ->expectException (OAuthServerException::class);
342
-
343
- $ validateClientMethod ->invoke ($ grantMock , $ serverRequest , true , true );
344
- }
345
-
346
268
public function testValidateClientBadClient (): void
347
269
{
348
270
$ clientRepositoryMock = $ this ->getMockBuilder (ClientRepositoryInterface::class)->getMock ();
@@ -398,6 +320,7 @@ public function testIssueRefreshToken(): void
398
320
$ issueRefreshTokenMethod ->setAccessible (true );
399
321
400
322
$ accessToken = new AccessTokenEntity ();
323
+ $ accessToken ->setClient (new ClientEntity ());
401
324
402
325
/** @var RefreshTokenEntityInterface $refreshToken */
403
326
$ refreshToken = $ issueRefreshTokenMethod ->invoke ($ grantMock , $ accessToken );
@@ -423,6 +346,34 @@ public function testIssueNullRefreshToken(): void
423
346
$ issueRefreshTokenMethod ->setAccessible (true );
424
347
425
348
$ accessToken = new AccessTokenEntity ();
349
+ $ accessToken ->setClient (new ClientEntity ());
350
+ self ::assertNull ($ issueRefreshTokenMethod ->invoke ($ grantMock , $ accessToken ));
351
+ }
352
+
353
+ public function testIssueNullRefreshTokenUnauthorizedClient (): void
354
+ {
355
+ $ client = $ this ->getMockBuilder (ClientEntity::class)->getMock ();
356
+ $ client
357
+ ->expects (self ::once ())
358
+ ->method ('supportsGrantType ' )
359
+ ->with ('refresh_token ' )
360
+ ->willReturn (false );
361
+
362
+ $ refreshTokenRepoMock = $ this ->getMockBuilder (RefreshTokenRepositoryInterface::class)->getMock ();
363
+ $ refreshTokenRepoMock ->expects (self ::never ())->method ('getNewRefreshToken ' );
364
+
365
+ /** @var AbstractGrant $grantMock */
366
+ $ grantMock = $ this ->getMockForAbstractClass (AbstractGrant::class);
367
+ $ grantMock ->setRefreshTokenTTL (new DateInterval ('PT1M ' ));
368
+ $ grantMock ->setRefreshTokenRepository ($ refreshTokenRepoMock );
369
+
370
+ $ abstractGrantReflection = new ReflectionClass ($ grantMock );
371
+ $ issueRefreshTokenMethod = $ abstractGrantReflection ->getMethod ('issueRefreshToken ' );
372
+ $ issueRefreshTokenMethod ->setAccessible (true );
373
+
374
+ $ accessToken = new AccessTokenEntity ();
375
+ $ accessToken ->setClient ($ client );
376
+
426
377
self ::assertNull ($ issueRefreshTokenMethod ->invoke ($ grantMock , $ accessToken ));
427
378
}
428
379
@@ -576,4 +527,30 @@ public function testCompleteAuthorizationRequest(): void
576
527
577
528
$ grantMock ->completeAuthorizationRequest (new AuthorizationRequest ());
578
529
}
530
+
531
+ public function testUnauthorizedClient (): void
532
+ {
533
+ $ client = $ this ->getMockBuilder (ClientEntity::class)->getMock ();
534
+ $ client ->method ('supportsGrantType ' )->willReturn (false );
535
+
536
+ $ clientRepositoryMock = $ this ->getMockBuilder (ClientRepositoryInterface::class)->getMock ();
537
+ $ clientRepositoryMock
538
+ ->expects (self ::once ())
539
+ ->method ('getClientEntity ' )
540
+ ->with ('foo ' )
541
+ ->willReturn ($ client );
542
+
543
+ /** @var AbstractGrant $grantMock */
544
+ $ grantMock = $ this ->getMockForAbstractClass (AbstractGrant::class);
545
+ $ grantMock ->setClientRepository ($ clientRepositoryMock );
546
+
547
+ $ abstractGrantReflection = new ReflectionClass ($ grantMock );
548
+
549
+ $ getClientEntityOrFailMethod = $ abstractGrantReflection ->getMethod ('getClientEntityOrFail ' );
550
+ $ getClientEntityOrFailMethod ->setAccessible (true );
551
+
552
+ $ this ->expectException (OAuthServerException::class);
553
+
554
+ $ getClientEntityOrFailMethod ->invoke ($ grantMock , 'foo ' , new ServerRequest ());
555
+ }
579
556
}
0 commit comments