summaryrefslogtreecommitdiffstats
path: root/tests/Core/Command/TwoFactorAuth
diff options
context:
space:
mode:
authorRoeland Jago Douma <roeland@famdouma.nl>2016-12-20 16:35:42 +0100
committerRoeland Jago Douma <roeland@famdouma.nl>2016-12-20 16:36:58 +0100
commit09caadac057094181d3ed8470bcd09b2dec18dbe (patch)
tree243467d71dd9d558f74a7f47fca76316bb7cf6cf /tests/Core/Command/TwoFactorAuth
parentf50252c7c1881dd044cbbd8933406e449f5fd0a8 (diff)
downloadnextcloud-server-09caadac057094181d3ed8470bcd09b2dec18dbe.tar.gz
nextcloud-server-09caadac057094181d3ed8470bcd09b2dec18dbe.zip
Add tests for 2FA commands
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Diffstat (limited to 'tests/Core/Command/TwoFactorAuth')
-rw-r--r--tests/Core/Command/TwoFactorAuth/DisableTest.php99
-rw-r--r--tests/Core/Command/TwoFactorAuth/EnableTest.php99
2 files changed, 198 insertions, 0 deletions
diff --git a/tests/Core/Command/TwoFactorAuth/DisableTest.php b/tests/Core/Command/TwoFactorAuth/DisableTest.php
new file mode 100644
index 00000000000..1a0bbc6c3d3
--- /dev/null
+++ b/tests/Core/Command/TwoFactorAuth/DisableTest.php
@@ -0,0 +1,99 @@
+<?php
+/**
+ * @copyright 2016, Roeland Jago Douma <roeland@famdouma.nl>
+ *
+ * @author Roeland Jago Douma <roeland@famdouma.nl>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+namespace Test\Core\Command\TwoFactorAuth;
+
+use OC\Authentication\TwoFactorAuth\Manager;
+use OC\Core\Command\TwoFactorAuth\Disable;
+use OCP\IUser;
+use OCP\IUserManager;
+use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Output\OutputInterface;
+use Test\TestCase;
+
+class DisableTest extends TestCase {
+
+ /** @var Manager|\PHPUnit_Framework_MockObject_MockObject */
+ private $manager;
+
+ /** @var IUserManager|\PHPUnit_Framework_MockObject_MockObject */
+ private $userManager;
+
+ /** @var Disable */
+ private $command;
+
+ public function setUp() {
+ parent::setUp();
+
+ $this->manager = $this->createMock(Manager::class);
+ $this->userManager = $this->createMock(IUserManager::class);
+
+ $this->command = new Disable($this->manager, $this->userManager);
+ }
+
+ public function testDisableSuccess() {
+ $user = $this->createMock(IUser::class);
+
+ $input = $this->createMock(InputInterface::class);
+ $output = $this->createMock(OutputInterface::class);
+
+ $input->method('getArgument')
+ ->with($this->equalTo('uid'))
+ ->willReturn('user');
+
+ $this->userManager->method('get')
+ ->with('user')
+ ->willReturn($user);
+
+ $this->manager->expects($this->once())
+ ->method('disableTwoFactorAuthentication')
+ ->with($this->equalTo($user));
+
+ $output->expects($this->once())
+ ->method('writeln')
+ ->with('Two-factor authentication disabled for user user');
+
+ $this->invokePrivate($this->command, 'execute', [$input, $output]);
+ }
+
+ public function testEnableFail() {
+ $input = $this->createMock(InputInterface::class);
+ $output = $this->createMock(OutputInterface::class);
+
+ $input->method('getArgument')
+ ->with($this->equalTo('uid'))
+ ->willReturn('user');
+
+ $this->userManager->method('get')
+ ->with('user')
+ ->willReturn(null);
+
+ $this->manager->expects($this->never())
+ ->method($this->anything());
+
+ $output->expects($this->once())
+ ->method('writeln')
+ ->with('<error>Invalid UID</error>');
+
+ $this->invokePrivate($this->command, 'execute', [$input, $output]);
+ }
+}
diff --git a/tests/Core/Command/TwoFactorAuth/EnableTest.php b/tests/Core/Command/TwoFactorAuth/EnableTest.php
new file mode 100644
index 00000000000..ebca40df9a5
--- /dev/null
+++ b/tests/Core/Command/TwoFactorAuth/EnableTest.php
@@ -0,0 +1,99 @@
+<?php
+/**
+ * @copyright 2016, Roeland Jago Douma <roeland@famdouma.nl>
+ *
+ * @author Roeland Jago Douma <roeland@famdouma.nl>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+namespace Test\Core\Command\TwoFactorAuth;
+
+use OC\Authentication\TwoFactorAuth\Manager;
+use OC\Core\Command\TwoFactorAuth\Enable;
+use OCP\IUser;
+use OCP\IUserManager;
+use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Output\OutputInterface;
+use Test\TestCase;
+
+class EnableTest extends TestCase {
+
+ /** @var Manager|\PHPUnit_Framework_MockObject_MockObject */
+ private $manager;
+
+ /** @var IUserManager|\PHPUnit_Framework_MockObject_MockObject */
+ private $userManager;
+
+ /** @var Enable */
+ private $command;
+
+ public function setUp() {
+ parent::setUp();
+
+ $this->manager = $this->createMock(Manager::class);
+ $this->userManager = $this->createMock(IUserManager::class);
+
+ $this->command = new Enable($this->manager, $this->userManager);
+ }
+
+ public function testEnableSuccess() {
+ $user = $this->createMock(IUser::class);
+
+ $input = $this->createMock(InputInterface::class);
+ $output = $this->createMock(OutputInterface::class);
+
+ $input->method('getArgument')
+ ->with($this->equalTo('uid'))
+ ->willReturn('user');
+
+ $this->userManager->method('get')
+ ->with('user')
+ ->willReturn($user);
+
+ $this->manager->expects($this->once())
+ ->method('enableTwoFactorAuthentication')
+ ->with($this->equalTo($user));
+
+ $output->expects($this->once())
+ ->method('writeln')
+ ->with('Two-factor authentication enabled for user user');
+
+ $this->invokePrivate($this->command, 'execute', [$input, $output]);
+ }
+
+ public function testEnableFail() {
+ $input = $this->createMock(InputInterface::class);
+ $output = $this->createMock(OutputInterface::class);
+
+ $input->method('getArgument')
+ ->with($this->equalTo('uid'))
+ ->willReturn('user');
+
+ $this->userManager->method('get')
+ ->with('user')
+ ->willReturn(null);
+
+ $this->manager->expects($this->never())
+ ->method($this->anything());
+
+ $output->expects($this->once())
+ ->method('writeln')
+ ->with('<error>Invalid UID</error>');
+
+ $this->invokePrivate($this->command, 'execute', [$input, $output]);
+ }
+}