|
|
|
@ -86,7 +86,7 @@ class EncryptionTest extends TestCase { |
|
|
|
/** |
|
|
|
* @dataProvider dataTestBegin |
|
|
|
*/ |
|
|
|
public function testBegin($mode, $header, $legacyCipher, $defaultCipher, $expected) { |
|
|
|
public function testBegin($mode, $header, $legacyCipher, $defaultCipher, $fileKey, $expected) { |
|
|
|
|
|
|
|
$this->cryptMock->expects($this->any()) |
|
|
|
->method('getCipher') |
|
|
|
@ -94,22 +94,36 @@ class EncryptionTest extends TestCase { |
|
|
|
$this->cryptMock->expects($this->any()) |
|
|
|
->method('getLegacyCipher') |
|
|
|
->willReturn($legacyCipher); |
|
|
|
$this->cryptMock->expects($this->any()) |
|
|
|
->method('generateFileKey') |
|
|
|
->willReturn('fileKey'); |
|
|
|
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(\Test_Helper::invokePrivate($this->instance, 'isWriteOperation')); |
|
|
|
} else { |
|
|
|
$this->assertFalse(\Test_Helper::invokePrivate($this->instance, 'isWriteOperation')); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public function dataTestBegin() { |
|
|
|
return array( |
|
|
|
array('w', ['cipher' => 'myCipher'], 'legacyCipher', 'defaultCipher', 'myCipher'), |
|
|
|
array('r', ['cipher' => 'myCipher'], 'legacyCipher', 'defaultCipher', 'myCipher'), |
|
|
|
array('w', [], 'legacyCipher', 'defaultCipher', 'defaultCipher'), |
|
|
|
array('r', [], 'legacyCipher', 'defaultCipher', 'legacyCipher'), |
|
|
|
array('w', ['cipher' => 'myCipher'], 'legacyCipher', 'defaultCipher', 'fileKey', 'myCipher'), |
|
|
|
array('r', ['cipher' => 'myCipher'], 'legacyCipher', 'defaultCipher', 'fileKey', 'myCipher'), |
|
|
|
array('w', [], 'legacyCipher', 'defaultCipher', '', 'defaultCipher'), |
|
|
|
array('r', [], 'legacyCipher', 'defaultCipher', 'file_key', 'legacyCipher'), |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
|