From 2df376367582edfbbfb98f8fe9837c5b57e5ad0c Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Thu, 14 Nov 2013 12:11:21 +0100 Subject: [PATCH] test encryptAll() and decryptAll() to make sure that mtime and etag stay the same --- apps/files_encryption/tests/util.php | 64 ++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/apps/files_encryption/tests/util.php b/apps/files_encryption/tests/util.php index 1b93bc36c8..0f21ed96e4 100755 --- a/apps/files_encryption/tests/util.php +++ b/apps/files_encryption/tests/util.php @@ -281,6 +281,70 @@ class Test_Encryption_Util extends \PHPUnit_Framework_TestCase { $this->assertFalse($this->util->isSharedPath($path)); } + function testEncryptAll() { + + $filename = "/encryptAll" . time() . ".txt"; + $util = new Encryption\Util($this->view, $this->userId); + + // disable encryption to upload a unencrypted file + \OC_App::disable('files_encryption'); + + $this->view->file_put_contents($this->userId . '/files/' . $filename, $this->dataShort); + + $fileInfoUnencrypted = $this->view->getFileInfo($this->userId . '/files/' . $filename); + + $this->assertTrue(is_array($fileInfoUnencrypted)); + + // enable file encryption again + \OC_App::enable('files_encryption'); + + // encrypt all unencrypted files + $util->encryptAll('/' . $this->userId . '/' . 'files'); + + $fileInfoEncrypted = $this->view->getFileInfo($this->userId . '/files/' . $filename); + + $this->assertTrue(is_array($fileInfoEncrypted)); + + // check if mtime and etags unchanged + $this->assertEquals($fileInfoEncrypted['mtime'], $fileInfoUnencrypted['mtime']); + $this->assertEquals($fileInfoEncrypted['etag'], $fileInfoUnencrypted['etag']); + + $this->view->unlink($this->userId . '/files/' . $filename); + } + + + function testDecryptAll() { + + $filename = "/decryptAll" . time() . ".txt"; + $util = new Encryption\Util($this->view, $this->userId); + + $this->view->file_put_contents($this->userId . '/files/' . $filename, $this->dataShort); + + $fileInfoEncrypted = $this->view->getFileInfo($this->userId . '/files/' . $filename); + + print("\n File Info Encrypted\n"); + print_r($fileInfoEncrypted); + + $this->assertTrue(is_array($fileInfoEncrypted)); + + // encrypt all unencrypted files + $util->decryptAll('/' . $this->userId . '/' . 'files'); + + $fileInfoUnencrypted = $this->view->getFileInfo($this->userId . '/files/' . $filename); + + print("\n File Info Unencrypted\n"); + print_r($fileInfoUnencrypted); + + $this->assertTrue(is_array($fileInfoUnencrypted)); + + // check if mtime and etags unchanged + $this->assertEquals($fileInfoEncrypted['mtime'], $fileInfoUnencrypted['mtime']); + $this->assertEquals($fileInfoEncrypted['etag'], $fileInfoUnencrypted['etag']); + + $this->view->unlink($this->userId . '/files/' . $filename); + + } + /** * @large */