summaryrefslogtreecommitdiffstats
path: root/apps/encryption/tests
diff options
context:
space:
mode:
authorBjoern Schiessle <schiessle@owncloud.com>2015-09-11 21:18:13 +0200
committerBjoern Schiessle <schiessle@owncloud.com>2015-09-14 11:49:16 +0200
commit7f459c64cb3bc011d8eb72ddb78cbd678949c675 (patch)
treec61b0836e697fb7a9a830598b6ec58b23f10e143 /apps/encryption/tests
parent1924dd348a41bb52968f4fe598dd6f170536c724 (diff)
downloadnextcloud-server-7f459c64cb3bc011d8eb72ddb78cbd678949c675.tar.gz
nextcloud-server-7f459c64cb3bc011d8eb72ddb78cbd678949c675.zip
check for the right user if we can change his password
Diffstat (limited to 'apps/encryption/tests')
-rw-r--r--apps/encryption/tests/hooks/UserHooksTest.php65
1 files changed, 61 insertions, 4 deletions
diff --git a/apps/encryption/tests/hooks/UserHooksTest.php b/apps/encryption/tests/hooks/UserHooksTest.php
index aa16a4d8703..0b0222ce861 100644
--- a/apps/encryption/tests/hooks/UserHooksTest.php
+++ b/apps/encryption/tests/hooks/UserHooksTest.php
@@ -50,6 +50,11 @@ class UserHooksTest extends TestCase {
/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
+ private $userManagerMock;
+
+ /**
+ * @var \PHPUnit_Framework_MockObject_MockObject
+ */
private $userSetupMock;
/**
* @var \PHPUnit_Framework_MockObject_MockObject
@@ -101,11 +106,58 @@ class UserHooksTest extends TestCase {
$this->assertNull($this->instance->postDeleteUser($this->params));
}
- public function testPreSetPassphrase() {
- $this->userSessionMock->expects($this->once())
- ->method('canChangePassword');
+ /**
+ * @dataProvider dataTestPreSetPassphrase
+ */
+ public function testPreSetPassphrase($canChange) {
+
+ /** @var UserHooks | \PHPUnit_Framework_MockObject_MockObject $instance */
+ $instance = $this->getMockBuilder('OCA\Encryption\Hooks\UserHooks')
+ ->setConstructorArgs(
+ [
+ $this->keyManagerMock,
+ $this->userManagerMock,
+ $this->loggerMock,
+ $this->userSetupMock,
+ $this->userSessionMock,
+ $this->utilMock,
+ $this->sessionMock,
+ $this->cryptMock,
+ $this->recoveryMock
+ ]
+ )
+ ->setMethods(['setPassphrase'])
+ ->getMock();
+
+ $userMock = $this->getMock('OCP\IUser');
+
+ $this->userManagerMock->expects($this->once())
+ ->method('get')
+ ->with($this->params['uid'])
+ ->willReturn($userMock);
+ $userMock->expects($this->once())
+ ->method('canChangePassword')
+ ->willReturn($canChange);
+
+ if ($canChange) {
+ // in this case the password will be changed in the post hook
+ $instance->expects($this->never())->method('setPassphrase');
+ } else {
+ // if user can't change the password we update the encryption
+ // key password already in the pre hook
+ $instance->expects($this->once())
+ ->method('setPassphrase')
+ ->with($this->params);
+ }
+
+ $instance->preSetPassphrase($this->params);
+ }
- $this->assertNull($this->instance->preSetPassphrase($this->params));
+ public function dataTestPreSetPassphrase() {
+ return [
+ [true],
+ [false]
+ ];
}
public function testSetPassphrase() {
@@ -186,6 +238,7 @@ class UserHooksTest extends TestCase {
->willReturn(false);
$userHooks = new UserHooks($this->keyManagerMock,
+ $this->userManagerMock,
$this->loggerMock,
$this->userSetupMock,
$userSessionMock,
@@ -216,6 +269,9 @@ class UserHooksTest extends TestCase {
$this->keyManagerMock = $this->getMockBuilder('OCA\Encryption\KeyManager')
->disableOriginalConstructor()
->getMock();
+ $this->userManagerMock = $this->getMockBuilder('OCP\IUserManager')
+ ->disableOriginalConstructor()
+ ->getMock();
$this->userSetupMock = $this->getMockBuilder('OCA\Encryption\Users\Setup')
->disableOriginalConstructor()
->getMock();
@@ -258,6 +314,7 @@ class UserHooksTest extends TestCase {
$this->recoveryMock = $recoveryMock;
$this->utilMock = $utilMock;
$this->instance = new UserHooks($this->keyManagerMock,
+ $this->userManagerMock,
$this->loggerMock,
$this->userSetupMock,
$this->userSessionMock,