summaryrefslogtreecommitdiffstats
path: root/apps/encryption/tests
diff options
context:
space:
mode:
authorClark Tomlinson <fallen013@gmail.com>2015-04-29 19:32:02 -0400
committerClark Tomlinson <fallen013@gmail.com>2015-04-29 19:32:02 -0400
commit4209757d61685346b9b3eb476035b4e86597ed64 (patch)
tree7ad0b7f6a8579838f8c0076dd81d036e73c75cf0 /apps/encryption/tests
parent8955f38e55e5ec99e79fae6ab999185fcceb0466 (diff)
parent29bcfb2fdbfd922b6918cd8665d4f31858d7e08e (diff)
downloadnextcloud-server-4209757d61685346b9b3eb476035b4e86597ed64.tar.gz
nextcloud-server-4209757d61685346b9b3eb476035b4e86597ed64.zip
Merge pull request #15919 from owncloud/enc_handle_empty_files
Encryption improve handling of empty and unencrypted files
Diffstat (limited to 'apps/encryption/tests')
-rw-r--r--apps/encryption/tests/lib/crypto/encryptionTest.php73
1 files changed, 66 insertions, 7 deletions
diff --git a/apps/encryption/tests/lib/crypto/encryptionTest.php b/apps/encryption/tests/lib/crypto/encryptionTest.php
index 500433c77d4..cb4ca2d3a12 100644
--- a/apps/encryption/tests/lib/crypto/encryptionTest.php
+++ b/apps/encryption/tests/lib/crypto/encryptionTest.php
@@ -38,6 +38,9 @@ class EncryptionTest extends TestCase {
/** @var \PHPUnit_Framework_MockObject_MockObject */
private $utilMock;
+ /** @var \PHPUnit_Framework_MockObject_MockObject */
+ private $loggerMock;
+
public function setUp() {
parent::setUp();
@@ -50,8 +53,16 @@ class EncryptionTest extends TestCase {
$this->keyManagerMock = $this->getMockBuilder('OCA\Encryption\KeyManager')
->disableOriginalConstructor()
->getMock();
+ $this->loggerMock = $this->getMockBuilder('OCP\ILogger')
+ ->disableOriginalConstructor()
+ ->getMock();
- $this->instance = new Encryption($this->cryptMock, $this->keyManagerMock, $this->utilMock);
+ $this->instance = new Encryption(
+ $this->cryptMock,
+ $this->keyManagerMock,
+ $this->utilMock,
+ $this->loggerMock
+ );
}
/**
@@ -75,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')
@@ -83,21 +94,69 @@ class EncryptionTest extends TestCase {
$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(\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'),
+ );
+ }
+
+ /**
+ * @dataProvider dataTestUpdate
+ *
+ * @param string $fileKey
+ * @param boolean $expected
+ */
+ public function testUpdate($fileKey, $expected) {
+ $this->keyManagerMock->expects($this->once())
+ ->method('getFileKey')->willReturn($fileKey);
+
+ $this->keyManagerMock->expects($this->any())
+ ->method('getPublicKey')->willReturn('publicKey');
+
+ $this->keyManagerMock->expects($this->any())
+ ->method('addSystemKeys')
+ ->willReturnCallback(function($accessList, $publicKeys) {
+ return $publicKeys;
+ });
+
+ $this->assertSame($expected,
+ $this->instance->update('path', 'user1', ['users' => ['user1']])
);
+
}
+ public function dataTestUpdate() {
+ return array(
+ array('', false),
+ array('fileKey', true)
+ );
+ }
-} \ No newline at end of file
+}