Beispiel #1
0
 /**
  * @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'));
 }
Beispiel #2
0
 public function testRecoverFile()
 {
     $this->keyManagerMock->expects($this->once())->method('getEncryptedFileKey')->willReturn(true);
     $this->keyManagerMock->expects($this->once())->method('getShareKey')->willReturn(true);
     $this->cryptMock->expects($this->once())->method('multiKeyDecrypt')->willReturn(true);
     $this->fileMock->expects($this->once())->method('getAccessList')->willReturn(['users' => ['admin']]);
     $this->keyManagerMock->expects($this->once())->method('getPublicKey')->willReturn('publicKey');
     $this->keyManagerMock->expects($this->once())->method('addSystemKeys')->with($this->anything(), $this->anything(), $this->equalTo('admin'))->willReturn(['admin' => 'publicKey']);
     $this->cryptMock->expects($this->once())->method('multiKeyEncrypt');
     $this->keyManagerMock->expects($this->once())->method('setAllFileKeys');
     $this->assertNull(self::invokePrivate($this->instance, 'recoverFile', ['/', 'testkey', 'admin']));
 }
Beispiel #3
0
 /**
  * Test case if the public key is missing. ownCloud should still encrypt
  * the file for the remaining users
  */
 public function testUpdateMissingPublicKey()
 {
     $this->keyManagerMock->expects($this->once())->method('getFileKey')->willReturn('fileKey');
     $this->keyManagerMock->expects($this->any())->method('getPublicKey')->willReturnCallback(function ($user) {
         throw new PublicKeyMissingException($user);
     });
     $this->keyManagerMock->expects($this->any())->method('addSystemKeys')->willReturnCallback(function ($accessList, $publicKeys) {
         return $publicKeys;
     });
     $this->cryptMock->expects($this->once())->method('multiKeyEncrypt')->willReturnCallback(function ($fileKey, $publicKeys) {
         $this->assertEmpty($publicKeys);
         $this->assertSame('fileKey', $fileKey);
     });
     $this->keyManagerMock->expects($this->never())->method('getVersion');
     $this->keyManagerMock->expects($this->never())->method('setVersion');
     $this->assertTrue($this->instance->update('path', 'user1', ['users' => ['user1']]));
 }
 /**
  * test updatePrivateKeyPassword() with the correct old and new password
  */
 public function testUpdatePrivateKeyPassword()
 {
     $oldPassword = '******';
     $newPassword = '******';
     $this->ocSessionMock->expects($this->once())->method('get')->with('loginname')->willReturn('testUser');
     $this->userManagerMock->expects($this->at(0))->method('checkPassword')->with('testUserUid', 'new')->willReturn(false);
     $this->userManagerMock->expects($this->at(1))->method('checkPassword')->with('testUser', 'new')->willReturn(true);
     $this->cryptMock->expects($this->once())->method('decryptPrivateKey')->willReturn('decryptedKey');
     $this->cryptMock->expects($this->once())->method('encryptPrivateKey')->willReturn('encryptedKey');
     $this->cryptMock->expects($this->once())->method('generateHeader')->willReturn('header.');
     // methods which must be called after successful changing the key password
     $this->keyManagerMock->expects($this->once())->method('setPrivateKey')->with($this->equalTo('testUserUid'), $this->equalTo('header.encryptedKey'));
     $this->sessionMock->expects($this->once())->method('setPrivateKey')->with($this->equalTo('decryptedKey'));
     $this->sessionMock->expects($this->once())->method('setStatus')->with($this->equalTo(Session::INIT_SUCCESSFUL));
     $result = $this->controller->updatePrivateKeyPassword($oldPassword, $newPassword);
     $data = $result->getData();
     $this->assertSame(Http::STATUS_OK, $result->getStatus());
     $this->assertSame('Private key password successfully updated.', $data['message']);
 }
 /**
  * @dataProvider dataTestValidateMasterKey
  *
  * @param $masterKey
  */
 public function testValidateMasterKey($masterKey)
 {
     /** @var \OCA\Encryption\KeyManager | \PHPUnit_Framework_MockObject_MockObject $instance */
     $instance = $this->getMockBuilder('OCA\\Encryption\\KeyManager')->setConstructorArgs([$this->keyStorageMock, $this->cryptMock, $this->configMock, $this->userMock, $this->sessionMock, $this->logMock, $this->utilMock])->setMethods(['getPublicMasterKey', 'setSystemPrivateKey', 'getMasterKeyPassword'])->getMock();
     $instance->expects($this->once())->method('getPublicMasterKey')->willReturn($masterKey);
     $instance->expects($this->any())->method('getMasterKeyPassword')->willReturn('masterKeyPassword');
     $this->cryptMock->expects($this->any())->method('generateHeader')->willReturn('header');
     if (empty($masterKey)) {
         $this->cryptMock->expects($this->once())->method('createKeyPair')->willReturn(['publicKey' => 'public', 'privateKey' => 'private']);
         $this->keyStorageMock->expects($this->once())->method('setSystemUserKey')->with('systemKeyId.publicKey', 'public', \OCA\Encryption\Crypto\Encryption::ID);
         $this->cryptMock->expects($this->once())->method('encryptPrivateKey')->with('private', 'masterKeyPassword', 'systemKeyId')->willReturn('EncryptedKey');
         $instance->expects($this->once())->method('setSystemPrivateKey')->with('systemKeyId', 'headerEncryptedKey');
     } else {
         $this->cryptMock->expects($this->never())->method('createKeyPair');
         $this->keyStorageMock->expects($this->never())->method('setSystemUserKey');
         $this->cryptMock->expects($this->never())->method('encryptPrivateKey');
         $instance->expects($this->never())->method('setSystemPrivateKey');
     }
     $instance->validateMasterKey();
 }