99namespace OCA \Provisioning_API \Tests \Controller ;
1010
1111use Exception ;
12+ use OC \Authentication \Token \Invalidator ;
1213use OC \Authentication \Token \RemoteWipe ;
1314use OC \Group \Manager ;
1415use OC \KnownUser \KnownUserService ;
@@ -73,6 +74,8 @@ class UsersControllerTest extends TestCase {
7374 /** @var RemoteWipe|MockObject */
7475 private $ remoteWipe ;
7576 /** @var KnownUserService|MockObject */
77+ private $ invalidator ;
78+ /** @var KnownUserService|MockObject */
7679 private $ knownUserService ;
7780 /** @var IEventDispatcher|MockObject */
7881 private $ eventDispatcher ;
@@ -95,6 +98,7 @@ protected function setUp(): void {
9598 $ this ->newUserMailHelper = $ this ->createMock (NewUserMailHelper::class);
9699 $ this ->secureRandom = $ this ->createMock (ISecureRandom::class);
97100 $ this ->remoteWipe = $ this ->createMock (RemoteWipe::class);
101+ $ this ->invalidator = $ this ->createMock (Invalidator::class);
98102 $ this ->knownUserService = $ this ->createMock (KnownUserService::class);
99103 $ this ->eventDispatcher = $ this ->createMock (IEventDispatcher::class);
100104 $ this ->phoneNumberUtil = new PhoneNumberUtil ();
@@ -119,6 +123,7 @@ protected function setUp(): void {
119123 $ this ->newUserMailHelper ,
120124 $ this ->secureRandom ,
121125 $ this ->remoteWipe ,
126+ $ this ->invalidator ,
122127 $ this ->knownUserService ,
123128 $ this ->eventDispatcher ,
124129 $ this ->phoneNumberUtil ,
@@ -513,6 +518,7 @@ public function testAddUserSuccessfulWithDisplayName() {
513518 $ this ->newUserMailHelper ,
514519 $ this ->secureRandom ,
515520 $ this ->remoteWipe ,
521+ $ this ->invalidator ,
516522 $ this ->knownUserService ,
517523 $ this ->eventDispatcher ,
518524 $ this ->phoneNumberUtil ,
@@ -3133,6 +3139,34 @@ public function testRemoveFromGroupWithNoTargetGroup() {
31333139 $ this ->api ->removeFromGroup ('TargetUser ' , '' );
31343140 }
31353141
3142+ public function testInvalidateUserTokensSuccess (): void {
3143+ $ currentUser = $ this ->createMock (IUser::class);
3144+ $ targetUser = $ this ->createMock (IUser::class);
3145+
3146+ $ this ->userSession ->method ('getUser ' )->willReturn ($ currentUser );
3147+ $ currentUser ->method ('getUID ' )->willReturn ('currentUserId ' );
3148+ $ targetUser ->method ('getUID ' )->willReturn ('targetUserId ' );
3149+
3150+ $ this ->userManager ->method ('get ' )->with ('targetUserId ' )->willReturn ($ targetUser );
3151+
3152+ $ this ->groupManager ->method ('isAdmin ' )->with ('currentUserId ' )->willReturn (true );
3153+
3154+ $ this ->invalidator ->expects ($ this ->once ())->method ('invalidateAllUserTokens ' )->with ('targetUserId ' );
3155+
3156+ $ this ->logger
3157+ ->expects ($ this ->once ())
3158+ ->method ('warning ' )
3159+ ->with ('Invalidating all tokens for user targetUserId by user currentUserId ' , [
3160+ 'app ' => 'ocs_api ' ,
3161+ 'adminUserId ' => 'currentUserId ' ,
3162+ 'accountId ' => 'targetUserId ' ,
3163+ ]);
3164+
3165+ $ response = $ this ->api ->invalidateUserTokens ('targetUserId ' );
3166+
3167+ $ this ->assertInstanceOf (DataResponse::class, $ response );
3168+ $ this ->assertEquals ([], $ response ->getData ());
3169+ }
31363170
31373171 public function testRemoveFromGroupWithEmptyTargetGroup () {
31383172 $ this ->expectException (\OCP \AppFramework \OCS \OCSException::class);
@@ -3785,6 +3819,7 @@ public function testGetCurrentUserLoggedIn() {
37853819 $ this ->newUserMailHelper ,
37863820 $ this ->secureRandom ,
37873821 $ this ->remoteWipe ,
3822+ $ this ->invalidator ,
37883823 $ this ->knownUserService ,
37893824 $ this ->eventDispatcher ,
37903825 $ this ->phoneNumberUtil ,
@@ -3873,6 +3908,7 @@ public function testGetUser() {
38733908 $ this ->newUserMailHelper ,
38743909 $ this ->secureRandom ,
38753910 $ this ->remoteWipe ,
3911+ $ this ->invalidator ,
38763912 $ this ->knownUserService ,
38773913 $ this ->eventDispatcher ,
38783914 $ this ->phoneNumberUtil ,
0 commit comments