diff options
author | Bjoern Schiessle <schiessle@owncloud.com> | 2013-12-18 17:07:35 +0100 |
---|---|---|
committer | Bjoern Schiessle <schiessle@owncloud.com> | 2013-12-18 17:07:35 +0100 |
commit | df0c1fe7f3abb0a7ec584cf64c19091bf86e1906 (patch) | |
tree | d382b17e086fbdf127fbd893e0ff00d271421ecf /apps | |
parent | f9ec3a71242a5a53c440094d42a75c9fa6f04223 (diff) | |
download | nextcloud-server-df0c1fe7f3abb0a7ec584cf64c19091bf86e1906.tar.gz nextcloud-server-df0c1fe7f3abb0a7ec584cf64c19091bf86e1906.zip |
add test for the stream wrapper to read encrypted files from the system folder /tmp
Diffstat (limited to 'apps')
-rw-r--r-- | apps/files_encryption/tests/stream.php | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/apps/files_encryption/tests/stream.php b/apps/files_encryption/tests/stream.php index 530ee3a7b2d..2767bbe512b 100644 --- a/apps/files_encryption/tests/stream.php +++ b/apps/files_encryption/tests/stream.php @@ -180,4 +180,43 @@ class Test_Encryption_Stream extends \PHPUnit_Framework_TestCase { // tear down $view->unlink($filename); } + + /** + * @medium + * @brief test if stream wrapper can read files outside from the data folder + */ + function testStreamFromLocalFile() { + + $filename = '/' . $this->userId . '/files/' . 'tmp-' . time().'.txt'; + + $tmpFilename = "/tmp/" . time() . ".txt"; + + // write an encrypted file + $cryptedFile = $this->view->file_put_contents($filename, $this->dataShort); + + // Test that data was successfully written + $this->assertTrue(is_int($cryptedFile)); + + // create a copy outside of the data folder in /tmp + $proxyStatus = \OC_FileProxy::$enabled; + \OC_FileProxy::$enabled = false; + $encryptedContent = $this->view->file_get_contents($filename); + \OC_FileProxy::$enabled = $proxyStatus; + + file_put_contents($tmpFilename, $encryptedContent); + + \OCA\Encryption\Helper::addTmpFileToMapper($tmpFilename, $filename); + + // try to read the file from /tmp + $handle = fopen("crypt://".$tmpFilename, "r"); + $contentFromTmpFile = stream_get_contents($handle); + + // check if it was successful + $this->assertEquals($this->dataShort, $contentFromTmpFile); + + // clean up + unlink($tmpFilename); + $this->view->unlink($filename); + + } } |