Ejemplo n.º 1
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'));
 }
Ejemplo n.º 2
0
 /**
  * @dataProvider dataTestBegin
  */
 public function testBegin($mode, $header, $legacyCipher, $defaultCipher, $fileKey, $expected)
 {
     $this->cryptMock->expects($this->any())->method('getCipher')->willReturn($defaultCipher);
     $this->cryptMock->expects($this->any())->method('getLegacyCipher')->willReturn($legacyCipher);
     if (empty($fileKey)) {
         $this->cryptMock->expects($this->once())->method('generateFileKey')->willReturn('fileKey');
     } else {
         $this->cryptMock->expects($this->never())->method('generateFileKey');
     }
     $this->keyManagerMock->expects($this->once())->method('getFileKey')->willReturn($fileKey);
     $result = $this->instance->begin('/user/files/foo.txt', 'user', $mode, $header, []);
     $this->assertArrayHasKey('cipher', $result);
     $this->assertSame($expected, $result['cipher']);
     if ($mode === 'w') {
         $this->assertTrue(self::invokePrivate($this->instance, 'isWriteOperation'));
     } else {
         $this->assertFalse(self::invokePrivate($this->instance, 'isWriteOperation'));
     }
 }