summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorBjoern Schiessle <bjoern@schiessle.org>2018-08-10 16:40:09 +0200
committerBjoern Schiessle <bjoern@schiessle.org>2018-08-15 15:08:36 +0200
commit3c5fb2b52b5f84fd6562da10f22c7ab7f6bf7a67 (patch)
tree7d18663be5d781d5d1a152c83b1335e152f2c4d9 /tests
parentdfec66ca029efb04b7051c227db780860302fd12 (diff)
downloadnextcloud-server-3c5fb2b52b5f84fd6562da10f22c7ab7f6bf7a67.tar.gz
nextcloud-server-3c5fb2b52b5f84fd6562da10f22c7ab7f6bf7a67.zip
update unit tests
Signed-off-by: Bjoern Schiessle <bjoern@schiessle.org>
Diffstat (limited to 'tests')
-rw-r--r--tests/Core/Controller/LostControllerTest.php42
1 files changed, 41 insertions, 1 deletions
diff --git a/tests/Core/Controller/LostControllerTest.php b/tests/Core/Controller/LostControllerTest.php
index 8ccabfbf79a..d6afa5959a0 100644
--- a/tests/Core/Controller/LostControllerTest.php
+++ b/tests/Core/Controller/LostControllerTest.php
@@ -27,6 +27,7 @@ use OCP\AppFramework\Http\JSONResponse;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\Defaults;
+use OCP\Encryption\IEncryptionModule;
use OCP\Encryption\IManager;
use OCP\IConfig;
use OCP\IL10N;
@@ -713,10 +714,49 @@ class LostControllerTest extends \Test\TestCase {
$this->assertEquals($expectedResponse, $response);
}
- public function testSetPasswordEncryptionDontProceed() {
+ public function testSetPasswordEncryptionDontProceedPerUserKey() {
+ /** @var IEncryptionModule|PHPUnit_Framework_MockObject_MockObject $encryptionModule */
+ $encryptionModule = $this->createMock(IEncryptionModule::class);
+ $encryptionModule->expects($this->once())->method('needDetailedAccessList')->willReturn(true);
+ $this->encryptionManager->expects($this->once())->method('getEncryptionModules')
+ ->willReturn([0 => ['callback' => function() use ($encryptionModule) { return $encryptionModule; }]]);
$response = $this->lostController->setPassword('myToken', 'user', 'newpass', false);
$expectedResponse = ['status' => 'error', 'msg' => '', 'encryption' => true];
$this->assertSame($expectedResponse, $response);
}
+ public function testSetPasswordDontProceedMasterKey() {
+ $encryptionModule = $this->createMock(IEncryptionModule::class);
+ $encryptionModule->expects($this->once())->method('needDetailedAccessList')->willReturn(false);
+ $this->encryptionManager->expects($this->once())->method('getEncryptionModules')
+ ->willReturn([0 => ['callback' => function() use ($encryptionModule) { return $encryptionModule; }]]);
+ $this->config->method('getUserValue')
+ ->with('ValidTokenUser', 'core', 'lostpassword', null)
+ ->willReturn('encryptedData');
+ $this->existingUser->method('getLastLogin')
+ ->will($this->returnValue(12344));
+ $this->existingUser->expects($this->once())
+ ->method('setPassword')
+ ->with('NewPassword')
+ ->willReturn(true);
+ $this->userManager->method('get')
+ ->with('ValidTokenUser')
+ ->willReturn($this->existingUser);
+ $this->config->expects($this->once())
+ ->method('deleteUserValue')
+ ->with('ValidTokenUser', 'core', 'lostpassword');
+ $this->timeFactory->method('getTime')
+ ->will($this->returnValue(12348));
+
+ $this->crypto->method('decrypt')
+ ->with(
+ $this->equalTo('encryptedData'),
+ $this->equalTo('test@example.comSECRET')
+ )->willReturn('12345:TheOnlyAndOnlyOneTokenToResetThePassword');
+
+ $response = $this->lostController->setPassword('TheOnlyAndOnlyOneTokenToResetThePassword', 'ValidTokenUser', 'NewPassword', false);
+ $expectedResponse = array('user' => 'ValidTokenUser', 'status' => 'success');
+ $this->assertSame($expectedResponse, $response);
+ }
+
}