]> source.dussan.org Git - nextcloud-server.git/commitdiff
add test for the stream wrapper to read encrypted files from the system folder /tmp
authorBjoern Schiessle <schiessle@owncloud.com>
Wed, 18 Dec 2013 16:07:35 +0000 (17:07 +0100)
committerBjoern Schiessle <schiessle@owncloud.com>
Wed, 18 Dec 2013 16:07:35 +0000 (17:07 +0100)
apps/files_encryption/tests/stream.php

index 530ee3a7b2d25c05fd5a827cba8662a973113856..2767bbe512bd096dc1e113aa0540fbde36438c27 100644 (file)
@@ -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);
+
+       }
 }