2222namespace OCA \OAuth2 \Tests \Controller ;
2323
2424use OC \Authentication \Exceptions \InvalidTokenException ;
25+ use OC \Authentication \Exceptions \ExpiredTokenException ;
2526use OC \Authentication \Token \DefaultToken ;
26- use OC \Authentication \Token \DefaultTokenMapper ;
27- use OC \Authentication \Token \ExpiredTokenException ;
2827use OC \Authentication \Token \IProvider as TokenProvider ;
29- use OC \Authentication \ Token \ IToken ;
28+ use OC \Security \ Bruteforce \ Throttler ;
3029use OCA \OAuth2 \Controller \OauthApiController ;
3130use OCA \OAuth2 \Db \AccessToken ;
3231use OCA \OAuth2 \Db \AccessTokenMapper ;
@@ -57,6 +56,8 @@ class OauthApiControllerTest extends TestCase {
5756 private $ secureRandom ;
5857 /** @var ITimeFactory|\PHPUnit_Framework_MockObject_MockObject */
5958 private $ time ;
59+ /** @var Throttler|\PHPUnit_Framework_MockObject_MockObject */
60+ private $ throttler ;
6061 /** @var OauthApiController */
6162 private $ oauthApiController ;
6263
@@ -70,6 +71,7 @@ public function setUp() {
7071 $ this ->tokenProvider = $ this ->createMock (TokenProvider::class);
7172 $ this ->secureRandom = $ this ->createMock (ISecureRandom::class);
7273 $ this ->time = $ this ->createMock (ITimeFactory::class);
74+ $ this ->throttler = $ this ->createMock (Throttler::class);
7375
7476 $ this ->oauthApiController = new OauthApiController (
7577 'oauth2 ' ,
@@ -79,7 +81,8 @@ public function setUp() {
7981 $ this ->clientMapper ,
8082 $ this ->tokenProvider ,
8183 $ this ->secureRandom ,
82- $ this ->time
84+ $ this ->time ,
85+ $ this ->throttler
8386 );
8487 }
8588
@@ -286,6 +289,17 @@ public function testGetTokenValidAppToken() {
286289 'user_id ' => 'userId ' ,
287290 ]);
288291
292+ $ this ->request ->method ('getRemoteAddress ' )
293+ ->willReturn ('1.2.3.4 ' );
294+
295+ $ this ->throttler ->expects ($ this ->once ())
296+ ->method ('resetDelay ' )
297+ ->with (
298+ '1.2.3.4 ' ,
299+ 'login ' ,
300+ ['user ' => 'userId ' ]
301+ );
302+
289303 $ this ->assertEquals ($ expected , $ this ->oauthApiController ->getToken ('refresh_token ' , null , 'validrefresh ' , 'clientId ' , 'clientSecret ' ));
290304 }
291305
@@ -370,6 +384,17 @@ public function testGetTokenValidAppTokenBasicAuth() {
370384 $ this ->request ->server ['PHP_AUTH_USER ' ] = 'clientId ' ;
371385 $ this ->request ->server ['PHP_AUTH_PW ' ] = 'clientSecret ' ;
372386
387+ $ this ->request ->method ('getRemoteAddress ' )
388+ ->willReturn ('1.2.3.4 ' );
389+
390+ $ this ->throttler ->expects ($ this ->once ())
391+ ->method ('resetDelay ' )
392+ ->with (
393+ '1.2.3.4 ' ,
394+ 'login ' ,
395+ ['user ' => 'userId ' ]
396+ );
397+
373398 $ this ->assertEquals ($ expected , $ this ->oauthApiController ->getToken ('refresh_token ' , null , 'validrefresh ' , null , null ));
374399 }
375400
@@ -451,6 +476,17 @@ public function testGetTokenExpiredAppToken() {
451476 'user_id ' => 'userId ' ,
452477 ]);
453478
479+ $ this ->request ->method ('getRemoteAddress ' )
480+ ->willReturn ('1.2.3.4 ' );
481+
482+ $ this ->throttler ->expects ($ this ->once ())
483+ ->method ('resetDelay ' )
484+ ->with (
485+ '1.2.3.4 ' ,
486+ 'login ' ,
487+ ['user ' => 'userId ' ]
488+ );
489+
454490 $ this ->assertEquals ($ expected , $ this ->oauthApiController ->getToken ('refresh_token ' , null , 'validrefresh ' , 'clientId ' , 'clientSecret ' ));
455491 }
456492}
0 commit comments