예제 #1
0
 /**
  * @dataProvider dataTestGetFileKey
  *
  * @param $uid
  * @param $isMasterKeyEnabled
  * @param $privateKey
  * @param $expected
  */
 public function testGetFileKey($uid, $isMasterKeyEnabled, $privateKey, $expected)
 {
     $path = '/foo.txt';
     if ($isMasterKeyEnabled) {
         $expectedUid = 'masterKeyId';
     } else {
         $expectedUid = $uid;
     }
     $this->invokePrivate($this->instance, 'masterKeyId', ['masterKeyId']);
     $this->keyStorageMock->expects($this->at(0))->method('getFileKey')->with($path, 'fileKey', 'OC_DEFAULT_MODULE')->willReturn(true);
     $this->keyStorageMock->expects($this->at(1))->method('getFileKey')->with($path, $expectedUid . '.shareKey', 'OC_DEFAULT_MODULE')->willReturn(true);
     if (is_null($uid)) {
         $this->keyStorageMock->expects($this->once())->method('getSystemUserKey')->willReturn(true);
         $this->cryptMock->expects($this->once())->method('decryptPrivateKey')->willReturn($privateKey);
     } else {
         $this->keyStorageMock->expects($this->never())->method('getSystemUserKey');
         $this->utilMock->expects($this->once())->method('isMasterKeyEnabled')->willReturn($isMasterKeyEnabled);
         $this->sessionMock->expects($this->once())->method('getPrivateKey')->willReturn($privateKey);
     }
     if ($privateKey) {
         $this->cryptMock->expects($this->once())->method('multiKeyDecrypt')->willReturn(true);
     } else {
         $this->cryptMock->expects($this->never())->method('multiKeyDecrypt');
     }
     $this->assertSame($expected, $this->instance->getFileKey($path, $uid));
 }
예제 #2
0
 /**
  * test begin() if decryptAll mode was activated
  */
 public function testBeginDecryptAll()
 {
     $path = '/user/files/foo.txt';
     $recoveryKeyId = 'recoveryKeyId';
     $recoveryShareKey = 'recoveryShareKey';
     $decryptAllKey = 'decryptAllKey';
     $fileKey = 'fileKey';
     $this->sessionMock->expects($this->once())->method('decryptAllModeActivated')->willReturn(true);
     $this->sessionMock->expects($this->once())->method('getDecryptAllUid')->willReturn($recoveryKeyId);
     $this->sessionMock->expects($this->once())->method('getDecryptAllKey')->willReturn($decryptAllKey);
     $this->keyManagerMock->expects($this->once())->method('getEncryptedFileKey')->willReturn('encryptedFileKey');
     $this->keyManagerMock->expects($this->once())->method('getShareKey')->with($path, $recoveryKeyId)->willReturn($recoveryShareKey);
     $this->cryptMock->expects($this->once())->method('multiKeyDecrypt')->with('encryptedFileKey', $recoveryShareKey, $decryptAllKey)->willReturn($fileKey);
     $this->keyManagerMock->expects($this->never())->method('getFileKey');
     $this->instance->begin($path, 'user', 'r', [], []);
     $this->assertSame($fileKey, $this->invokePrivate($this->instance, 'fileKey'));
 }
 /**
  * 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']);
 }