[Pkg-owncloud-commits] [owncloud] 24/103: fix unit tests
David Prévot
taffit at moszumanska.debian.org
Sun May 31 12:32:34 UTC 2015
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to annotated tag v8.0.4RC1
in repository owncloud.
commit 15f54c263e7b1205ec55b3eb0d432d1639a683a3
Author: Morris Jobke <hey at morrisjobke.de>
Date: Wed Apr 22 13:55:55 2015 +0200
fix unit tests
---
apps/files/tests/service/tagservice.php | 2 +-
apps/files_encryption/lib/util.php | 11 +++++++++--
apps/files_encryption/tests/hooks.php | 24 +++++++++++++++---------
tests/lib/preview.php | 4 ++--
4 files changed, 27 insertions(+), 14 deletions(-)
diff --git a/apps/files/tests/service/tagservice.php b/apps/files/tests/service/tagservice.php
index 158dd77..322a940 100644
--- a/apps/files/tests/service/tagservice.php
+++ b/apps/files/tests/service/tagservice.php
@@ -65,7 +65,7 @@ class TagServiceTest extends \Test\TestCase {
->withAnyParameters()
->will($this->returnValue($user));
- $this->root = \OC::$server->getUserFolder();
+ $this->root = \OC::$server->getUserFolder($this->user);
$this->tagger = \OC::$server->getTagManager()->load('files');
$this->tagService = new TagService(
diff --git a/apps/files_encryption/lib/util.php b/apps/files_encryption/lib/util.php
index 14d0a0b..106ed3b 100644
--- a/apps/files_encryption/lib/util.php
+++ b/apps/files_encryption/lib/util.php
@@ -24,6 +24,7 @@
*/
namespace OCA\Files_Encryption;
+use OC\User\NoUserException;
/**
* Class for utilities relating to encrypted file storage system
@@ -945,8 +946,14 @@ class Util {
) {
return true;
}
- $util = new Util($this->view, $user);
- return $util->ready();
+ try {
+ $util = new Util($this->view, $user);
+ return $util->ready();
+ } catch (NoUserException $e) {
+ \OCP\Util::writeLog('Encryption library',
+ 'No User object for '.$user, \OCP\Util::DEBUG);
+ return false;
+ }
}
/**
diff --git a/apps/files_encryption/tests/hooks.php b/apps/files_encryption/tests/hooks.php
index 7c60024..755573e 100644
--- a/apps/files_encryption/tests/hooks.php
+++ b/apps/files_encryption/tests/hooks.php
@@ -30,6 +30,7 @@ class Hooks extends TestCase {
const TEST_ENCRYPTION_HOOKS_USER1 = "test-encryption-hooks-user1.dot";
const TEST_ENCRYPTION_HOOKS_USER2 = "test-encryption-hooks-user2.dot";
+ const TEST_ENCRYPTION_HOOKS_USER3 = "test-encryption-hooks-user3.dot";
/** @var \OC\Files\View */
public $user1View; // view on /data/user1/files
@@ -91,6 +92,7 @@ class Hooks extends TestCase {
// cleanup test user
\OC_User::deleteUser(self::TEST_ENCRYPTION_HOOKS_USER1);
\OC_User::deleteUser(self::TEST_ENCRYPTION_HOOKS_USER2);
+ \OC_User::deleteUser(self::TEST_ENCRYPTION_HOOKS_USER3);
parent::tearDownAfterClass();
}
@@ -407,31 +409,35 @@ class Hooks extends TestCase {
$view = new \OC\Files\View();
// set user password for the first time
- \OCA\Files_Encryption\Hooks::postCreateUser(array('uid' => 'newUser', 'password' => 'newUserPassword'));
+ \OC_User::createUser(self::TEST_ENCRYPTION_HOOKS_USER3, 'newUserPassword');
+ \OCA\Files_Encryption\Hooks::postCreateUser(array(
+ 'uid' => self::TEST_ENCRYPTION_HOOKS_USER3,
+ 'password' => 'newUserPassword')
+ );
- $this->assertTrue($view->file_exists(\OCA\Files_Encryption\Keymanager::getPublicKeyPath() . '/newUser.publicKey'));
- $this->assertTrue($view->file_exists('newUser/files_encryption/newUser.privateKey'));
+ $this->assertTrue($view->file_exists(\OCA\Files_Encryption\Keymanager::getPublicKeyPath() . '/'.self::TEST_ENCRYPTION_HOOKS_USER3.'.publicKey'));
+ $this->assertTrue($view->file_exists(self::TEST_ENCRYPTION_HOOKS_USER3.'/files_encryption/'.self::TEST_ENCRYPTION_HOOKS_USER3.'.privateKey'));
// check if we are able to decrypt the private key
- $encryptedKey = \OCA\Files_Encryption\Keymanager::getPrivateKey($view, 'newUser');
+ $encryptedKey = \OCA\Files_Encryption\Keymanager::getPrivateKey($view, self::TEST_ENCRYPTION_HOOKS_USER3);
$privateKey = \OCA\Files_Encryption\Crypt::decryptPrivateKey($encryptedKey, 'newUserPassword');
$this->assertTrue(is_string($privateKey));
// change the password before the user logged-in for the first time,
// we can replace the encryption keys
- \OCA\Files_Encryption\Hooks::setPassphrase(array('uid' => 'newUser', 'password' => 'passwordChanged'));
+ \OCA\Files_Encryption\Hooks::setPassphrase(array('uid' => self::TEST_ENCRYPTION_HOOKS_USER3, 'password' => 'passwordChanged'));
- $encryptedKey = \OCA\Files_Encryption\Keymanager::getPrivateKey($view, 'newUser');
+ $encryptedKey = \OCA\Files_Encryption\Keymanager::getPrivateKey($view, self::TEST_ENCRYPTION_HOOKS_USER3);
$privateKey = \OCA\Files_Encryption\Crypt::decryptPrivateKey($encryptedKey, 'passwordChanged');
$this->assertTrue(is_string($privateKey));
// now create a files folder to simulate a already used account
- $view->mkdir('/newUser/files');
+ $view->mkdir('/'.self::TEST_ENCRYPTION_HOOKS_USER3.'/files');
// change the password after the user logged in, now the password should not change
- \OCA\Files_Encryption\Hooks::setPassphrase(array('uid' => 'newUser', 'password' => 'passwordChanged2'));
+ \OCA\Files_Encryption\Hooks::setPassphrase(array('uid' => self::TEST_ENCRYPTION_HOOKS_USER3, 'password' => 'passwordChanged2'));
- $encryptedKey = \OCA\Files_Encryption\Keymanager::getPrivateKey($view, 'newUser');
+ $encryptedKey = \OCA\Files_Encryption\Keymanager::getPrivateKey($view, self::TEST_ENCRYPTION_HOOKS_USER3);
$privateKey = \OCA\Files_Encryption\Crypt::decryptPrivateKey($encryptedKey, 'passwordChanged2');
$this->assertFalse($privateKey);
diff --git a/tests/lib/preview.php b/tests/lib/preview.php
index 8323387..c7a58f8 100644
--- a/tests/lib/preview.php
+++ b/tests/lib/preview.php
@@ -104,11 +104,11 @@ class Preview extends TestCase {
\OC_Config::setValue('preview_max_x', $maxX);
\OC_Config::setValue('preview_max_y', $maxY);
- $sampleFile = '/'.$this->user.'/files/test.txt';
+ $sampleFile = '/'.self::TEST_PREVIEW_USER1.'/files/test.txt';
$this->rootView->file_put_contents($sampleFile, 'dummy file data');
- $preview = new \OC\Preview($this->user, 'files/', 'test.txt', 1000, 1000);
+ $preview = new \OC\Preview(self::TEST_PREVIEW_USER1, 'files/', 'test.txt', 1000, 1000);
$image = $preview->getPreview();
$this->assertEquals($image->width(), $maxX);
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud.git
More information about the Pkg-owncloud-commits
mailing list