diff options
author | Bjoern Schiessle <schiessle@owncloud.com> | 2016-03-02 13:58:06 +0100 |
---|---|---|
committer | Bjoern Schiessle <schiessle@owncloud.com> | 2016-03-18 11:06:14 +0100 |
commit | 5e267589d40400223e5dce692568ab2933be14f7 (patch) | |
tree | 018f66a48dacf80ab512c3d1898359f420b173b6 /apps/encryption/tests | |
parent | a6c921267e00d0fb5021e8bdbd4d202931d7a58a (diff) | |
download | nextcloud-server-5e267589d40400223e5dce692568ab2933be14f7.tar.gz nextcloud-server-5e267589d40400223e5dce692568ab2933be14f7.zip |
only create and update user specific key if no master key is enabled
Diffstat (limited to 'apps/encryption/tests')
-rw-r--r-- | apps/encryption/tests/hooks/UserHooksTest.php | 31 | ||||
-rw-r--r-- | apps/encryption/tests/lib/users/SetupTest.php | 59 |
2 files changed, 57 insertions, 33 deletions
diff --git a/apps/encryption/tests/hooks/UserHooksTest.php b/apps/encryption/tests/hooks/UserHooksTest.php index 08d1981266c..1aeafad0ba2 100644 --- a/apps/encryption/tests/hooks/UserHooksTest.php +++ b/apps/encryption/tests/hooks/UserHooksTest.php @@ -71,7 +71,7 @@ class UserHooksTest extends TestCase { private $params = ['uid' => 'testUser', 'password' => 'password']; public function testLogin() { - $this->userSetupMock->expects($this->exactly(2)) + $this->userSetupMock->expects($this->once()) ->method('setupUser') ->willReturnOnConsecutiveCalls(true, false); @@ -80,7 +80,6 @@ class UserHooksTest extends TestCase { ->with('testUser', 'password'); $this->assertNull($this->instance->login($this->params)); - $this->assertFalse($this->instance->login($this->params)); } public function testLogout() { @@ -256,7 +255,7 @@ class UserHooksTest extends TestCase { ->with('testUser'); $this->userSetupMock->expects($this->once()) - ->method('setupServerSide') + ->method('setupUser') ->with('testUser', 'password'); $this->assertNull($this->instance->postPasswordReset($this->params)); @@ -312,16 +311,22 @@ class UserHooksTest extends TestCase { $this->sessionMock = $sessionMock; $this->recoveryMock = $recoveryMock; $this->utilMock = $utilMock; - $this->instance = new UserHooks($this->keyManagerMock, - $this->userManagerMock, - $this->loggerMock, - $this->userSetupMock, - $this->userSessionMock, - $this->utilMock, - $this->sessionMock, - $this->cryptMock, - $this->recoveryMock - ); + $this->utilMock->expects($this->any())->method('isMasterKeyEnabled')->willReturn(false); + + $this->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(['setupFS'])->getMock(); } diff --git a/apps/encryption/tests/lib/users/SetupTest.php b/apps/encryption/tests/lib/users/SetupTest.php index 0cc59384b16..e7d8afbb102 100644 --- a/apps/encryption/tests/lib/users/SetupTest.php +++ b/apps/encryption/tests/lib/users/SetupTest.php @@ -41,26 +41,6 @@ class SetupTest extends TestCase { */ private $instance; - public function testSetupServerSide() { - $this->keyManagerMock->expects($this->exactly(2))->method('validateShareKey'); - $this->keyManagerMock->expects($this->exactly(2))->method('validateMasterKey'); - $this->keyManagerMock->expects($this->exactly(2)) - ->method('userHasKeys') - ->with('admin') - ->willReturnOnConsecutiveCalls(true, false); - - $this->assertTrue($this->instance->setupServerSide('admin', - 'password')); - - $this->keyManagerMock->expects($this->once()) - ->method('storeKeyPair') - ->with('admin', 'password') - ->willReturn(false); - - $this->assertFalse($this->instance->setupServerSide('admin', - 'password')); - } - protected function setUp() { parent::setUp(); $logMock = $this->getMock('OCP\ILogger'); @@ -81,4 +61,43 @@ class SetupTest extends TestCase { $this->keyManagerMock); } + + public function testSetupSystem() { + $this->keyManagerMock->expects($this->once())->method('validateShareKey'); + $this->keyManagerMock->expects($this->once())->method('validateMasterKey'); + + $this->instance->setupSystem(); + } + + /** + * @dataProvider dataTestSetupUser + * + * @param bool $hasKeys + * @param bool $expected + */ + public function testSetupUser($hasKeys, $expected) { + + $this->keyManagerMock->expects($this->once())->method('userHasKeys') + ->with('uid')->willReturn($hasKeys); + + if ($hasKeys) { + $this->keyManagerMock->expects($this->never())->method('storeKeyPair'); + } else { + $this->cryptMock->expects($this->once())->method('createKeyPair')->willReturn('keyPair'); + $this->keyManagerMock->expects($this->once())->method('storeKeyPair') + ->with('uid', 'password', 'keyPair')->willReturn(true); + } + + $this->assertSame($expected, + $this->instance->setupUser('uid', 'password') + ); + } + + public function dataTestSetupUser() { + return [ + [true, true], + [false, true] + ]; + } + } |