|
15 | 15 | use OC\Authentication\TwoFactorAuth\ProviderLoader; |
16 | 16 | use OCP\Activity\IEvent; |
17 | 17 | use OCP\Activity\IManager; |
| 18 | +use OCP\AppFramework\Db\DoesNotExistException; |
18 | 19 | use OCP\AppFramework\Utility\ITimeFactory; |
19 | 20 | use OCP\Authentication\TwoFactorAuth\IActivatableAtLogin; |
20 | 21 | use OCP\Authentication\TwoFactorAuth\IProvider; |
@@ -701,4 +702,61 @@ public function testNeedsSecondFactorAppPassword() { |
701 | 702 |
|
702 | 703 | $this->assertFalse($this->manager->needsSecondFactor($user)); |
703 | 704 | } |
| 705 | + |
| 706 | + public function testClearTwoFactorPending() { |
| 707 | + $this->config->method('getUserKeys') |
| 708 | + ->with('theUserId', 'login_token_2fa') |
| 709 | + ->willReturn([ |
| 710 | + '42', '43', '44' |
| 711 | + ]); |
| 712 | + |
| 713 | + $this->config->expects($this->exactly(3)) |
| 714 | + ->method('deleteUserValue') |
| 715 | + ->withConsecutive( |
| 716 | + ['theUserId', 'login_token_2fa', '42'], |
| 717 | + ['theUserId', 'login_token_2fa', '43'], |
| 718 | + ['theUserId', 'login_token_2fa', '44'], |
| 719 | + ); |
| 720 | + |
| 721 | + $this->tokenProvider->expects($this->exactly(3)) |
| 722 | + ->method('invalidateTokenById') |
| 723 | + ->withConsecutive( |
| 724 | + ['theUserId', 42], |
| 725 | + ['theUserId', 43], |
| 726 | + ['theUserId', 44], |
| 727 | + ); |
| 728 | + |
| 729 | + $this->manager->clearTwoFactorPending('theUserId'); |
| 730 | + } |
| 731 | + |
| 732 | + public function testClearTwoFactorPendingTokenDoesNotExist() { |
| 733 | + $this->config->method('getUserKeys') |
| 734 | + ->with('theUserId', 'login_token_2fa') |
| 735 | + ->willReturn([ |
| 736 | + '42', '43', '44' |
| 737 | + ]); |
| 738 | + |
| 739 | + $this->config->expects($this->exactly(3)) |
| 740 | + ->method('deleteUserValue') |
| 741 | + ->withConsecutive( |
| 742 | + ['theUserId', 'login_token_2fa', '42'], |
| 743 | + ['theUserId', 'login_token_2fa', '43'], |
| 744 | + ['theUserId', 'login_token_2fa', '44'], |
| 745 | + ); |
| 746 | + |
| 747 | + $this->tokenProvider->expects($this->exactly(3)) |
| 748 | + ->method('invalidateTokenById') |
| 749 | + ->withConsecutive( |
| 750 | + ['theUserId', 42], |
| 751 | + ['theUserId', 43], |
| 752 | + ['theUserId', 44], |
| 753 | + ) |
| 754 | + ->willReturnCallback(function ($user, $tokenId) { |
| 755 | + if ($tokenId === 43) { |
| 756 | + throw new DoesNotExistException('token does not exist'); |
| 757 | + } |
| 758 | + }); |
| 759 | + |
| 760 | + $this->manager->clearTwoFactorPending('theUserId'); |
| 761 | + } |
704 | 762 | } |
0 commit comments