]> source.dussan.org Git - nextcloud-server.git/commitdiff
unit tests for Manager::invalidateTokensOfUser
authorArtur Neumann <artur@jankaritech.com>
Tue, 22 Nov 2022 06:43:35 +0000 (12:28 +0545)
committerCôme Chilliet <come.chilliet@nextcloud.com>
Tue, 14 Mar 2023 16:13:30 +0000 (17:13 +0100)
Signed-off-by: Artur Neumann <artur@jankaritech.com>
tests/lib/Authentication/Token/ManagerTest.php

index 5f024bb1d43c028625a1350b8dd4375d530abc39..de3e5e1c3620294ec4fbb44cc137cecc2256fd32 100644 (file)
@@ -355,4 +355,48 @@ class ManagerTest extends TestCase {
 
                $this->manager->updatePasswords('uid', 'pass');
        }
+
+       public function testInvalidateTokensOfUserNoClientName() {
+               $t1 = new PublicKeyToken();
+               $t2 = new PublicKeyToken();
+               $t1->setId(123);
+               $t2->setId(456);
+
+               $this->publicKeyTokenProvider
+                       ->expects($this->once())
+                       ->method('getTokenByUser')
+                       ->with('theUser')
+                       ->willReturn([$t1, $t2]);
+               $this->publicKeyTokenProvider
+                       ->expects($this->exactly(2))
+                       ->method('invalidateTokenById')
+                       ->withConsecutive(
+                               ['theUser', 123],
+                               ['theUser', 456],
+                       );
+               $this->manager->invalidateTokensOfUser('theUser', null);
+       }
+
+       public function testInvalidateTokensOfUserClientNameGiven() {
+               $t1 = new PublicKeyToken();
+               $t2 = new PublicKeyToken();
+               $t3 = new PublicKeyToken();
+               $t1->setId(123);
+               $t1->setName('Firefox session');
+               $t2->setId(456);
+               $t2->setName('My Client Name');
+               $t3->setId(789);
+               $t3->setName('mobile client');
+
+               $this->publicKeyTokenProvider
+                       ->expects($this->once())
+                       ->method('getTokenByUser')
+                       ->with('theUser')
+                       ->willReturn([$t1, $t2, $t3]);
+               $this->publicKeyTokenProvider
+                       ->expects($this->once())
+                       ->method('invalidateTokenById')
+                       ->with('theUser', 456);
+               $this->manager->invalidateTokensOfUser('theUser', 'My Client Name');
+       }
 }