summaryrefslogtreecommitdiffstats
path: root/apps/encryption/tests
diff options
context:
space:
mode:
authorClark Tomlinson <fallen013@gmail.com>2015-04-20 13:49:21 -0400
committerClark Tomlinson <fallen013@gmail.com>2015-04-22 10:46:56 -0400
commit1747117edfd337d50075e3612ca56cac18b96f5a (patch)
treeef2dcad6aeb75db8a98a686f9c0de2373e195caf /apps/encryption/tests
parentc81bc152d7bd649b24b00482e0d57b6ce24643c4 (diff)
downloadnextcloud-server-1747117edfd337d50075e3612ca56cac18b96f5a.tar.gz
nextcloud-server-1747117edfd337d50075e3612ca56cac18b96f5a.zip
destupify tests
Diffstat (limited to 'apps/encryption/tests')
-rw-r--r--apps/encryption/tests/controller/RecoveryControllerTest.php157
1 files changed, 77 insertions, 80 deletions
diff --git a/apps/encryption/tests/controller/RecoveryControllerTest.php b/apps/encryption/tests/controller/RecoveryControllerTest.php
index 289fe60e88c..0ac76774c5f 100644
--- a/apps/encryption/tests/controller/RecoveryControllerTest.php
+++ b/apps/encryption/tests/controller/RecoveryControllerTest.php
@@ -7,10 +7,11 @@
*/
-namespace OC\apps\encryption\tests\lib\controller;
+namespace OCA\Encryption\Tests\Controller;
use OCA\Encryption\Controller\RecoveryController;
+use OCP\AppFramework\Http;
use Test\TestCase;
class RecoveryControllerTest extends TestCase {
@@ -36,114 +37,110 @@ class RecoveryControllerTest extends TestCase {
*/
private $recoveryMock;
- public function testAdminRecovery() {
+ public function adminRecoveryProvider() {
+ return [
+ ['test', 'test', '1', 'Recovery key successfully enabled', HTTP::STATUS_OK],
+ ['', 'test', '1', 'Missing recovery key password', HTTP::STATUS_INTERNAL_SERVER_ERROR],
+ ['test', '', '1', 'Please repeat the recovery key password', HTTP::STATUS_INTERNAL_SERVER_ERROR],
+ ['test', 'soimething that doesn\'t match', '1', 'Repeated recovery key password does not match the provided recovery key password', HTTP::STATUS_INTERNAL_SERVER_ERROR],
+ ['test', 'test', '0', 'Recovery key successfully disabled', HTTP::STATUS_OK],
+ ];
+ }
+
+ /**
+ * @dataProvider adminRecoveryProvider
+ * @param $recoveryPassword
+ * @param $passconfirm
+ * @param $enableRecovery
+ * @param $expectedMessage
+ * @param $expectedStatus
+ */
+ public function testAdminRecovery($recoveryPassword, $passconfirm, $enableRecovery, $expectedMessage, $expectedStatus) {
- $recoveryPassword = 'test';
- $enableRecovery = '1';
$this->recoveryMock->expects($this->any())
->method('enableAdminRecovery')
->willReturn(true);
- $response = $this->controller->adminRecovery($recoveryPassword,
- $recoveryPassword,
- $enableRecovery)->getData();
-
-
- $this->assertEquals('Recovery key successfully enabled',
- $response['data']['message']);
-
- $response = $this->controller->adminRecovery('',
- $recoveryPassword,
- $enableRecovery)->getData();
-
- $this->assertEquals('Missing recovery key password',
- $response['data']['message']);
-
- $response = $this->controller->adminRecovery($recoveryPassword,
- '',
- $enableRecovery)->getData();
-
- $this->assertEquals('Please repeat the recovery key password',
- $response['data']['message']);
-
- $response = $this->controller->adminRecovery($recoveryPassword,
- 'something that doesn\'t match',
- $enableRecovery)->getData();
-
- $this->assertEquals('Repeated recovery key password does not match the provided recovery key password',
- $response['data']['message']);
-
- $this->recoveryMock->expects($this->once())
+ $this->recoveryMock->expects($this->any())
->method('disableAdminRecovery')
->willReturn(true);
$response = $this->controller->adminRecovery($recoveryPassword,
- $recoveryPassword,
- '0')->getData();
+ $passconfirm,
+ $enableRecovery);
- $this->assertEquals('Recovery key successfully disabled',
- $response['data']['message']);
- }
- public function testChangeRecoveryPassword() {
- $password = 'test';
- $oldPassword = 'oldtest';
+ $this->assertEquals($expectedMessage, $response->getData()['data']['message']);
+ $this->assertEquals($expectedStatus, $response->getStatus());
- $data = $this->controller->changeRecoveryPassword($password,
- $oldPassword,
- $password)->getData();
- $this->assertEquals('Could not change the password. Maybe the old password was not correct.',
- $data['data']['message']);
+ }
- $this->recoveryMock->expects($this->once())
+ public function changeRecoveryPasswordProvider() {
+ return [
+ ['test', 'test', 'oldtestFail', 'Could not change the password. Maybe the old password was not correct.', HTTP::STATUS_INTERNAL_SERVER_ERROR],
+ ['test', 'test', 'oldtest', 'Password successfully changed.', HTTP::STATUS_OK],
+ ['test', 'notmatch', 'oldtest', 'Repeated recovery key password does not match the provided recovery key password', HTTP::STATUS_INTERNAL_SERVER_ERROR],
+ ['', 'test', 'oldtest', 'Please provide a new recovery password', HTTP::STATUS_INTERNAL_SERVER_ERROR],
+ ['test', 'test', '', 'Please provide the old recovery password', HTTP::STATUS_INTERNAL_SERVER_ERROR]
+ ];
+ }
+
+ /**
+ * @dataProvider changeRecoveryPasswordProvider
+ * @param $password
+ * @param $confirmPassword
+ * @param $oldPassword
+ * @param $expectedMessage
+ * @param $expectedStatus
+ */
+ public function testChangeRecoveryPassword($password, $confirmPassword, $oldPassword, $expectedMessage, $expectedStatus) {
+ $this->recoveryMock->expects($this->any())
->method('changeRecoveryKeyPassword')
->with($password, $oldPassword)
- ->willReturn(true);
-
- $data = $this->controller->changeRecoveryPassword($password,
- $oldPassword,
- $password)->getData();
-
- $this->assertEquals('Password successfully changed.',
- $data['data']['message']);
+ ->will($this->returnValueMap([
+ ['test', 'oldTestFail', false],
+ ['test', 'oldtest', true]
+ ]));
- $data = $this->controller->changeRecoveryPassword($password,
+ $response = $this->controller->changeRecoveryPassword($password,
$oldPassword,
- 'not match')->getData();
+ $confirmPassword);
- $this->assertEquals('Repeated recovery key password does not match the provided recovery key password',
- $data['data']['message']);
+ $this->assertEquals($expectedMessage, $response->getData()['data']['message']);
+ $this->assertEquals($expectedStatus, $response->getStatus());
- $data = $this->controller->changeRecoveryPassword('',
- $oldPassword,
- $password)->getData();
- $this->assertEquals('Please provide a new recovery password',
- $data['data']['message']);
-
- $data = $this->controller->changeRecoveryPassword($password,
- '',
- $password)->getData();
+ }
- $this->assertEquals('Please provide the old recovery password',
- $data['data']['message']);
+ public function userSetRecoveryProvider() {
+ return [
+ ['1', 'Recovery Key enabled', Http::STATUS_OK],
+ ['0', 'Could not enable the recovery key, please try again or contact your administrator', Http::STATUS_INTERNAL_SERVER_ERROR]
+ ];
}
- public function testUserSetRecovery() {
- $this->recoveryMock->expects($this->exactly(2))
+ /**
+ * @dataProvider userSetRecoveryProvider
+ * @param $enableRecovery
+ * @param $expectedMessage
+ * @param $expectedStatus
+ */
+ public function testUserSetRecovery($enableRecovery, $expectedMessage, $expectedStatus) {
+ $this->recoveryMock->expects($this->any())
->method('setRecoveryForUser')
- ->willReturnOnConsecutiveCalls(true, false);
-
- $data = $this->controller->userSetRecovery('1')->getData();
+ ->with($enableRecovery)
+ ->will($this->returnValueMap([
+ ['1', true],
+ ['0', false]
+ ]));
- $this->assertEquals('Recovery Key enabled', $data['data']['message']);
- $data = $this->controller->userSetRecovery('1')->getData();
+ $response = $this->controller->userSetRecovery($enableRecovery);
- $this->assertEquals('Could not enable the recovery key, please try again or contact your administrator',
- $data['data']['message']);
+ $this->assertEquals($expectedMessage, $response->getData()['data']['message']);
+ $this->assertEquals($expectedStatus, $response->getStatus());
}