Merge pull request #15489 from owncloud/dont_hide_exceptions_master
Dont hide exceptions master
This commit is contained in:
commit
7b2d53603c
|
@ -30,8 +30,10 @@
|
|||
|
||||
namespace OCA\user_ldap\lib;
|
||||
|
||||
//magic properties (incomplete)
|
||||
use OC\ServerNotAvailableException;
|
||||
|
||||
/**
|
||||
* magic properties (incomplete)
|
||||
* responsible for LDAP connections in context with the provided configuration
|
||||
*
|
||||
* @property string ldapUserFilter
|
||||
|
@ -54,7 +56,7 @@ class Connection extends LDAPUtility {
|
|||
//cache handler
|
||||
protected $cache;
|
||||
|
||||
//settings handler
|
||||
/** @var Configuration settings handler **/
|
||||
protected $configuration;
|
||||
|
||||
protected $doNotValidate = false;
|
||||
|
@ -167,7 +169,8 @@ class Connection extends LDAPUtility {
|
|||
$this->establishConnection();
|
||||
}
|
||||
if(is_null($this->ldapConnectionRes)) {
|
||||
\OCP\Util::writeLog('user_ldap', 'Connection could not be established', \OCP\Util::ERROR);
|
||||
\OCP\Util::writeLog('user_ldap', 'No LDAP Connection to server ' . $this->configuration->ldapHost, \OCP\Util::ERROR);
|
||||
throw new ServerNotAvailableException('Connection to LDAP server could not be established');
|
||||
}
|
||||
return $this->ldapConnectionRes;
|
||||
}
|
||||
|
|
|
@ -149,6 +149,11 @@ class Manager {
|
|||
$this->access->getUserMapper());
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief returns a User object by it's ownCloud username
|
||||
* @param string the DN or username of the user
|
||||
* @return \OCA\user_ldap\lib\user\User|\OCA\user_ldap\lib\user\OfflineUser|null
|
||||
*/
|
||||
protected function createInstancyByUserName($id) {
|
||||
//most likely a uid. Check whether it is a deleted user
|
||||
if($this->isDeletedUser($id)) {
|
||||
|
@ -158,13 +163,14 @@ class Manager {
|
|||
if($dn !== false) {
|
||||
return $this->createAndCache($dn, $id);
|
||||
}
|
||||
throw new \Exception('Could not create User instance');
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief returns a User object by it's DN or ownCloud username
|
||||
* @param string the DN or username of the user
|
||||
* @return \OCA\user_ldap\lib\user\User|\OCA\user_ldap\lib\user\OfflineUser|null
|
||||
* @throws \Exception when connection could not be established
|
||||
*/
|
||||
public function get($id) {
|
||||
$this->checkAccess();
|
||||
|
@ -181,12 +187,7 @@ class Manager {
|
|||
}
|
||||
}
|
||||
|
||||
try {
|
||||
$user = $this->createInstancyByUserName($id);
|
||||
return $user;
|
||||
} catch (\Exception $e) {
|
||||
return null;
|
||||
}
|
||||
return $this->createInstancyByUserName($id);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -417,21 +417,53 @@ class Test_User_Ldap_Direct extends \Test\TestCase {
|
|||
$this->prepareMockForUserExists($access);
|
||||
|
||||
$access->expects($this->any())
|
||||
->method('readAttribute')
|
||||
->will($this->returnCallback(function($dn) {
|
||||
if($dn === 'dnOfRoland,dc=test') {
|
||||
return array();
|
||||
}
|
||||
return false;
|
||||
}));
|
||||
->method('readAttribute')
|
||||
->will($this->returnCallback(function($dn) {
|
||||
if($dn === 'dnOfRoland,dc=test') {
|
||||
return array();
|
||||
}
|
||||
return false;
|
||||
}));
|
||||
|
||||
//test for existing user
|
||||
$result = $backend->userExists('gunslinger');
|
||||
$this->assertTrue($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Exception
|
||||
*/
|
||||
public function testUserExistsForDeleted() {
|
||||
$access = $this->getAccessMock();
|
||||
$backend = new UserLDAP($access, $this->getMock('\OCP\IConfig'));
|
||||
$this->prepareMockForUserExists($access);
|
||||
|
||||
$access->expects($this->any())
|
||||
->method('readAttribute')
|
||||
->will($this->returnCallback(function($dn) {
|
||||
if($dn === 'dnOfRoland,dc=test') {
|
||||
return array();
|
||||
}
|
||||
return false;
|
||||
}));
|
||||
|
||||
//test for deleted user
|
||||
$result = $backend->userExists('formerUser');
|
||||
$this->assertFalse($result);
|
||||
}
|
||||
|
||||
public function testUserExistsForNeverExisting() {
|
||||
$access = $this->getAccessMock();
|
||||
$backend = new UserLDAP($access, $this->getMock('\OCP\IConfig'));
|
||||
$this->prepareMockForUserExists($access);
|
||||
|
||||
$access->expects($this->any())
|
||||
->method('readAttribute')
|
||||
->will($this->returnCallback(function($dn) {
|
||||
if($dn === 'dnOfRoland,dc=test') {
|
||||
return array();
|
||||
}
|
||||
return false;
|
||||
}));
|
||||
|
||||
//test for never-existing user
|
||||
$result = $backend->userExists('mallory');
|
||||
|
@ -445,21 +477,55 @@ class Test_User_Ldap_Direct extends \Test\TestCase {
|
|||
\OC_User::useBackend($backend);
|
||||
|
||||
$access->expects($this->any())
|
||||
->method('readAttribute')
|
||||
->will($this->returnCallback(function($dn) {
|
||||
if($dn === 'dnOfRoland,dc=test') {
|
||||
return array();
|
||||
}
|
||||
return false;
|
||||
}));
|
||||
->method('readAttribute')
|
||||
->will($this->returnCallback(function($dn) {
|
||||
if($dn === 'dnOfRoland,dc=test') {
|
||||
return array();
|
||||
}
|
||||
return false;
|
||||
}));
|
||||
|
||||
//test for existing user
|
||||
$result = \OCP\User::userExists('gunslinger');
|
||||
$this->assertTrue($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Exception
|
||||
*/
|
||||
public function testUserExistsPublicAPIForDeleted() {
|
||||
$access = $this->getAccessMock();
|
||||
$backend = new UserLDAP($access, $this->getMock('\OCP\IConfig'));
|
||||
$this->prepareMockForUserExists($access);
|
||||
\OC_User::useBackend($backend);
|
||||
|
||||
$access->expects($this->any())
|
||||
->method('readAttribute')
|
||||
->will($this->returnCallback(function($dn) {
|
||||
if($dn === 'dnOfRoland,dc=test') {
|
||||
return array();
|
||||
}
|
||||
return false;
|
||||
}));
|
||||
|
||||
//test for deleted user
|
||||
$result = \OCP\User::userExists('formerUser');
|
||||
$this->assertFalse($result);
|
||||
}
|
||||
|
||||
public function testUserExistsPublicAPIForNeverExisting() {
|
||||
$access = $this->getAccessMock();
|
||||
$backend = new UserLDAP($access, $this->getMock('\OCP\IConfig'));
|
||||
$this->prepareMockForUserExists($access);
|
||||
\OC_User::useBackend($backend);
|
||||
|
||||
$access->expects($this->any())
|
||||
->method('readAttribute')
|
||||
->will($this->returnCallback(function($dn) {
|
||||
if($dn === 'dnOfRoland,dc=test') {
|
||||
return array();
|
||||
}
|
||||
return false;
|
||||
}));
|
||||
|
||||
//test for never-existing user
|
||||
$result = \OCP\User::userExists('mallory');
|
||||
|
@ -475,54 +541,105 @@ class Test_User_Ldap_Direct extends \Test\TestCase {
|
|||
$this->assertFalse($result);
|
||||
}
|
||||
|
||||
public function testGetHome() {
|
||||
public function testGetHomeAbsolutePath() {
|
||||
$access = $this->getAccessMock();
|
||||
$config = $this->getMock('\OCP\IConfig');
|
||||
$backend = new UserLDAP($access, $config);
|
||||
$this->prepareMockForUserExists($access);
|
||||
|
||||
$access->connection->expects($this->any())
|
||||
->method('__get')
|
||||
->will($this->returnCallback(function($name) {
|
||||
if($name === 'homeFolderNamingRule') {
|
||||
return 'attr:testAttribute';
|
||||
}
|
||||
return null;
|
||||
}));
|
||||
->method('__get')
|
||||
->will($this->returnCallback(function($name) {
|
||||
if($name === 'homeFolderNamingRule') {
|
||||
return 'attr:testAttribute';
|
||||
}
|
||||
return null;
|
||||
}));
|
||||
|
||||
$access->expects($this->any())
|
||||
->method('readAttribute')
|
||||
->will($this->returnCallback(function($dn, $attr) {
|
||||
switch ($dn) {
|
||||
case 'dnOfRoland,dc=test':
|
||||
if($attr === 'testAttribute') {
|
||||
return array('/tmp/rolandshome/');
|
||||
}
|
||||
return array();
|
||||
break;
|
||||
case 'dnOfLadyOfShadows,dc=test':
|
||||
if($attr === 'testAttribute') {
|
||||
return array('susannah/');
|
||||
}
|
||||
return array();
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}));
|
||||
->method('readAttribute')
|
||||
->will($this->returnCallback(function($dn, $attr) {
|
||||
switch ($dn) {
|
||||
case 'dnOfRoland,dc=test':
|
||||
if($attr === 'testAttribute') {
|
||||
return array('/tmp/rolandshome/');
|
||||
}
|
||||
return array();
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}));
|
||||
|
||||
//absolut path
|
||||
$result = $backend->getHome('gunslinger');
|
||||
$this->assertEquals('/tmp/rolandshome/', $result);
|
||||
}
|
||||
|
||||
public function testGetHomeRelative() {
|
||||
$access = $this->getAccessMock();
|
||||
$config = $this->getMock('\OCP\IConfig');
|
||||
$backend = new UserLDAP($access, $config);
|
||||
$this->prepareMockForUserExists($access);
|
||||
|
||||
$access->connection->expects($this->any())
|
||||
->method('__get')
|
||||
->will($this->returnCallback(function($name) {
|
||||
if($name === 'homeFolderNamingRule') {
|
||||
return 'attr:testAttribute';
|
||||
}
|
||||
return null;
|
||||
}));
|
||||
|
||||
$access->expects($this->any())
|
||||
->method('readAttribute')
|
||||
->will($this->returnCallback(function($dn, $attr) {
|
||||
switch ($dn) {
|
||||
case 'dnOfLadyOfShadows,dc=test':
|
||||
if($attr === 'testAttribute') {
|
||||
return array('susannah/');
|
||||
}
|
||||
return array();
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}));
|
||||
//datadir-relativ path
|
||||
$datadir = '/my/data/dir';
|
||||
$config->expects($this->once())
|
||||
->method('getSystemValue')
|
||||
->will($this->returnValue($datadir));
|
||||
|
||||
//absolut path
|
||||
$result = $backend->getHome('gunslinger');
|
||||
$this->assertEquals('/tmp/rolandshome/', $result);
|
||||
|
||||
//datadir-relativ path
|
||||
$result = $backend->getHome('ladyofshadows');
|
||||
$this->assertEquals($datadir.'/susannah/', $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Exception
|
||||
*/
|
||||
public function testGetHomeNoPath() {
|
||||
$access = $this->getAccessMock();
|
||||
$backend = new UserLDAP($access, $this->getMock('\OCP\IConfig'));
|
||||
$this->prepareMockForUserExists($access);
|
||||
|
||||
$access->connection->expects($this->any())
|
||||
->method('__get')
|
||||
->will($this->returnCallback(function($name) {
|
||||
if($name === 'homeFolderNamingRule') {
|
||||
return 'attr:testAttribute';
|
||||
}
|
||||
return null;
|
||||
}));
|
||||
|
||||
$access->expects($this->any())
|
||||
->method('readAttribute')
|
||||
->will($this->returnCallback(function($dn, $attr) {
|
||||
switch ($dn) {
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}));
|
||||
|
||||
//no path at all – triggers OC default behaviour
|
||||
$result = $backend->getHome('newyorker');
|
||||
|
@ -562,6 +679,12 @@ class Test_User_Ldap_Direct extends \Test\TestCase {
|
|||
$backend = new UserLDAP($access, $this->getMock('\OCP\IConfig'));
|
||||
$this->prepareMockForUserExists($access);
|
||||
|
||||
$access->connection->expects($this->any())
|
||||
->method('getConnectionResource')
|
||||
->will($this->returnCallback(function() {
|
||||
return true;
|
||||
}));
|
||||
|
||||
//with displayName
|
||||
$result = $backend->getDisplayName('gunslinger');
|
||||
$this->assertEquals('Roland Deschain', $result);
|
||||
|
@ -573,9 +696,36 @@ class Test_User_Ldap_Direct extends \Test\TestCase {
|
|||
|
||||
public function testGetDisplayNamePublicAPI() {
|
||||
$access = $this->getAccessMock();
|
||||
$access->expects($this->any())
|
||||
->method('username2dn')
|
||||
->will($this->returnCallback(function($uid) {
|
||||
switch ($uid) {
|
||||
case 'gunslinger':
|
||||
return 'dnOfRoland,dc=test';
|
||||
break;
|
||||
case 'formerUser':
|
||||
return 'dnOfFormerUser,dc=test';
|
||||
break;
|
||||
case 'newyorker':
|
||||
return 'dnOfNewYorker,dc=test';
|
||||
break;
|
||||
case 'ladyofshadows':
|
||||
return 'dnOfLadyOfShadows,dc=test';
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}));
|
||||
$this->prepareAccessForGetDisplayName($access);
|
||||
$backend = new UserLDAP($access, $this->getMock('\OCP\IConfig'));
|
||||
$this->prepareMockForUserExists($access);
|
||||
|
||||
$access->connection->expects($this->any())
|
||||
->method('getConnectionResource')
|
||||
->will($this->returnCallback(function() {
|
||||
return true;
|
||||
}));
|
||||
|
||||
\OC_User::useBackend($backend);
|
||||
|
||||
//with displayName
|
||||
|
|
|
@ -190,6 +190,7 @@ class USER_LDAP extends BackendUtility implements \OCP\IUserBackend, \OCP\UserIn
|
|||
* check if a user exists
|
||||
* @param string $uid the username
|
||||
* @return boolean
|
||||
* @throws \Exception when connection could not be established
|
||||
*/
|
||||
public function userExists($uid) {
|
||||
if($this->access->connection->isCached('userExists'.$uid)) {
|
||||
|
@ -208,17 +209,12 @@ class USER_LDAP extends BackendUtility implements \OCP\IUserBackend, \OCP\UserIn
|
|||
return true;
|
||||
}
|
||||
|
||||
try {
|
||||
$result = $this->userExistsOnLDAP($user);
|
||||
$this->access->connection->writeToCache('userExists'.$uid, $result);
|
||||
if($result === true) {
|
||||
$user->update();
|
||||
}
|
||||
return $result;
|
||||
} catch (\Exception $e) {
|
||||
\OCP\Util::writeLog('user_ldap', $e->getMessage(), \OCP\Util::WARN);
|
||||
return false;
|
||||
$result = $this->userExistsOnLDAP($user);
|
||||
$this->access->connection->writeToCache('userExists'.$uid, $result);
|
||||
if($result === true) {
|
||||
$user->update();
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -499,6 +499,10 @@ OC.Share={
|
|||
} else {
|
||||
response();
|
||||
}
|
||||
}).fail(function(){
|
||||
$('#dropdown').find('.shareWithLoading').addClass('hidden');
|
||||
OC.Notification.show(t('core', 'An error occured. Please try again'));
|
||||
window.setTimeout(OC.Notification.hide, 5000);
|
||||
});
|
||||
},
|
||||
focus: function(event, focused) {
|
||||
|
|
|
@ -24,6 +24,12 @@ script('core', [
|
|||
<?php p($message); ?><br>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
<?php if (isset($_['internalexception']) && ($_['internalexception'])): ?>
|
||||
<div class="warning">
|
||||
<?php p($l->t('An internal error occured.')); ?><br>
|
||||
<small><?php p($l->t('Please try again or contact your administrator.')); ?></small>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<p id="message" class="hidden">
|
||||
<img class="float-spinner" alt=""
|
||||
src="<?php p(\OCP\Util::imagePath('core', 'loading-dark.gif'));?>">
|
||||
|
|
|
@ -967,6 +967,10 @@ class OC {
|
|||
}
|
||||
} catch (\OC\User\LoginException $e) {
|
||||
$messages[] = $e->getMessage();
|
||||
} catch (\Exception $ex) {
|
||||
\OCP\Util::logException('handleLogin', $ex);
|
||||
// do not disclose information. show generic error
|
||||
$error[] = 'internalexception';
|
||||
}
|
||||
|
||||
OC_Util::displayLoginPage(array_unique($error), $messages);
|
||||
|
|
|
@ -373,41 +373,41 @@ class Filesystem {
|
|||
|
||||
$userObject = \OC_User::getManager()->get($user);
|
||||
|
||||
if (!is_null($userObject)) {
|
||||
$homeStorage = \OC_Config::getValue( 'objectstore' );
|
||||
if (!empty($homeStorage)) {
|
||||
// sanity checks
|
||||
if (empty($homeStorage['class'])) {
|
||||
\OCP\Util::writeLog('files', 'No class given for objectstore', \OCP\Util::ERROR);
|
||||
}
|
||||
if (!isset($homeStorage['arguments'])) {
|
||||
$homeStorage['arguments'] = array();
|
||||
}
|
||||
// instantiate object store implementation
|
||||
$homeStorage['arguments']['objectstore'] = new $homeStorage['class']($homeStorage['arguments']);
|
||||
// mount with home object store implementation
|
||||
$homeStorage['class'] = '\OC\Files\ObjectStore\HomeObjectStoreStorage';
|
||||
} else {
|
||||
$homeStorage = array(
|
||||
//default home storage configuration:
|
||||
'class' => '\OC\Files\Storage\Home',
|
||||
'arguments' => array()
|
||||
);
|
||||
}
|
||||
$homeStorage['arguments']['user'] = $userObject;
|
||||
|
||||
// check for legacy home id (<= 5.0.12)
|
||||
if (\OC\Files\Cache\Storage::exists('local::' . $root . '/')) {
|
||||
$homeStorage['arguments']['legacy'] = true;
|
||||
}
|
||||
|
||||
self::mount($homeStorage['class'], $homeStorage['arguments'], $user);
|
||||
|
||||
$home = \OC\Files\Filesystem::getStorage($user);
|
||||
if (is_null($userObject)) {
|
||||
\OCP\Util::writeLog('files', ' Backends provided no user object for '.$user, \OCP\Util::ERROR);
|
||||
throw new \OC\User\NoUserException();
|
||||
}
|
||||
else {
|
||||
self::mount('\OC\Files\Storage\Local', array('datadir' => $root), $user);
|
||||
|
||||
$homeStorage = \OC_Config::getValue( 'objectstore' );
|
||||
if (!empty($homeStorage)) {
|
||||
// sanity checks
|
||||
if (empty($homeStorage['class'])) {
|
||||
\OCP\Util::writeLog('files', 'No class given for objectstore', \OCP\Util::ERROR);
|
||||
}
|
||||
if (!isset($homeStorage['arguments'])) {
|
||||
$homeStorage['arguments'] = array();
|
||||
}
|
||||
// instantiate object store implementation
|
||||
$homeStorage['arguments']['objectstore'] = new $homeStorage['class']($homeStorage['arguments']);
|
||||
// mount with home object store implementation
|
||||
$homeStorage['class'] = '\OC\Files\ObjectStore\HomeObjectStoreStorage';
|
||||
} else {
|
||||
$homeStorage = array(
|
||||
//default home storage configuration:
|
||||
'class' => '\OC\Files\Storage\Home',
|
||||
'arguments' => array()
|
||||
);
|
||||
}
|
||||
$homeStorage['arguments']['user'] = $userObject;
|
||||
|
||||
// check for legacy home id (<= 5.0.12)
|
||||
if (\OC\Files\Cache\Storage::exists('local::' . $root . '/')) {
|
||||
$homeStorage['arguments']['legacy'] = true;
|
||||
}
|
||||
|
||||
self::mount($homeStorage['class'], $homeStorage['arguments'], $user);
|
||||
|
||||
$home = \OC\Files\Filesystem::getStorage($user);
|
||||
|
||||
self::mountCacheDir($user);
|
||||
|
||||
|
|
|
@ -114,6 +114,9 @@ class OC_Hook{
|
|||
OC_Log::write('hook',
|
||||
'error while running hook (' . $class . '::' . $i["name"] . '): ' . $message,
|
||||
OC_Log::ERROR);
|
||||
if($e instanceof \OC\ServerNotAvailableException) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
<?php
|
||||
/**
|
||||
* @author Morris Jobke <hey@morrisjobke.de>
|
||||
*
|
||||
* @copyright Copyright (c) 2015, ownCloud, Inc.
|
||||
* @license AGPL-3.0
|
||||
*
|
||||
* This code is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3,
|
||||
* as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License, version 3,
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
*/
|
||||
|
||||
namespace OC;
|
||||
|
||||
|
||||
class ServerNotAvailableException extends \Exception {
|
||||
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
<?php
|
||||
/**
|
||||
* ownCloud
|
||||
*
|
||||
* This file is licensed under the Affero General Public License version 3 or
|
||||
* later. See the COPYING-AGPL file.
|
||||
*
|
||||
* @author Jörn Friedrich Dreyer <jfd@owncloud.com>
|
||||
* @copyright Jörn Friedrich Dreyer 2015
|
||||
*/
|
||||
|
||||
namespace OC\User;
|
||||
|
||||
class NoUserException extends \Exception {}
|
|
@ -22,7 +22,12 @@
|
|||
|
||||
namespace Test\Files;
|
||||
|
||||
use OC\User\NoUserException;
|
||||
|
||||
class Filesystem extends \Test\TestCase {
|
||||
|
||||
const TEST_FILESYSTEM_USER1 = "test-filesystem-user1";
|
||||
|
||||
/**
|
||||
* @var array tmpDirs
|
||||
*/
|
||||
|
@ -236,8 +241,14 @@ class Filesystem extends \Test\TestCase {
|
|||
if (\OC\Files\Filesystem::getView()) {
|
||||
$user = \OC_User::getUser();
|
||||
} else {
|
||||
$user = $this->getUniqueID();
|
||||
$user = self::TEST_FILESYSTEM_USER1;
|
||||
$backend = new \OC_User_Dummy();
|
||||
\OC_User::useBackend($backend);
|
||||
$backend->createUser($user, $user);
|
||||
$userObj = \OC::$server->getUserManager()->get($user);
|
||||
\OC::$server->getUserSession()->setUser($userObj);
|
||||
\OC\Files\Filesystem::init($user, '/' . $user . '/files');
|
||||
|
||||
}
|
||||
\OC_Hook::clear('OC_Filesystem');
|
||||
\OC_Hook::connect('OC_Filesystem', 'post_write', $this, 'dummyHook');
|
||||
|
@ -259,19 +270,14 @@ class Filesystem extends \Test\TestCase {
|
|||
}
|
||||
|
||||
/**
|
||||
* Tests that a local storage mount is used when passed user
|
||||
* does not exist.
|
||||
* Tests that an exception is thrown when passed user does not exist.
|
||||
* @expectedException \OC\User\NoUserException
|
||||
*/
|
||||
public function testLocalMountWhenUserDoesNotExist() {
|
||||
$datadir = \OC_Config::getValue("datadirectory", \OC::$SERVERROOT . "/data");
|
||||
$userId = $this->getUniqueID('user_');
|
||||
|
||||
\OC\Files\Filesystem::initMountPoints($userId);
|
||||
|
||||
$homeMount = \OC\Files\Filesystem::getStorage('/' . $userId . '/');
|
||||
|
||||
$this->assertTrue($homeMount->instanceOfStorage('\OC\Files\Storage\Local'));
|
||||
$this->assertEquals('local::' . $datadir . '/' . $userId . '/', $homeMount->getId());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -10,10 +10,7 @@ namespace Test;
|
|||
|
||||
class Preview extends TestCase {
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $user;
|
||||
const TEST_PREVIEW_USER1 = "test-preview-user1";
|
||||
|
||||
/**
|
||||
* @var \OC\Files\View
|
||||
|
@ -32,15 +29,18 @@ class Preview extends TestCase {
|
|||
|
||||
// create a new user with his own filesystem view
|
||||
// this gets called by each test in this test class
|
||||
$this->user = $this->getUniqueID();
|
||||
\OC_User::setUserId($this->user);
|
||||
\OC\Files\Filesystem::init($this->user, '/' . $this->user . '/files');
|
||||
$backend = new \OC_User_Dummy();
|
||||
\OC_User::useBackend($backend);
|
||||
$backend->createUser(self::TEST_PREVIEW_USER1, self::TEST_PREVIEW_USER1);
|
||||
$user = \OC::$server->getUserManager()->get(self::TEST_PREVIEW_USER1);
|
||||
\OC::$server->getUserSession()->setUser($user);
|
||||
\OC\Files\Filesystem::init(self::TEST_PREVIEW_USER1, '/' . self::TEST_PREVIEW_USER1 . '/files');
|
||||
|
||||
\OC\Files\Filesystem::mount('OC\Files\Storage\Temporary', array(), '/');
|
||||
|
||||
$this->rootView = new \OC\Files\View('');
|
||||
$this->rootView->mkdir('/'.$this->user);
|
||||
$this->rootView->mkdir('/'.$this->user.'/files');
|
||||
$this->rootView->mkdir('/'.self::TEST_PREVIEW_USER1);
|
||||
$this->rootView->mkdir('/'.self::TEST_PREVIEW_USER1.'/files');
|
||||
}
|
||||
|
||||
protected function tearDown() {
|
||||
|
@ -59,14 +59,14 @@ class Preview extends TestCase {
|
|||
\OC::$server->getConfig()->setSystemValue('preview_max_y', $maxY);
|
||||
|
||||
// Sample is 1680x1050 JPEG
|
||||
$sampleFile = '/' . $this->user . '/files/testimage.jpg';
|
||||
$sampleFile = '/' . self::TEST_PREVIEW_USER1 . '/files/testimage.jpg';
|
||||
$this->rootView->file_put_contents($sampleFile, file_get_contents(\OC::$SERVERROOT.'/tests/data/testimage.jpg'));
|
||||
$fileInfo = $this->rootView->getFileInfo($sampleFile);
|
||||
$fileId = $fileInfo['fileid'];
|
||||
|
||||
$largeX = 1920;
|
||||
$largeY = 1080;
|
||||
$preview = new \OC\Preview($this->user, 'files/', 'testimage.jpg', $largeX, $largeY);
|
||||
$preview = new \OC\Preview(self::TEST_PREVIEW_USER1, 'files/', 'testimage.jpg', $largeX, $largeY);
|
||||
|
||||
$this->assertEquals($preview->isFileValid(), true);
|
||||
|
||||
|
@ -84,7 +84,7 @@ class Preview extends TestCase {
|
|||
$this->assertEquals($image->height(), $maxY);
|
||||
|
||||
// The max thumbnail should be created
|
||||
$maxThumbCacheFile = '/' . $this->user . '/' . \OC\Preview::THUMBNAILS_FOLDER . '/' . $fileId . '/' . $maxX . '-' . $maxY . '-max.png';
|
||||
$maxThumbCacheFile = '/' . self::TEST_PREVIEW_USER1 . '/' . \OC\Preview::THUMBNAILS_FOLDER . '/' . $fileId . '/' . $maxX . '-' . $maxY . '-max.png';
|
||||
|
||||
$this->assertEquals($this->rootView->file_exists($maxThumbCacheFile), true);
|
||||
|
||||
|
@ -100,7 +100,7 @@ class Preview extends TestCase {
|
|||
// Smaller previews should be based on the cached max preview
|
||||
$smallX = 50;
|
||||
$smallY = 50;
|
||||
$preview = new \OC\Preview($this->user, 'files/', 'testimage.jpg', $smallX, $smallY);
|
||||
$preview = new \OC\Preview(self::TEST_PREVIEW_USER1, 'files/', 'testimage.jpg', $smallX, $smallY);
|
||||
$isCached = $preview->isCached($fileId);
|
||||
|
||||
$this->assertEquals(\OC\Preview::THUMBNAILS_FOLDER . '/' . $fileId . '/' . $maxX . '-' . $maxY . '.png', $isCached);
|
||||
|
@ -111,7 +111,7 @@ class Preview extends TestCase {
|
|||
$this->assertEquals($image->height(), $smallY);
|
||||
|
||||
// The cache should contain the small preview
|
||||
$thumbCacheFile = '/' . $this->user . '/' . \OC\Preview::THUMBNAILS_FOLDER . '/' . $fileId . '/' . $smallX . '-' . $smallY . '.png';
|
||||
$thumbCacheFile = '/' . self::TEST_PREVIEW_USER1 . '/' . \OC\Preview::THUMBNAILS_FOLDER . '/' . $fileId . '/' . $smallX . '-' . $smallY . '.png';
|
||||
|
||||
$this->assertEquals($this->rootView->file_exists($thumbCacheFile), true);
|
||||
|
||||
|
@ -123,20 +123,20 @@ class Preview extends TestCase {
|
|||
|
||||
public function testIsPreviewDeleted() {
|
||||
|
||||
$sampleFile = '/'.$this->user.'/files/test.txt';
|
||||
$sampleFile = '/'.self::TEST_PREVIEW_USER1.'/files/test.txt';
|
||||
|
||||
$this->rootView->file_put_contents($sampleFile, 'dummy file data');
|
||||
|
||||
$x = 50;
|
||||
$y = 50;
|
||||
|
||||
$preview = new \OC\Preview($this->user, 'files/', 'test.txt', $x, $y);
|
||||
$preview = new \OC\Preview(self::TEST_PREVIEW_USER1, 'files/', 'test.txt', $x, $y);
|
||||
$preview->getPreview();
|
||||
|
||||
$fileInfo = $this->rootView->getFileInfo($sampleFile);
|
||||
$fileId = $fileInfo['fileid'];
|
||||
|
||||
$thumbCacheFile = '/' . $this->user . '/' . \OC\Preview::THUMBNAILS_FOLDER . '/' . $fileId . '/' . $x . '-' . $y . '.png';
|
||||
$thumbCacheFile = '/' . self::TEST_PREVIEW_USER1 . '/' . \OC\Preview::THUMBNAILS_FOLDER . '/' . $fileId . '/' . $x . '-' . $y . '.png';
|
||||
|
||||
$this->assertEquals($this->rootView->file_exists($thumbCacheFile), true);
|
||||
|
||||
|
@ -147,20 +147,20 @@ class Preview extends TestCase {
|
|||
|
||||
public function testAreAllPreviewsDeleted() {
|
||||
|
||||
$sampleFile = '/'.$this->user.'/files/test.txt';
|
||||
$sampleFile = '/'.self::TEST_PREVIEW_USER1.'/files/test.txt';
|
||||
|
||||
$this->rootView->file_put_contents($sampleFile, 'dummy file data');
|
||||
|
||||
$x = 50;
|
||||
$y = 50;
|
||||
|
||||
$preview = new \OC\Preview($this->user, 'files/', 'test.txt', $x, $y);
|
||||
$preview = new \OC\Preview(self::TEST_PREVIEW_USER1, 'files/', 'test.txt', $x, $y);
|
||||
$preview->getPreview();
|
||||
|
||||
$fileInfo = $this->rootView->getFileInfo($sampleFile);
|
||||
$fileId = $fileInfo['fileid'];
|
||||
|
||||
$thumbCacheFolder = '/' . $this->user . '/' . \OC\Preview::THUMBNAILS_FOLDER . '/' . $fileId . '/';
|
||||
$thumbCacheFolder = '/' . self::TEST_PREVIEW_USER1 . '/' . \OC\Preview::THUMBNAILS_FOLDER . '/' . $fileId . '/';
|
||||
|
||||
$this->assertEquals($this->rootView->is_dir($thumbCacheFolder), true);
|
||||
|
||||
|
@ -185,9 +185,9 @@ class Preview extends TestCase {
|
|||
$x = 32;
|
||||
$y = 32;
|
||||
|
||||
$sample = '/'.$this->user.'/files/test.'.$extension;
|
||||
$sample = '/'.self::TEST_PREVIEW_USER1.'/files/test.'.$extension;
|
||||
$this->rootView->file_put_contents($sample, $data);
|
||||
$preview = new \OC\Preview($this->user, 'files/', 'test.'.$extension, $x, $y);
|
||||
$preview = new \OC\Preview(self::TEST_PREVIEW_USER1, 'files/', 'test.'.$extension, $x, $y);
|
||||
$image = $preview->getPreview();
|
||||
$resource = $image->resource();
|
||||
|
||||
|
@ -203,7 +203,7 @@ class Preview extends TestCase {
|
|||
|
||||
public function testCreationFromCached() {
|
||||
|
||||
$sampleFile = '/'.$this->user.'/files/test.txt';
|
||||
$sampleFile = '/'.self::TEST_PREVIEW_USER1.'/files/test.txt';
|
||||
|
||||
$this->rootView->file_put_contents($sampleFile, 'dummy file data');
|
||||
|
||||
|
@ -211,22 +211,22 @@ class Preview extends TestCase {
|
|||
$x = 150;
|
||||
$y = 150;
|
||||
|
||||
$preview = new \OC\Preview($this->user, 'files/', 'test.txt', $x, $y);
|
||||
$preview = new \OC\Preview(self::TEST_PREVIEW_USER1, 'files/', 'test.txt', $x, $y);
|
||||
$preview->getPreview();
|
||||
|
||||
$fileInfo = $this->rootView->getFileInfo($sampleFile);
|
||||
$fileId = $fileInfo['fileid'];
|
||||
|
||||
$thumbCacheFile = '/' . $this->user . '/' . \OC\Preview::THUMBNAILS_FOLDER . '/' . $fileId . '/' . $x . '-' . $y . '.png';
|
||||
$thumbCacheFile = '/' . self::TEST_PREVIEW_USER1 . '/' . \OC\Preview::THUMBNAILS_FOLDER . '/' . $fileId . '/' . $x . '-' . $y . '.png';
|
||||
|
||||
$this->assertEquals($this->rootView->file_exists($thumbCacheFile), true);
|
||||
|
||||
|
||||
// create smaller previews
|
||||
$preview = new \OC\Preview($this->user, 'files/', 'test.txt', 50, 50);
|
||||
$preview = new \OC\Preview(self::TEST_PREVIEW_USER1, 'files/', 'test.txt', 50, 50);
|
||||
$isCached = $preview->isCached($fileId);
|
||||
|
||||
$this->assertEquals($this->user . '/' . \OC\Preview::THUMBNAILS_FOLDER . '/' . $fileId . '/150-150.png', $isCached);
|
||||
$this->assertEquals(self::TEST_PREVIEW_USER1 . '/' . \OC\Preview::THUMBNAILS_FOLDER . '/' . $fileId . '/150-150.png', $isCached);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
Loading…
Reference in New Issue