summaryrefslogtreecommitdiffstats
path: root/apps/twofactor_backupcodes/tests
diff options
context:
space:
mode:
authorChristoph Wurst <christoph@winzerhof-wurst.at>2017-05-02 14:40:44 +0200
committerChristoph Wurst <christoph@winzerhof-wurst.at>2017-05-02 14:40:44 +0200
commitd8b3fe460e8fc12d7611f0e2f3f469e791f4c090 (patch)
tree927396a0a92244288921d717602933c025ee4078 /apps/twofactor_backupcodes/tests
parent94c2f12226ed005fc2a1e9c440ec70346e9c272a (diff)
downloadnextcloud-server-d8b3fe460e8fc12d7611f0e2f3f469e791f4c090.tar.gz
nextcloud-server-d8b3fe460e8fc12d7611f0e2f3f469e791f4c090.zip
Hide 2FA backup codes if no other 2FA providers are enabled
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Diffstat (limited to 'apps/twofactor_backupcodes/tests')
-rw-r--r--apps/twofactor_backupcodes/tests/Unit/Provider/BackupCodesProviderTest.php61
1 files changed, 56 insertions, 5 deletions
diff --git a/apps/twofactor_backupcodes/tests/Unit/Provider/BackupCodesProviderTest.php b/apps/twofactor_backupcodes/tests/Unit/Provider/BackupCodesProviderTest.php
index 5a99cfadd41..cec5b7b2160 100644
--- a/apps/twofactor_backupcodes/tests/Unit/Provider/BackupCodesProviderTest.php
+++ b/apps/twofactor_backupcodes/tests/Unit/Provider/BackupCodesProviderTest.php
@@ -22,32 +22,41 @@
namespace OCA\TwoFactorBackupCodes\Tests\Unit\Provider;
+use OC\App\AppManager;
use OCA\TwoFactorBackupCodes\Provider\BackupCodesProvider;
use OCA\TwoFactorBackupCodes\Service\BackupCodeStorage;
use OCP\IL10N;
use OCP\IUser;
use OCP\Template;
+use PHPUnit_Framework_MockObject_MockObject;
use Test\TestCase;
class BackupCodesProviderTest extends TestCase {
+ /** @var string */
+ private $appName;
+
/** @var BackupCodeStorage|PHPUnit_Framework_MockObject_MockObject */
private $storage;
/** @var IL10N|PHPUnit_Framework_MockObject_MockObject */
private $l10n;
+ /** @var AppManager|PHPUnit_Framework_MockObject_MockObject */
+ private $appManager;
+
/** @var BackupCodesProvider */
private $provider;
protected function setUp() {
parent::setUp();
- $this->storage = $this->getMockBuilder(BackupCodeStorage::class)
- ->disableOriginalConstructor()
- ->getMock();
- $this->l10n = $this->getMockBuilder(IL10N::class)->getMock();
- $this->provider = new BackupCodesProvider($this->storage, $this->l10n);
+ $this->appName = "twofactor_backupcodes";
+ $this->storage = $this->createMock(BackupCodeStorage::class);
+ $this->l10n = $this->createMock(IL10N::class);
+ $this->appManager = $this->createMock(AppManager::class);
+
+ $this->provider = new BackupCodesProvider($this->appName, $this->storage, $this->l10n, $this->appManager);
}
public function testGetId() {
@@ -100,4 +109,46 @@ class BackupCodesProviderTest extends TestCase {
$this->assertTrue($this->provider->isTwoFactorAuthEnabledForUser($user));
}
+ public function testIsActiveNoProviders() {
+ $user = $this->getMockBuilder(IUser::class)->getMock();
+
+ $this->appManager->expects($this->once())
+ ->method('getEnabledAppsForUser')
+ ->with($user)
+ ->willReturn([
+ 'twofactor_backupcodes',
+ 'mail',
+ ]);
+ $this->appManager->expects($this->once())
+ ->method('getAppInfo')
+ ->with('mail')
+ ->willReturn([
+ 'two-factor-providers' => [],
+ ]);
+
+ $this->assertFalse($this->provider->isActive($user));
+ }
+
+ public function testIsActiveWithProviders() {
+ $user = $this->getMockBuilder(IUser::class)->getMock();
+
+ $this->appManager->expects($this->once())
+ ->method('getEnabledAppsForUser')
+ ->with($user)
+ ->willReturn([
+ 'twofactor_backupcodes',
+ 'twofactor_u2f',
+ ]);
+ $this->appManager->expects($this->once())
+ ->method('getAppInfo')
+ ->with('twofactor_u2f')
+ ->willReturn([
+ 'two-factor-providers' => [
+ 'OCA\TwoFactorU2F\Provider\U2FProvider',
+ ],
+ ]);
+
+ $this->assertTrue($this->provider->isActive($user));
+ }
+
}