summaryrefslogtreecommitdiffstats
path: root/tests/lib/Authentication/TwoFactorAuth/ManagerTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/lib/Authentication/TwoFactorAuth/ManagerTest.php')
-rw-r--r--tests/lib/Authentication/TwoFactorAuth/ManagerTest.php26
1 files changed, 26 insertions, 0 deletions
diff --git a/tests/lib/Authentication/TwoFactorAuth/ManagerTest.php b/tests/lib/Authentication/TwoFactorAuth/ManagerTest.php
index 301b4cc09db..acc0f0d3e92 100644
--- a/tests/lib/Authentication/TwoFactorAuth/ManagerTest.php
+++ b/tests/lib/Authentication/TwoFactorAuth/ManagerTest.php
@@ -26,6 +26,7 @@ use Exception;
use OC;
use OC\Authentication\Token\IProvider as TokenProvider;
use OC\Authentication\TwoFactorAuth\Manager;
+use OC\Authentication\TwoFactorAuth\MandatoryTwoFactor;
use OC\Authentication\TwoFactorAuth\ProviderLoader;
use OCP\Activity\IEvent;
use OCP\Activity\IManager;
@@ -50,6 +51,9 @@ class ManagerTest extends TestCase {
/** @var IRegistry|\PHPUnit_Framework_MockObject_MockObject */
private $providerRegistry;
+ /** @var MandatoryTwoFactor|\PHPUnit_Framework_MockObject_MockObject */
+ private $mandatoryTwoFactor;
+
/** @var ISession|\PHPUnit_Framework_MockObject_MockObject */
private $session;
@@ -86,6 +90,7 @@ class ManagerTest extends TestCase {
$this->user = $this->createMock(IUser::class);
$this->providerLoader = $this->createMock(\OC\Authentication\TwoFactorAuth\ProviderLoader::class);
$this->providerRegistry = $this->createMock(IRegistry::class);
+ $this->mandatoryTwoFactor = $this->createMock(MandatoryTwoFactor::class);
$this->session = $this->createMock(ISession::class);
$this->config = $this->createMock(IConfig::class);
$this->activityManager = $this->createMock(IManager::class);
@@ -97,6 +102,7 @@ class ManagerTest extends TestCase {
$this->manager = new Manager(
$this->providerLoader,
$this->providerRegistry,
+ $this->mandatoryTwoFactor,
$this->session,
$this->config,
$this->activityManager,
@@ -142,7 +148,20 @@ class ManagerTest extends TestCase {
]);
}
+ public function testIsTwoFactorAuthenticatedEnforced() {
+ $this->mandatoryTwoFactor->expects($this->once())
+ ->method('isEnforced')
+ ->willReturn(true);
+
+ $enabled = $this->manager->isTwoFactorAuthenticated($this->user);
+
+ $this->assertTrue($enabled);
+ }
+
public function testIsTwoFactorAuthenticatedNoProviders() {
+ $this->mandatoryTwoFactor->expects($this->once())
+ ->method('isEnforced')
+ ->willReturn(false);
$this->providerRegistry->expects($this->once())
->method('getProviderStates')
->willReturn([]); // No providers registered
@@ -154,6 +173,9 @@ class ManagerTest extends TestCase {
}
public function testIsTwoFactorAuthenticatedOnlyBackupCodes() {
+ $this->mandatoryTwoFactor->expects($this->once())
+ ->method('isEnforced')
+ ->willReturn(false);
$this->providerRegistry->expects($this->once())
->method('getProviderStates')
->willReturn([
@@ -173,6 +195,9 @@ class ManagerTest extends TestCase {
}
public function testIsTwoFactorAuthenticatedFailingProviders() {
+ $this->mandatoryTwoFactor->expects($this->once())
+ ->method('isEnforced')
+ ->willReturn(false);
$this->providerRegistry->expects($this->once())
->method('getProviderStates')
->willReturn([
@@ -474,6 +499,7 @@ class ManagerTest extends TestCase {
->setConstructorArgs([
$this->providerLoader,
$this->providerRegistry,
+ $this->mandatoryTwoFactor,
$this->session,
$this->config,
$this->activityManager,