]> source.dussan.org Git - nextcloud-server.git/commitdiff
test for isEncryptedPath()
authorBjoern Schiessle <schiessle@owncloud.com>
Wed, 18 Dec 2013 15:39:34 +0000 (16:39 +0100)
committerBjoern Schiessle <schiessle@owncloud.com>
Wed, 18 Dec 2013 15:39:34 +0000 (16:39 +0100)
apps/files_encryption/tests/util.php

index e8dfb74f3f398c12022ae7dc0a671f30453fbf18..7d425dc122ac38657781b3450cb8451906e6293f 100755 (executable)
@@ -132,6 +132,41 @@ class Test_Encryption_Util extends \PHPUnit_Framework_TestCase {
 
        }
 
+       /**
+        * @medium
+        * @brief test detection of encrypted files
+        */
+       function testIsEncryptedPath() {
+
+               $util = new Encryption\Util($this->view, $this->userId);
+
+               self::loginHelper($this->userId);
+
+               $unencryptedFile = '/tmpUnencrypted-' . time() . '.txt';
+               $encryptedFile =  '/tmpEncrypted-' . time() . '.txt';
+
+               // Disable encryption proxy to write a unencrypted file
+               $proxyStatus = \OC_FileProxy::$enabled;
+               \OC_FileProxy::$enabled = false;
+
+               $this->view->file_put_contents($this->userId . '/files/' . $unencryptedFile, $this->dataShort);
+
+               // Re-enable proxy - our work is done
+               \OC_FileProxy::$enabled = $proxyStatus;
+
+               // write a encrypted file
+               $this->view->file_put_contents($this->userId . '/files/' . $encryptedFile, $this->dataShort);
+
+               // test if both files are detected correctly
+               $this->assertFalse($util->isEncryptedPath($this->userId . '/files/' . $unencryptedFile));
+               $this->assertTrue($util->isEncryptedPath($this->userId . '/files/' . $encryptedFile));
+
+               // cleanup
+               $this->view->unlink($this->userId . '/files/' . $unencryptedFile, $this->dataShort);
+               $this->view->unlink($this->userId . '/files/' . $encryptedFile, $this->dataShort);
+
+       }
+
        /**
         * @medium
         * @brief test setup of encryption directories