summaryrefslogtreecommitdiffstats
path: root/apps/files_encryption/tests/stream.php
diff options
context:
space:
mode:
Diffstat (limited to 'apps/files_encryption/tests/stream.php')
-rw-r--r--apps/files_encryption/tests/stream.php47
1 files changed, 43 insertions, 4 deletions
diff --git a/apps/files_encryption/tests/stream.php b/apps/files_encryption/tests/stream.php
index 530ee3a7b2d..fed2e7d89d1 100644
--- a/apps/files_encryption/tests/stream.php
+++ b/apps/files_encryption/tests/stream.php
@@ -99,7 +99,7 @@ class Test_Encryption_Stream extends \PHPUnit_Framework_TestCase {
}
function testStreamOptions() {
- $filename = '/tmp-' . time();
+ $filename = '/tmp-' . uniqid();
$view = new \OC\Files\View('/' . $this->userId . '/files');
// Save short data as encrypted file using stream wrapper
@@ -122,7 +122,7 @@ class Test_Encryption_Stream extends \PHPUnit_Framework_TestCase {
}
function testStreamSetBlocking() {
- $filename = '/tmp-' . time();
+ $filename = '/tmp-' . uniqid();
$view = new \OC\Files\View('/' . $this->userId . '/files');
// Save short data as encrypted file using stream wrapper
@@ -144,7 +144,7 @@ class Test_Encryption_Stream extends \PHPUnit_Framework_TestCase {
* @medium
*/
function testStreamSetTimeout() {
- $filename = '/tmp-' . time();
+ $filename = '/tmp-' . uniqid();
$view = new \OC\Files\View('/' . $this->userId . '/files');
// Save short data as encrypted file using stream wrapper
@@ -163,7 +163,7 @@ class Test_Encryption_Stream extends \PHPUnit_Framework_TestCase {
}
function testStreamSetWriteBuffer() {
- $filename = '/tmp-' . time();
+ $filename = '/tmp-' . uniqid();
$view = new \OC\Files\View('/' . $this->userId . '/files');
// Save short data as encrypted file using stream wrapper
@@ -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-' . uniqid().'.txt';
+
+ $tmpFilename = "/tmp/" . uniqid() . ".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);
+
+ }
}