summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/private/Share/Share.php24
-rw-r--r--lib/public/Share.php10
-rw-r--r--tests/lib/Files/FilesystemTest.php2
-rw-r--r--tests/lib/Share/ShareTest.php28
-rw-r--r--tests/lib/TestCase.php3
5 files changed, 58 insertions, 9 deletions
diff --git a/lib/private/Share/Share.php b/lib/private/Share/Share.php
index b9accda728c..f6da19f3bb8 100644
--- a/lib/private/Share/Share.php
+++ b/lib/private/Share/Share.php
@@ -45,6 +45,8 @@ namespace OC\Share;
use OC\Files\Filesystem;
use OCA\FederatedFileSharing\DiscoveryManager;
use OCP\DB\QueryBuilder\IQueryBuilder;
+use OCP\ILogger;
+use OCP\IUserManager;
use OCP\IUserSession;
use OCP\IDBConnection;
use OCP\IConfig;
@@ -128,19 +130,35 @@ class Share extends Constants {
* Find which users can access a shared item
* @param string $path to the file
* @param string $ownerUser owner of the file
+ * @param IUserManager $userManager
+ * @param ILogger $logger
* @param boolean $includeOwner include owner to the list of users with access to the file
* @param boolean $returnUserPaths Return an array with the user => path map
* @param boolean $recursive take all parent folders into account (default true)
* @return array
* @note $path needs to be relative to user data dir, e.g. 'file.txt'
* not '/admin/data/file.txt'
+ * @throws \OC\User\NoUserException
*/
- public static function getUsersSharingFile($path, $ownerUser, $includeOwner = false, $returnUserPaths = false, $recursive = true) {
- $userManager = \OC::$server->getUserManager();
+ public static function getUsersSharingFile($path,
+ $ownerUser,
+ IUserManager $userManager,
+ ILogger $logger,
+ $includeOwner = false,
+ $returnUserPaths = false,
+ $recursive = true) {
$userObject = $userManager->get($ownerUser);
if (is_null($userObject)) {
- \OCP\Util::writeLog('files', ' Backends provided no user object for ' . $ownerUser, \OCP\Util::ERROR);
+ $logger->error(
+ sprintf(
+ 'Backends provided no user object for %s',
+ $ownerUser
+ ),
+ [
+ 'app' => 'files',
+ ]
+ );
throw new \OC\User\NoUserException('Backends provided no user object');
}
diff --git a/lib/public/Share.php b/lib/public/Share.php
index bc7aa828f62..ec3a7c8db1b 100644
--- a/lib/public/Share.php
+++ b/lib/public/Share.php
@@ -89,7 +89,15 @@ class Share extends \OC\Share\Constants {
* @since 5.0.0 - $recursive was added in 9.0.0
*/
public static function getUsersSharingFile($path, $ownerUser, $includeOwner = false, $returnUserPaths = false, $recursive = true) {
- return \OC\Share\Share::getUsersSharingFile($path, $ownerUser, $includeOwner, $returnUserPaths, $recursive);
+ return \OC\Share\Share::getUsersSharingFile(
+ $path,
+ $ownerUser,
+ \OC::$server->getUserManager(),
+ \OC::$server->getLogger(),
+ $includeOwner,
+ $returnUserPaths,
+ $recursive
+ );
}
/**
diff --git a/tests/lib/Files/FilesystemTest.php b/tests/lib/Files/FilesystemTest.php
index 04eafc99f36..dd4785ecf09 100644
--- a/tests/lib/Files/FilesystemTest.php
+++ b/tests/lib/Files/FilesystemTest.php
@@ -79,7 +79,6 @@ class FilesystemTest extends \Test\TestCase {
protected function setUp() {
parent::setUp();
- \OC_User::clearBackends();
$userBackend = new \Test\Util\User\Dummy();
$userBackend->createUser(self::TEST_FILESYSTEM_USER1, self::TEST_FILESYSTEM_USER1);
$userBackend->createUser(self::TEST_FILESYSTEM_USER2, self::TEST_FILESYSTEM_USER2);
@@ -94,7 +93,6 @@ class FilesystemTest extends \Test\TestCase {
$this->logout();
$this->invokePrivate('\OC\Files\Filesystem', 'normalizedPathCache', [null]);
- \OC_User::clearBackends();
parent::tearDown();
}
diff --git a/tests/lib/Share/ShareTest.php b/tests/lib/Share/ShareTest.php
index 63289529843..d550ba158a9 100644
--- a/tests/lib/Share/ShareTest.php
+++ b/tests/lib/Share/ShareTest.php
@@ -20,6 +20,9 @@
*/
namespace Test\Share;
+use OC\Share\Share;
+use OCP\ILogger;
+use OCP\IUserManager;
/**
* Class Test_Share
@@ -1631,6 +1634,31 @@ class ShareTest extends \Test\TestCase {
$this->assertEquals('Sharing failed, because the user ' . $this->user1 . ' is the original sharer', $e->getMessage());
}
}
+
+ /**
+ * @expectedException \OC\User\NoUserException
+ * @expectedExceptionMessage Backends provided no user object
+ */
+ public function testGetUsersSharingFileWithException() {
+ $userManager = $this->createMock(IUserManager::class);
+ $logger = $this->createMock(ILogger::class);
+ $userManager
+ ->expects($this->once())
+ ->method('get')
+ ->with('test')
+ ->willReturn(null);
+ $logger
+ ->expects($this->once())
+ ->method('error')
+ ->with(
+ 'Backends provided no user object for test',
+ [
+ 'app' => 'files',
+ ]
+ );
+
+ Share::getUsersSharingFile('/my/file/path', 'test', $userManager, $logger);
+ }
}
class DummyShareClass extends \OC\Share\Share {
diff --git a/tests/lib/TestCase.php b/tests/lib/TestCase.php
index 1ca896e0914..61372d4ae90 100644
--- a/tests/lib/TestCase.php
+++ b/tests/lib/TestCase.php
@@ -273,9 +273,6 @@ abstract class TestCase extends \PHPUnit_Framework_TestCase {
self::tearDownAfterClassCleanStrayHooks();
self::tearDownAfterClassCleanStrayLocks();
- \OC_User::clearBackends();
- \OC_User::useBackend('dummy');
-
parent::tearDownAfterClass();
}