summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorThomas Müller <thomas.mueller@tmit.eu>2015-09-18 14:54:06 +0200
committerThomas Müller <thomas.mueller@tmit.eu>2015-09-18 14:54:06 +0200
commitd62cffbc9a47839ae922c8c06a6cc25008ff5ec5 (patch)
treec96784c20dd286495dff40adaa533d2cb6f85bcc /tests
parent101fe59ce2822652b59383699626b14024b45553 (diff)
parent485ea316a196e86e547eab622e4ed522c4b52588 (diff)
downloadnextcloud-server-d62cffbc9a47839ae922c8c06a6cc25008ff5ec5.tar.gz
nextcloud-server-d62cffbc9a47839ae922c8c06a6cc25008ff5ec5.zip
Merge pull request #18901 from owncloud/encryption-dav-tests
Add tests for doing dav requests with encryption enabled
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/connector/sabre/requesttest/encryptionuploadtest.php25
-rw-r--r--tests/lib/connector/sabre/requesttest/requesttest.php3
-rw-r--r--tests/lib/connector/sabre/requesttest/uploadtest.php14
-rw-r--r--tests/lib/traits/encryptiontrait.php104
-rw-r--r--tests/lib/traits/mountprovidertrait.php6
5 files changed, 143 insertions, 9 deletions
diff --git a/tests/lib/connector/sabre/requesttest/encryptionuploadtest.php b/tests/lib/connector/sabre/requesttest/encryptionuploadtest.php
new file mode 100644
index 00000000000..f1849c94760
--- /dev/null
+++ b/tests/lib/connector/sabre/requesttest/encryptionuploadtest.php
@@ -0,0 +1,25 @@
+<?php
+/**
+ * Copyright (c) 2015 Robin Appelman <icewind@owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+namespace Test\Connector\Sabre\RequestTest;
+
+use OC\Files\View;
+use Test\Traits\EncryptionTrait;
+
+class EncryptionUploadTest extends UploadTest {
+ use EncryptionTrait;
+
+ protected function setupUser($name, $password) {
+ $this->createUser($name, $password);
+ $tmpFolder = \OC::$server->getTempManager()->getTemporaryFolder();
+ $this->registerMount($name, '\OC\Files\Storage\Local', '/' . $name, ['datadir' => $tmpFolder]);
+ $this->setupForUser($name, $password);
+ $this->loginWithEncryption($name);
+ return new View('/' . $name . '/files');
+ }
+}
diff --git a/tests/lib/connector/sabre/requesttest/requesttest.php b/tests/lib/connector/sabre/requesttest/requesttest.php
index 7afe2645037..4d4c8173caa 100644
--- a/tests/lib/connector/sabre/requesttest/requesttest.php
+++ b/tests/lib/connector/sabre/requesttest/requesttest.php
@@ -52,7 +52,8 @@ abstract class RequestTest extends TestCase {
protected function setupUser($name, $password) {
$this->createUser($name, $password);
- $this->registerMount($name, '\OC\Files\Storage\Temporary', '/' . $name);
+ $tmpFolder = \OC::$server->getTempManager()->getTemporaryFolder();
+ $this->registerMount($name, '\OC\Files\Storage\Local', '/' . $name, ['datadir' => $tmpFolder]);
$this->loginAsUser($name);
return new View('/' . $name . '/files');
}
diff --git a/tests/lib/connector/sabre/requesttest/uploadtest.php b/tests/lib/connector/sabre/requesttest/uploadtest.php
index b8cd44afda7..8f39aff81b9 100644
--- a/tests/lib/connector/sabre/requesttest/uploadtest.php
+++ b/tests/lib/connector/sabre/requesttest/uploadtest.php
@@ -8,6 +8,8 @@
namespace Test\Connector\Sabre\RequestTest;
+use OC\AppFramework\Http;
+
class UploadTest extends RequestTest {
public function testBasicUpload() {
$user = $this->getUniqueID();
@@ -16,7 +18,7 @@ class UploadTest extends RequestTest {
$this->assertFalse($view->file_exists('foo.txt'));
$response = $this->request($view, $user, 'pass', 'PUT', '/foo.txt', 'asd');
- $this->assertEquals(201, $response->getStatus());
+ $this->assertEquals(Http::STATUS_CREATED, $response->getStatus());
$this->assertTrue($view->file_exists('foo.txt'));
$this->assertEquals('asd', $view->file_get_contents('foo.txt'));
@@ -33,7 +35,7 @@ class UploadTest extends RequestTest {
$response = $this->request($view, $user, 'pass', 'PUT', '/foo.txt', 'asd');
- $this->assertEquals(204, $response->getStatus());
+ $this->assertEquals(Http::STATUS_NO_CONTENT, $response->getStatus());
$this->assertEquals('asd', $view->file_get_contents('foo.txt'));
$info = $view->getFileInfo('foo.txt');
@@ -53,7 +55,7 @@ class UploadTest extends RequestTest {
$response = $this->request($view, $user, 'pass', 'PUT', '/foo.txt-chunking-123-2-1', 'bar', ['OC-Chunked' => '1']);
- $this->assertEquals(201, $response->getStatus());
+ $this->assertEquals(Http::STATUS_CREATED, $response->getStatus());
$this->assertTrue($view->file_exists('foo.txt'));
$this->assertEquals('asdbar', $view->file_get_contents('foo.txt'));
@@ -70,12 +72,12 @@ class UploadTest extends RequestTest {
$view->file_put_contents('foo.txt', 'bar');
$response = $this->request($view, $user, 'pass', 'PUT', '/foo.txt-chunking-123-2-0', 'asd', ['OC-Chunked' => '1']);
- $this->assertEquals(201, $response->getStatus());
+ $this->assertEquals(Http::STATUS_CREATED, $response->getStatus());
$this->assertEquals('bar', $view->file_get_contents('foo.txt'));
$response = $this->request($view, $user, 'pass', 'PUT', '/foo.txt-chunking-123-2-1', 'bar', ['OC-Chunked' => '1']);
- $this->assertEquals(201, $response->getStatus());
+ $this->assertEquals(Http::STATUS_CREATED, $response->getStatus());
$this->assertEquals('asdbar', $view->file_get_contents('foo.txt'));
@@ -91,7 +93,7 @@ class UploadTest extends RequestTest {
$this->assertFalse($view->file_exists('foo.txt'));
$response = $this->request($view, $user, 'pass', 'PUT', '/foo.txt-chunking-123-2-1', 'bar', ['OC-Chunked' => '1']);
- $this->assertEquals(201, $response->getStatus());
+ $this->assertEquals(Http::STATUS_CREATED, $response->getStatus());
$this->assertFalse($view->file_exists('foo.txt'));
$response = $this->request($view, $user, 'pass', 'PUT', '/foo.txt-chunking-123-2-0', 'asd', ['OC-Chunked' => '1']);
diff --git a/tests/lib/traits/encryptiontrait.php b/tests/lib/traits/encryptiontrait.php
new file mode 100644
index 00000000000..92ba3734873
--- /dev/null
+++ b/tests/lib/traits/encryptiontrait.php
@@ -0,0 +1,104 @@
+<?php
+/**
+ * Copyright (c) 2015 Robin Appelman <icewind@owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+namespace Test\Traits;
+
+use OC\Encryption\Util;
+use OC\Files\View;
+use OCA\Encryption\AppInfo\Application;
+use OCA\Encryption\KeyManager;
+use OCA\Encryption\Users\Setup;
+use OC\Files\Filesystem;
+
+/**
+ * Enables encryption
+ */
+trait EncryptionTrait {
+ // from MountProviderTrait
+ abstract protected function registerStorageWrapper($name, $wrapper);
+
+ // from phpunit
+ abstract protected function markTestSkipped($reason = '');
+ abstract protected function assertTrue($condition, $message = '');
+
+ private $encryptionWasEnabled;
+
+ private $originalEncryptionModule;
+
+ /**
+ * @var \OCP\IConfig
+ */
+ private $config;
+
+ /**
+ * @var \OCA\Encryption\AppInfo\Application
+ */
+ private $encryptionApp;
+
+ protected function loginWithEncryption($user = '') {
+ \OC_Util::tearDownFS();
+ \OC_User::setUserId('');
+ // needed for fully logout
+ \OC::$server->getUserSession()->setUser(null);
+
+ Filesystem::tearDown();
+ \OC_User::setUserId($user);
+ $this->postLogin();
+ \OC_Util::setupFS($user);
+ if (\OC_User::userExists($user)) {
+ \OC::$server->getUserFolder($user);
+ }
+ }
+
+ protected function setupForUser($name, $password) {
+ \OC_Util::tearDownFS();
+ \OC_Util::setupFS($name);
+ $container = $this->encryptionApp->getContainer();
+ /** @var KeyManager $keyManager */
+ $keyManager = $container->query('KeyManager');
+ /** @var Setup $userSetup */
+ $userSetup = $container->query('UserSetup');
+ $userSetup->setupServerSide($name, $password);
+ $keyManager->init($name, $password);
+ }
+
+ protected function postLogin() {
+ $util = new Util(
+ new View(),
+ \OC::$server->getUserManager(),
+ \OC::$server->getGroupManager(),
+ \OC::$server->getConfig()
+ );
+ $this->registerStorageWrapper('oc_encryption', array($util, 'wrapStorage'));
+ }
+
+ protected function setUpEncryptionTrait() {
+ $isReady = \OC::$server->getEncryptionManager()->isReady();
+ if (!$isReady) {
+ $this->markTestSkipped('Encryption not ready');
+ }
+
+ \OC_App::loadApp('encryption');
+
+ $this->encryptionApp = new Application([], $isReady);
+
+ $this->config = \OC::$server->getConfig();
+ $this->encryptionWasEnabled = $this->config->getAppValue('core', 'encryption_enabled', 'no');
+ $this->originalEncryptionModule = $this->config->getAppValue('core', 'default_encryption_module');
+ $this->config->setAppValue('core', 'default_encryption_module', \OCA\Encryption\Crypto\Encryption::ID);
+ $this->config->setAppValue('core', 'encryption_enabled', 'yes');
+ $this->assertTrue(\OC::$server->getEncryptionManager()->isEnabled());
+ }
+
+ protected function tearDownEncryptionTrait() {
+ if ($this->config) {
+ $this->config->setAppValue('core', 'encryption_enabled', $this->encryptionWasEnabled);
+ $this->config->setAppValue('core', 'default_encryption_module', $this->originalEncryptionModule);
+ }
+ }
+}
diff --git a/tests/lib/traits/mountprovidertrait.php b/tests/lib/traits/mountprovidertrait.php
index 66eca1597c8..bccb5b693ee 100644
--- a/tests/lib/traits/mountprovidertrait.php
+++ b/tests/lib/traits/mountprovidertrait.php
@@ -32,7 +32,7 @@ trait MountProviderTrait {
if (!isset($this->mounts[$userId])) {
$this->mounts[$userId] = [];
}
- $this->mounts[$userId][] = new MountPoint($storage, $mountPoint, $arguments, $this->storageFactory);
+ $this->mounts[$userId][] = ['storage' => $storage, 'mountPoint' => $mountPoint, 'arguments' => $arguments];
}
protected function registerStorageWrapper($name, $wrapper) {
@@ -46,7 +46,9 @@ trait MountProviderTrait {
->method('getMountsForUser')
->will($this->returnCallback(function (IUser $user) {
if (isset($this->mounts[$user->getUID()])) {
- return $this->mounts[$user->getUID()];
+ return array_map(function ($config) {
+ return new MountPoint($config['storage'], $config['mountPoint'], $config['arguments'], $this->storageFactory);
+ }, $this->mounts[$user->getUID()]);
} else {
return [];
}