|
29 | 29 | use OC\Authentication\TwoFactorAuth\ProviderLoader;
|
30 | 30 | use OCP\Activity\IEvent;
|
31 | 31 | use OCP\Activity\IManager;
|
| 32 | +use OCP\AppFramework\Db\DoesNotExistException; |
32 | 33 | use OCP\AppFramework\Utility\ITimeFactory;
|
33 | 34 | use OCP\Authentication\TwoFactorAuth\IActivatableAtLogin;
|
34 | 35 | use OCP\Authentication\TwoFactorAuth\IProvider;
|
@@ -715,4 +716,61 @@ public function testNeedsSecondFactorAppPassword() {
|
715 | 716 |
|
716 | 717 | $this->assertFalse($this->manager->needsSecondFactor($user));
|
717 | 718 | }
|
| 719 | + |
| 720 | + public function testClearTwoFactorPending() { |
| 721 | + $this->config->method('getUserKeys') |
| 722 | + ->with('theUserId', 'login_token_2fa') |
| 723 | + ->willReturn([ |
| 724 | + '42', '43', '44' |
| 725 | + ]); |
| 726 | + |
| 727 | + $this->config->expects($this->exactly(3)) |
| 728 | + ->method('deleteUserValue') |
| 729 | + ->withConsecutive( |
| 730 | + ['theUserId', 'login_token_2fa', '42'], |
| 731 | + ['theUserId', 'login_token_2fa', '43'], |
| 732 | + ['theUserId', 'login_token_2fa', '44'], |
| 733 | + ); |
| 734 | + |
| 735 | + $this->tokenProvider->expects($this->exactly(3)) |
| 736 | + ->method('invalidateTokenById') |
| 737 | + ->withConsecutive( |
| 738 | + ['theUserId', 42], |
| 739 | + ['theUserId', 43], |
| 740 | + ['theUserId', 44], |
| 741 | + ); |
| 742 | + |
| 743 | + $this->manager->clearTwoFactorPending('theUserId'); |
| 744 | + } |
| 745 | + |
| 746 | + public function testClearTwoFactorPendingTokenDoesNotExist() { |
| 747 | + $this->config->method('getUserKeys') |
| 748 | + ->with('theUserId', 'login_token_2fa') |
| 749 | + ->willReturn([ |
| 750 | + '42', '43', '44' |
| 751 | + ]); |
| 752 | + |
| 753 | + $this->config->expects($this->exactly(3)) |
| 754 | + ->method('deleteUserValue') |
| 755 | + ->withConsecutive( |
| 756 | + ['theUserId', 'login_token_2fa', '42'], |
| 757 | + ['theUserId', 'login_token_2fa', '43'], |
| 758 | + ['theUserId', 'login_token_2fa', '44'], |
| 759 | + ); |
| 760 | + |
| 761 | + $this->tokenProvider->expects($this->exactly(3)) |
| 762 | + ->method('invalidateTokenById') |
| 763 | + ->withConsecutive( |
| 764 | + ['theUserId', 42], |
| 765 | + ['theUserId', 43], |
| 766 | + ['theUserId', 44], |
| 767 | + ) |
| 768 | + ->willReturnCallback(function ($user, $tokenId) { |
| 769 | + if ($tokenId === 43) { |
| 770 | + throw new DoesNotExistException('token does not exist'); |
| 771 | + } |
| 772 | + }); |
| 773 | + |
| 774 | + $this->manager->clearTwoFactorPending('theUserId'); |
| 775 | + } |
718 | 776 | }
|
0 commit comments