1313use OCA \DAV \DAV \Security \RateLimiting ;
1414use OCP \IAppConfig ;
1515use OCP \IUser ;
16- use OCP \IUserManager ;
16+ use OCP \IUserSession ;
1717use OCP \Security \RateLimiting \ILimiter ;
1818use OCP \Security \RateLimiting \IRateLimitExceededException ;
1919use PHPUnit \Framework \MockObject \MockObject ;
2020use Test \TestCase ;
2121
2222class RateLimitingTest extends TestCase {
23- private ILimiter &MockObject $ limiter ;
24- private IUserManager &MockObject $ userManager ;
23+ private IUserSession $ userSession ;
2524 private IAppConfig &MockObject $ config ;
25+ private ILimiter &MockObject $ limiter ;
2626 private RateLimiting $ rateLimiting ;
2727 private string $ userId = 'user123 ' ;
2828
2929 protected function setUp (): void {
3030 parent ::setUp ();
3131
32- $ this ->limiter = $ this ->createMock (ILimiter::class);
33- $ this ->userManager = $ this ->createMock (IUserManager::class);
32+ $ this ->userSession = $ this ->createMock (IUserSession::class);
3433 $ this ->config = $ this ->createMock (IAppConfig::class);
34+ $ this ->limiter = $ this ->createMock (ILimiter::class);
35+
3536 $ this ->rateLimiting = new RateLimiting (
36- $ this ->limiter ,
37- $ this ->userManager ,
37+ $ this ->userSession ,
3838 $ this ->config ,
39- $ this ->userId ,
39+ $ this ->limiter ,
4040 );
4141 }
4242
4343 public function testNoUserObject (): void {
44- $ this ->userManager ->expects (self ::once ())
45- ->method ('get ' )
46- ->with ($ this ->userId )
44+ $ this ->userSession ->expects ($ this ->once ())
45+ ->method ('getUser ' )
4746 ->willReturn (null );
48- $ this ->limiter ->expects (self :: never ())
47+ $ this ->limiter ->expects ($ this -> never ())
4948 ->method ('registerUserRequest ' );
5049
5150 $ this ->rateLimiting ->check ();
5251 }
5352
5453 public function testRegisterShareRequest (): void {
5554 $ user = $ this ->createMock (IUser::class);
56- $ this ->userManager ->expects (self ::once ())
57- ->method ('get ' )
58- ->with ($ this ->userId )
55+ $ this ->userSession ->expects ($ this ->once ())
56+ ->method ('getUser ' )
5957 ->willReturn ($ user );
6058 $ this ->config ->method ('getValueInt ' )
6159 ->willReturnCallback (static function (string $ app , string $ key , int $ default ): int {
@@ -65,7 +63,7 @@ public function testRegisterShareRequest(): void {
6563 default => $ default ,
6664 };
6765 });
68- $ this ->limiter ->expects (self :: once ())
66+ $ this ->limiter ->expects ($ this -> once ())
6967 ->method ('registerUserRequest ' )
7068 ->with (
7169 'share-addressbook-or-calendar ' ,
@@ -79,13 +77,12 @@ public function testRegisterShareRequest(): void {
7977
8078 public function testShareRequestRateLimitExceeded (): void {
8179 $ user = $ this ->createMock (IUser::class);
82- $ this ->userManager ->expects (self ::once ())
83- ->method ('get ' )
84- ->with ($ this ->userId )
80+ $ this ->userSession ->expects ($ this ->once ())
81+ ->method ('getUser ' )
8582 ->willReturn ($ user );
8683 $ this ->config ->method ('getValueInt ' )
8784 ->willReturnArgument (2 );
88- $ this ->limiter ->expects (self :: once ())
85+ $ this ->limiter ->expects ($ this -> once ())
8986 ->method ('registerUserRequest ' )
9087 ->with (
9188 'share-addressbook-or-calendar ' ,
0 commit comments