]> source.dussan.org Git - nextcloud-server.git/commitdiff
[Share 2.0] Fix shareManager
authorRoeland Jago Douma <rullzer@owncloud.com>
Tue, 2 Feb 2016 20:02:09 +0000 (21:02 +0100)
committerRoeland Jago Douma <rullzer@owncloud.com>
Wed, 3 Feb 2016 18:25:29 +0000 (19:25 +0100)
lib/private/server.php
lib/private/share20/manager.php
lib/public/share/imanager.php
tests/lib/share20/managertest.php

index d3dbcba86bacc75284043e23066e4ca860de1e20..69406c2203f616d367e4e2f15e42ef27ad478d7c 100644 (file)
@@ -617,7 +617,8 @@ class Server extends ServerContainer implements IServerContainer {
                                $c->getMountManager(),
                                $c->getGroupManager(),
                                $c->getL10N('core'),
-                               $factory
+                               $factory,
+                               $c->getUserManager()
                        );
 
                        return $manager;
index 520b5a53762f945db6d4799eaaf5630bd37984ea..db42f76d7a2f698ce9704053799f963b09db22dc 100644 (file)
@@ -21,7 +21,7 @@
 
 namespace OC\Share20;
 
-use OCP\Files\Node;
+use OCP\IUserManager;
 use OCP\Share\IManager;
 use OCP\Share\IProviderFactory;
 use OC\Share20\Exception\BackendError;
@@ -34,7 +34,6 @@ use OCP\Files\Mount\IMountManager;
 use OCP\IGroupManager;
 use OCP\Files\File;
 use OCP\Files\Folder;
-use OCP\IUser;
 
 use OCP\Share\Exceptions\ShareNotFound;
 use OCP\Share\Exceptions\GenericShareException;
@@ -68,6 +67,9 @@ class Manager implements IManager {
        /** @var IL10N */
        private $l;
 
+       /** @var IUserManager */
+       private $userManager;
+
        /**
         * Manager constructor.
         *
@@ -79,6 +81,7 @@ class Manager implements IManager {
         * @param IGroupManager $groupManager
         * @param IL10N $l
         * @param IProviderFactory $factory
+        * @param IUserManager $userManager
         */
        public function __construct(
                        ILogger $logger,
@@ -88,7 +91,8 @@ class Manager implements IManager {
                        IMountManager $mountManager,
                        IGroupManager $groupManager,
                        IL10N $l,
-                       IProviderFactory $factory
+                       IProviderFactory $factory,
+                       IUserManager $userManager
        ) {
                $this->logger = $logger;
                $this->config = $config;
@@ -98,6 +102,7 @@ class Manager implements IManager {
                $this->groupManager = $groupManager;
                $this->l = $l;
                $this->factory = $factory;
+               $this->userManager = $userManager;
        }
 
        /**
@@ -150,13 +155,13 @@ class Manager implements IManager {
        protected function generalCreateChecks(\OCP\Share\IShare $share) {
                if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) {
                        // We expect a valid user as sharedWith for user shares
-                       if (!($share->getSharedWith() instanceof \OCP\IUser)) {
-                               throw new \InvalidArgumentException('SharedWith should be an IUser');
+                       if (!$this->userManager->userExists($share->getSharedWith())) {
+                               throw new \InvalidArgumentException('SharedWith is not a valid user');
                        }
                } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
                        // We expect a valid group as sharedWith for group shares
-                       if (!($share->getSharedWith() instanceof \OCP\IGroup)) {
-                               throw new \InvalidArgumentException('SharedWith should be an IGroup');
+                       if (!$this->groupManager->groupExists($share->getSharedWith())) {
+                               throw new \InvalidArgumentException('SharedWith is not a valid group');
                        }
                } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) {
                        if ($share->getSharedWith() !== null) {
@@ -173,7 +178,8 @@ class Manager implements IManager {
                }
 
                // Cannot share with yourself
-               if ($share->getSharedWith() === $share->getSharedBy()) {
+               if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER &&
+                       $share->getSharedWith() === $share->getSharedBy()) {
                        throw new \InvalidArgumentException('Can\'t share with yourself');
                }
 
@@ -215,7 +221,7 @@ class Manager implements IManager {
         * Validate if the expiration date fits the system settings
         *
         * @param \OCP\Share\IShare $share The share to validate the expiration date of
-        * @return \DateTime|null The expiration date or null if $expireDate was null and it is not required
+        * @return \OCP\Share\IShare The expiration date or null if $expireDate was null and it is not required
         * @throws GenericShareException
         * @throws \InvalidArgumentException
         * @throws \Exception
@@ -285,10 +291,12 @@ class Manager implements IManager {
        protected function userCreateChecks(\OCP\Share\IShare $share) {
                // Check if we can share with group members only
                if ($this->shareWithGroupMembersOnly()) {
+                       $sharedBy = $this->userManager->get($share->getSharedBy());
+                       $sharedWith = $this->userManager->get($share->getSharedWith());
                        // Verify we can share with this user
                        $groups = array_intersect(
-                                       $this->groupManager->getUserGroupIds($share->getSharedBy()),
-                                       $this->groupManager->getUserGroupIds($share->getSharedWith())
+                                       $this->groupManager->getUserGroupIds($sharedBy),
+                                       $this->groupManager->getUserGroupIds($sharedWith)
                        );
                        if (empty($groups)) {
                                throw new \Exception('Only sharing with group members is allowed');
@@ -314,10 +322,13 @@ class Manager implements IManager {
                        }
 
                        // The share is already shared with this user via a group share
-                       if ($existingShare->getShareType() === \OCP\Share::SHARE_TYPE_GROUP &&
-                                       $existingShare->getSharedWith()->inGroup($share->getSharedWith()) &&
-                                       $existingShare->getShareOwner() !== $share->getShareOwner()) {
-                               throw new \Exception('Path already shared with this user');
+                       if ($existingShare->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
+                               $group = $this->groupManager->get($existingShare->getSharedWith());
+                               $user = $this->userManager->get($share->getSharedWith());
+
+                               if ($group->inGroup($user) && $existingShare->getShareOwner() !== $share->getShareOwner()) {
+                                       throw new \Exception('Path already shared with this user');
+                               }
                        }
                }
        }
@@ -331,7 +342,9 @@ class Manager implements IManager {
        protected function groupCreateChecks(\OCP\Share\IShare $share) {
                // Verify if the user can share with this group
                if ($this->shareWithGroupMembersOnly()) {
-                       if (!$share->getSharedWith()->inGroup($share->getSharedBy())) {
+                       $sharedBy = $this->userManager->get($share->getSharedBy());
+                       $sharedWith = $this->groupManager->get($share->getSharedWith());
+                       if (!$sharedWith->inGroup($sharedBy)) {
                                throw new \Exception('Only sharing within your own groups is allowed');
                        }
                }
@@ -468,10 +481,11 @@ class Manager implements IManager {
                $this->pathCreateChecks($share->getNode());
 
                // On creation of a share the owner is always the owner of the path
-               $share->setShareOwner($share->getNode()->getOwner());
+               $share->setShareOwner($share->getNode()->getOwner()->getUID());
 
                // Cannot share with the owner
-               if ($share->getSharedWith() === $share->getShareOwner()) {
+               if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER &&
+                       $share->getSharedWith() === $share->getShareOwner()) {
                        throw new \InvalidArgumentException('Can\'t share with the share owner');
                }
 
@@ -480,16 +494,6 @@ class Manager implements IManager {
                $target = \OC\Files\Filesystem::normalizePath($target);
                $share->setTarget($target);
 
-               //Get sharewith for hooks
-               $sharedWith = null;
-               if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) {
-                       $sharedWith = $share->getSharedWith()->getUID();
-               } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
-                       $sharedWith = $share->getSharedWith()->getGID();
-               } else {
-                       $sharedWith = $share->getSharedWith();
-               }
-
                // Pre share hook
                $run = true;
                $error = '';
@@ -497,13 +501,13 @@ class Manager implements IManager {
                        'itemType' => $share->getNode() instanceof \OCP\Files\File ? 'file' : 'folder',
                        'itemSource' => $share->getNode()->getId(),
                        'shareType' => $share->getShareType(),
-                       'uidOwner' => $share->getSharedBy()->getUID(),
+                       'uidOwner' => $share->getSharedBy(),
                        'permissions' => $share->getPermissions(),
                        'fileSource' => $share->getNode()->getId(),
                        'expiration' => $share->getExpirationDate(),
                        'token' => $share->getToken(),
                        'itemTarget' => $share->getTarget(),
-                       'shareWith' => $sharedWith,
+                       'shareWith' => $share->getSharedWith(),
                        'run' => &$run,
                        'error' => &$error,
                ];
@@ -521,13 +525,13 @@ class Manager implements IManager {
                        'itemType' => $share->getNode() instanceof \OCP\Files\File ? 'file' : 'folder',
                        'itemSource' => $share->getNode()->getId(),
                        'shareType' => $share->getShareType(),
-                       'uidOwner' => $share->getSharedBy()->getUID(),
+                       'uidOwner' => $share->getSharedBy(),
                        'permissions' => $share->getPermissions(),
                        'fileSource' => $share->getNode()->getId(),
                        'expiration' => $share->getExpirationDate(),
                        'token' => $share->getToken(),
                        'id' => $share->getId(),
-                       'shareWith' => $sharedWith,
+                       'shareWith' => $share->getSharedWith(),
                        'itemTarget' => $share->getTarget(),
                        'fileTarget' => $share->getTarget(),
                ];
@@ -542,6 +546,7 @@ class Manager implements IManager {
         *
         * @param \OCP\Share\IShare $share
         * @return \OCP\Share\IShare The share object
+        * @throws \InvalidArgumentException
         */
        public function updateShare(\OCP\Share\IShare $share) {
                $expirationDateUpdated = false;
@@ -564,7 +569,8 @@ class Manager implements IManager {
                }
 
                // Cannot share with the owner
-               if ($share->getSharedWith() === $share->getShareOwner()) {
+               if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER &&
+                       $share->getSharedWith() === $share->getShareOwner()) {
                        throw new \InvalidArgumentException('Can\'t share with the share owner');
                }
 
@@ -606,7 +612,7 @@ class Manager implements IManager {
                                'itemType' => $share->getNode() instanceof \OCP\Files\File ? 'file' : 'folder',
                                'itemSource' => $share->getNode()->getId(),
                                'date' => $share->getExpirationDate(),
-                               'uidOwner' => $share->getSharedBy()->getUID(),
+                               'uidOwner' => $share->getSharedBy(),
                        ]);
                }
 
@@ -651,9 +657,9 @@ class Manager implements IManager {
                        $shareType = $share->getShareType();
                        $sharedWith = '';
                        if ($shareType === \OCP\Share::SHARE_TYPE_USER) {
-                               $sharedWith = $share->getSharedWith()->getUID();
+                               $sharedWith = $share->getSharedWith();
                        } else if ($shareType === \OCP\Share::SHARE_TYPE_GROUP) {
-                               $sharedWith = $share->getSharedWith()->getGID();
+                               $sharedWith = $share->getSharedWith();
                        } else if ($shareType === \OCP\Share::SHARE_TYPE_REMOTE) {
                                $sharedWith = $share->getSharedWith();
                        }
@@ -665,7 +671,7 @@ class Manager implements IManager {
                                'shareType'  => $shareType,
                                'shareWith'  => $sharedWith,
                                'itemparent' => $share->getParent(),
-                               'uidOwner'   => $share->getSharedBy()->getUID(),
+                               'uidOwner'   => $share->getSharedBy(),
                                'fileSource' => $share->getNode()->getId(),
                                'fileTarget' => $share->getTarget()
                        ];
@@ -706,38 +712,45 @@ class Manager implements IManager {
         * handle this.
         *
         * @param \OCP\Share\IShare $share
-        * @param IUser $recipient
+        * @param string $recipientId
         */
-       public function deleteFromSelf(\OCP\Share\IShare $share, IUser $recipient) {
-               list($providerId, $id) = $this->splitFullId($share->getId());
+       public function deleteFromSelf(\OCP\Share\IShare $share, $recipientId) {
+               list($providerId, ) = $this->splitFullId($share->getId());
                $provider = $this->factory->getProvider($providerId);
 
-               $provider->deleteFromSelf($share, $recipient);
+               $provider->deleteFromSelf($share, $recipientId);
        }
 
        /**
         * @inheritdoc
         */
-       public function moveShare(\OCP\Share\IShare $share, IUser $recipient) {
+       public function moveShare(\OCP\Share\IShare $share, $recipientId) {
                if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) {
                        throw new \InvalidArgumentException('Can\'t change target of link share');
                }
 
-               if (($share->getShareType() === \OCP\Share::SHARE_TYPE_USER && $share->getSharedWith() !== $recipient) ||
-                       ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP && !$share->getSharedWith()->inGroup($recipient))) {
+               if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER && $share->getSharedWith() !== $recipientId) {
                        throw new \InvalidArgumentException('Invalid recipient');
                }
 
+               if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
+                       $sharedWith = $this->groupManager->get($share->getSharedWith());
+                       $recipient = $this->userManager->get($recipientId);
+                       if (!$sharedWith->inGroup($recipient)) {
+                               throw new \InvalidArgumentException('Invalid recipient');
+                       }
+               }
+
                list($providerId, ) = $this->splitFullId($share->getId());
                $provider = $this->factory->getProvider($providerId);
 
-               $provider->move($share, $recipient);
+               $provider->move($share, $recipientId);
        }
 
        /**
         * Get shares shared by (initiated) by the provided user.
         *
-        * @param IUser $user
+        * @param string $userId
         * @param int $shareType
         * @param \OCP\Files\File|\OCP\Files\Folder $path
         * @param bool $reshares
@@ -745,7 +758,7 @@ class Manager implements IManager {
         * @param int $offset
         * @return \OCP\Share\IShare[]
         */
-       public function getSharesBy(IUser $user, $shareType, $path = null, $reshares = false, $limit = 50, $offset = 0) {
+       public function getSharesBy($userId, $shareType, $path = null, $reshares = false, $limit = 50, $offset = 0) {
                if ($path !== null &&
                                !($path instanceof \OCP\Files\File) &&
                                !($path instanceof \OCP\Files\Folder)) {
@@ -754,16 +767,16 @@ class Manager implements IManager {
 
                $provider = $this->factory->getProviderForType($shareType);
 
-               return $provider->getSharesBy($user, $shareType, $path, $reshares, $limit, $offset);
+               return $provider->getSharesBy($userId, $shareType, $path, $reshares, $limit, $offset);
        }
 
        /**
         * @inheritdoc
         */
-       public function getSharedWith(IUser $user, $shareType, $node = null, $limit = 50, $offset = 0) {
+       public function getSharedWith($userId, $shareType, $node = null, $limit = 50, $offset = 0) {
                $provider = $this->factory->getProviderForType($shareType);
 
-               return $provider->getSharedWith($user, $shareType, $node, $limit, $offset);
+               return $provider->getSharedWith($userId, $shareType, $node, $limit, $offset);
        }
 
        /**
@@ -955,10 +968,10 @@ class Manager implements IManager {
         *
         * TODO: Deprecate fuction from OC_Util
         *
-        * @param IUser $user
+        * @param string $userId
         * @return bool
         */
-       public function sharingDisabledForUser(IUser $user) {
+       public function sharingDisabledForUser($userId) {
                if ($this->config->getAppValue('core', 'shareapi_exclude_groups', 'no') === 'yes') {
                        $groupsList = $this->config->getAppValue('core', 'shareapi_exclude_groups_list', '');
                        $excludedGroups = json_decode($groupsList);
@@ -967,6 +980,7 @@ class Manager implements IManager {
                                $newValue = json_encode($excludedGroups);
                                $this->config->setAppValue('core', 'shareapi_exclude_groups_list', $newValue);
                        }
+                       $user = $this->userManager->get($userId);
                        $usersGroups = $this->groupManager->getUserGroupIds($user);
                        if (!empty($usersGroups)) {
                                $remainingGroups = array_diff($usersGroups, $excludedGroups);
index 15b9f34764ee63eb6105014d025a36ffc66d8019..4d79f97c31ad3303c10ca2d08e35579bfc45e572 100644 (file)
@@ -69,27 +69,27 @@ interface IManager {
         * handle this.
         *
         * @param IShare $share
-        * @param IUser $recipient
+        * @param string $recipientId
         * @since 9.0.0
         */
-       public function deleteFromSelf(IShare $share, IUser $recipient);
+       public function deleteFromSelf(IShare $share, $recipientId);
 
        /**
         * Move the share as a recipient of the share.
         * This is updating the share target. So where the recipient has the share mounted.
         *
         * @param IShare $share
-        * @param IUser $recipient
+        * @param string $recipientId
         * @return IShare
         * @throws \InvalidArgumentException If $share is a link share or the $recipient does not match
         * @since 9.0.0
         */
-       public function moveShare(IShare $share, IUser $recipient);
+       public function moveShare(IShare $share, $recipientId);
 
        /**
         * Get shares shared by (initiated) by the provided user.
         *
-        * @param IUser $user
+        * @param string $userId
         * @param int $shareType
         * @param \OCP\Files\File|\OCP\Files\Folder $path
         * @param bool $reshares
@@ -98,13 +98,13 @@ interface IManager {
         * @return IShare[]
         * @since 9.0.0
         */
-       public function getSharesBy(IUser $user, $shareType, $path = null, $reshares = false, $limit = 50, $offset = 0);
+       public function getSharesBy($userId, $shareType, $path = null, $reshares = false, $limit = 50, $offset = 0);
 
        /**
         * Get shares shared with $user.
         * Filter by $node if provided
         *
-        * @param IUser $user
+        * @param string $userId
         * @param int $shareType
         * @param File|Folder|null $node
         * @param int $limit The maximum number of shares returned, -1 for all
@@ -112,7 +112,7 @@ interface IManager {
         * @return IShare[]
         * @since 9.0.0
         */
-       public function getSharedWith(IUser $user, $shareType, $node = null, $limit = 50, $offset = 0);
+       public function getSharedWith($userId, $shareType, $node = null, $limit = 50, $offset = 0);
 
        /**
         * Retrieve a share by the share id.
@@ -223,10 +223,10 @@ interface IManager {
        /**
         * Check if sharing is disabled for the given user
         *
-        * @param IUser $user
+        * @param string $userId
         * @return bool
         * @since 9.0.0
         */
-       public function sharingDisabledForUser(IUser $user);
+       public function sharingDisabledForUser($userId);
 
 }
index 34cc39a77df8bfa1de3817f2f8bb9f797578a1eb..aa286cc4719bf5b3159fc02285299958c3db888d 100644 (file)
@@ -20,6 +20,7 @@
  */
 namespace Test\Share20;
 
+use OCP\IUserManager;
 use OCP\Share\IProviderFactory;
 use OCP\Share\IShare;
 use OC\Share20\Manager;
@@ -74,6 +75,9 @@ class ManagerTest extends \Test\TestCase {
        /** @var DummyFactory */
        protected $factory;
 
+       /** @var IUserManager */
+       protected $userManager;
+
        public function setUp() {
                
                $this->logger = $this->getMock('\OCP\ILogger');
@@ -82,6 +86,7 @@ class ManagerTest extends \Test\TestCase {
                $this->hasher = $this->getMock('\OCP\Security\IHasher');
                $this->mountManager = $this->getMock('\OCP\Files\Mount\IMountManager');
                $this->groupManager = $this->getMock('\OCP\IGroupManager');
+               $this->userManager = $this->getMock('\OCP\IUserManager');
 
                $this->l = $this->getMock('\OCP\IL10N');
                $this->l->method('t')
@@ -99,7 +104,8 @@ class ManagerTest extends \Test\TestCase {
                        $this->mountManager,
                        $this->groupManager,
                        $this->l,
-                       $this->factory
+                       $this->factory,
+                       $this->userManager
                );
 
                $this->defaultProvider = $this->getMockBuilder('\OC\Share20\DefaultShareProvider')
@@ -124,7 +130,8 @@ class ManagerTest extends \Test\TestCase {
                                $this->mountManager,
                                $this->groupManager,
                                $this->l,
-                               $this->factory
+                               $this->factory,
+                               $this->userManager
                        ]);
        }
 
@@ -151,24 +158,21 @@ class ManagerTest extends \Test\TestCase {
                $group->method('getGID')->willReturn('sharedWithGroup');
        
                return [
-                       [\OCP\Share::SHARE_TYPE_USER, $user, 'sharedWithUser'],
-                       [\OCP\Share::SHARE_TYPE_GROUP, $group, 'sharedWithGroup'],
-                       [\OCP\Share::SHARE_TYPE_LINK, '', ''],
-                       [\OCP\Share::SHARE_TYPE_REMOTE, 'foo@bar.com', 'foo@bar.com'],
+                       [\OCP\Share::SHARE_TYPE_USER, 'sharedWithUser'],
+                       [\OCP\Share::SHARE_TYPE_GROUP, 'sharedWithGroup'],
+                       [\OCP\Share::SHARE_TYPE_LINK, ''],
+                       [\OCP\Share::SHARE_TYPE_REMOTE, 'foo@bar.com'],
                ];
        }
 
        /**
         * @dataProvider dataTestDelete
         */
-       public function testDelete($shareType, $sharedWith, $sharedWith_string) {
+       public function testDelete($shareType, $sharedWith) {
                $manager = $this->createManagerMock()
                        ->setMethods(['getShareById', 'deleteChildren'])
                        ->getMock();
 
-               $sharedBy = $this->getMock('\OCP\IUser');
-               $sharedBy->method('getUID')->willReturn('sharedBy');
-
                $path = $this->getMock('\OCP\Files\File');
                $path->method('getId')->willReturn(1);
 
@@ -177,7 +181,7 @@ class ManagerTest extends \Test\TestCase {
                        ->setProviderId('prov')
                        ->setShareType($shareType)
                        ->setSharedWith($sharedWith)
-                       ->setSharedBy($sharedBy)
+                       ->setSharedBy('sharedBy')
                        ->setNode($path)
                        ->setTarget('myTarget');
 
@@ -198,7 +202,7 @@ class ManagerTest extends \Test\TestCase {
                        'itemType' => 'file',
                        'itemSource' => 1,
                        'shareType' => $shareType,
-                       'shareWith' => $sharedWith_string,
+                       'shareWith' => $sharedWith,
                        'itemparent' => null,
                        'uidOwner' => 'sharedBy',
                        'fileSource' => 1,
@@ -210,7 +214,7 @@ class ManagerTest extends \Test\TestCase {
                        'itemType' => 'file',
                        'itemSource' => 1,
                        'shareType' => $shareType,
-                       'shareWith' => $sharedWith_string,
+                       'shareWith' => $sharedWith,
                        'itemparent' => null,
                        'uidOwner' => 'sharedBy',
                        'fileSource' => 1,
@@ -221,7 +225,7 @@ class ManagerTest extends \Test\TestCase {
                                        'itemType' => 'file',
                                        'itemSource' => 1,
                                        'shareType' => $shareType,
-                                       'shareWith' => $sharedWith_string,
+                                       'shareWith' => $sharedWith,
                                        'itemparent' => null,
                                        'uidOwner' => 'sharedBy',
                                        'fileSource' => 1,
@@ -248,18 +252,6 @@ class ManagerTest extends \Test\TestCase {
                        ->setMethods(['getShareById'])
                        ->getMock();
 
-               $sharedBy1 = $this->getMock('\OCP\IUser');
-               $sharedBy1->method('getUID')->willReturn('sharedBy1');
-               $sharedBy2 = $this->getMock('\OCP\IUser');
-               $sharedBy2->method('getUID')->willReturn('sharedBy2');
-               $sharedBy3 = $this->getMock('\OCP\IUser');
-               $sharedBy3->method('getUID')->willReturn('sharedBy3');
-
-               $sharedWith1 = $this->getMock('\OCP\IUser');
-               $sharedWith1->method('getUID')->willReturn('sharedWith1');
-               $sharedWith2 = $this->getMock('\OCP\IGroup');
-               $sharedWith2->method('getGID')->willReturn('sharedWith2');
-
                $path = $this->getMock('\OCP\Files\File');
                $path->method('getId')->willReturn(1);
 
@@ -267,8 +259,8 @@ class ManagerTest extends \Test\TestCase {
                $share1->setId(42)
                        ->setProviderId('prov')
                        ->setShareType(\OCP\Share::SHARE_TYPE_USER)
-                       ->setSharedWith($sharedWith1)
-                       ->setSharedBy($sharedBy1)
+                       ->setSharedWith('sharedWith1')
+                       ->setSharedBy('sharedBy1')
                        ->setNode($path)
                        ->setTarget('myTarget1');
 
@@ -276,8 +268,8 @@ class ManagerTest extends \Test\TestCase {
                $share2->setId(43)
                        ->setProviderId('prov')
                        ->setShareType(\OCP\Share::SHARE_TYPE_GROUP)
-                       ->setSharedWith($sharedWith2)
-                       ->setSharedBy($sharedBy2)
+                       ->setSharedWith('sharedWith2')
+                       ->setSharedBy('sharedBy2')
                        ->setNode($path)
                        ->setTarget('myTarget2')
                        ->setParent(42);
@@ -286,7 +278,7 @@ class ManagerTest extends \Test\TestCase {
                $share3->setId(44)
                        ->setProviderId('prov')
                        ->setShareType(\OCP\Share::SHARE_TYPE_LINK)
-                       ->setSharedBy($sharedBy3)
+                       ->setSharedBy('sharedBy3')
                        ->setNode($path)
                        ->setTarget('myTarget3')
                        ->setParent(43);
@@ -504,72 +496,72 @@ class ManagerTest extends \Test\TestCase {
        }
 
        public function dataGeneralChecks() {
-               $user = $this->getMock('\OCP\IUser');
-               $user2 = $this->getMock('\OCP\IUser');
-               $group = $this->getMock('\OCP\IGroup');
+               $user0 = 'user0';
+               $user2 = 'user1';
+               $group0 = 'group0';
 
                $file = $this->getMock('\OCP\Files\File');
                $node = $this->getMock('\OCP\Files\Node');
 
                $data = [
-                       [$this->createShare(null, \OCP\Share::SHARE_TYPE_USER,  $file, null, $user, $user, 31, null, null), 'SharedWith should be an IUser', true],
-                       [$this->createShare(null, \OCP\Share::SHARE_TYPE_USER,  $file, $group, $user, $user, 31, null, null), 'SharedWith should be an IUser', true],
-                       [$this->createShare(null, \OCP\Share::SHARE_TYPE_USER,  $file, 'foo@bar.com', $user, $user, 31, null, null), 'SharedWith should be an IUser', true],
-                       [$this->createShare(null, \OCP\Share::SHARE_TYPE_GROUP, $file, null, $user, $user, 31, null, null), 'SharedWith should be an IGroup', true],
-                       [$this->createShare(null, \OCP\Share::SHARE_TYPE_GROUP, $file, $user2, $user, $user, 31, null, null), 'SharedWith should be an IGroup', true],
-                       [$this->createShare(null, \OCP\Share::SHARE_TYPE_GROUP, $file, 'foo@bar.com', $user, $user, 31, null, null), 'SharedWith should be an IGroup', true],
-                       [$this->createShare(null, \OCP\Share::SHARE_TYPE_LINK,  $file, $user2, $user, $user, 31, null, null), 'SharedWith should be empty', true],
-                       [$this->createShare(null, \OCP\Share::SHARE_TYPE_LINK,  $file, $group, $user, $user, 31, null, null), 'SharedWith should be empty', true],
-                       [$this->createShare(null, \OCP\Share::SHARE_TYPE_LINK,  $file, 'foo@bar.com', $user, $user, 31, null, null), 'SharedWith should be empty', true],
-                       [$this->createShare(null, -1, $file, null, $user, $user, 31, null, null), 'unkown share type', true],
-
-                       [$this->createShare(null, \OCP\Share::SHARE_TYPE_USER,  $file, $user2, null, $user, 31, null, null), 'SharedBy should be set', true],
-                       [$this->createShare(null, \OCP\Share::SHARE_TYPE_GROUP, $file, $group, null, $user, 31, null, null), 'SharedBy should be set', true],
-                       [$this->createShare(null, \OCP\Share::SHARE_TYPE_LINK,  $file, null, null, $user, 31, null, null), 'SharedBy should be set', true],
-
-                       [$this->createShare(null, \OCP\Share::SHARE_TYPE_USER,  $file, $user, $user, $user, 31, null, null), 'Can\'t share with yourself', true],
-
-                       [$this->createShare(null, \OCP\Share::SHARE_TYPE_USER,  null, $user2, $user, $user, 31, null, null), 'Path should be set', true],
-                       [$this->createShare(null, \OCP\Share::SHARE_TYPE_GROUP, null, $group, $user, $user, 31, null, null), 'Path should be set', true],
-                       [$this->createShare(null, \OCP\Share::SHARE_TYPE_LINK,  null, null, $user, $user, 31, null, null), 'Path should be set', true],
-
-                       [$this->createShare(null, \OCP\Share::SHARE_TYPE_USER,  $node, $user2, $user, $user, 31, null, null), 'Path should be either a file or a folder', true],
-                       [$this->createShare(null, \OCP\Share::SHARE_TYPE_GROUP, $node, $group, $user, $user, 31, null, null), 'Path should be either a file or a folder', true],
-                       [$this->createShare(null, \OCP\Share::SHARE_TYPE_LINK,  $node, null, $user, $user, 31, null, null), 'Path should be either a file or a folder', true],
+                       [$this->createShare(null, \OCP\Share::SHARE_TYPE_USER,  $file, null, $user0, $user0, 31, null, null), 'SharedWith is not a valid user', true],
+                       [$this->createShare(null, \OCP\Share::SHARE_TYPE_USER,  $file, $group0, $user0, $user0, 31, null, null), 'SharedWith is not a valid user', true],
+                       [$this->createShare(null, \OCP\Share::SHARE_TYPE_USER,  $file, 'foo@bar.com', $user0, $user0, 31, null, null), 'SharedWith is not a valid user', true],
+                       [$this->createShare(null, \OCP\Share::SHARE_TYPE_GROUP, $file, null, $user0, $user0, 31, null, null), 'SharedWith is not a valid group', true],
+                       [$this->createShare(null, \OCP\Share::SHARE_TYPE_GROUP, $file, $user2, $user0, $user0, 31, null, null), 'SharedWith is not a valid group', true],
+                       [$this->createShare(null, \OCP\Share::SHARE_TYPE_GROUP, $file, 'foo@bar.com', $user0, $user0, 31, null, null), 'SharedWith is not a valid group', true],
+                       [$this->createShare(null, \OCP\Share::SHARE_TYPE_LINK,  $file, $user2, $user0, $user0, 31, null, null), 'SharedWith should be empty', true],
+                       [$this->createShare(null, \OCP\Share::SHARE_TYPE_LINK,  $file, $group0, $user0, $user0, 31, null, null), 'SharedWith should be empty', true],
+                       [$this->createShare(null, \OCP\Share::SHARE_TYPE_LINK,  $file, 'foo@bar.com', $user0, $user0, 31, null, null), 'SharedWith should be empty', true],
+                       [$this->createShare(null, -1, $file, null, $user0, $user0, 31, null, null), 'unkown share type', true],
+
+                       [$this->createShare(null, \OCP\Share::SHARE_TYPE_USER,  $file, $user2, null, $user0, 31, null, null), 'SharedBy should be set', true],
+                       [$this->createShare(null, \OCP\Share::SHARE_TYPE_GROUP, $file, $group0, null, $user0, 31, null, null), 'SharedBy should be set', true],
+                       [$this->createShare(null, \OCP\Share::SHARE_TYPE_LINK,  $file, null, null, $user0, 31, null, null), 'SharedBy should be set', true],
+
+                       [$this->createShare(null, \OCP\Share::SHARE_TYPE_USER,  $file, $user0, $user0, $user0, 31, null, null), 'Can\'t share with yourself', true],
+
+                       [$this->createShare(null, \OCP\Share::SHARE_TYPE_USER,  null, $user2, $user0, $user0, 31, null, null), 'Path should be set', true],
+                       [$this->createShare(null, \OCP\Share::SHARE_TYPE_GROUP, null, $group0, $user0, $user0, 31, null, null), 'Path should be set', true],
+                       [$this->createShare(null, \OCP\Share::SHARE_TYPE_LINK,  null, null, $user0, $user0, 31, null, null), 'Path should be set', true],
+
+                       [$this->createShare(null, \OCP\Share::SHARE_TYPE_USER,  $node, $user2, $user0, $user0, 31, null, null), 'Path should be either a file or a folder', true],
+                       [$this->createShare(null, \OCP\Share::SHARE_TYPE_GROUP, $node, $group0, $user0, $user0, 31, null, null), 'Path should be either a file or a folder', true],
+                       [$this->createShare(null, \OCP\Share::SHARE_TYPE_LINK,  $node, null, $user0, $user0, 31, null, null), 'Path should be either a file or a folder', true],
                ];
 
                $nonShareAble = $this->getMock('\OCP\Files\Folder');
                $nonShareAble->method('isShareable')->willReturn(false);
                $nonShareAble->method('getPath')->willReturn('path');
 
-               $data[] = [$this->createShare(null, \OCP\Share::SHARE_TYPE_USER,  $nonShareAble, $user2, $user, $user, 31, null, null), 'You are not allowed to share path', true];
-               $data[] = [$this->createShare(null, \OCP\Share::SHARE_TYPE_GROUP, $nonShareAble, $group, $user, $user, 31, null, null), 'You are not allowed to share path', true];
-               $data[] = [$this->createShare(null, \OCP\Share::SHARE_TYPE_LINK,  $nonShareAble, null, $user, $user, 31, null, null), 'You are not allowed to share path', true];
+               $data[] = [$this->createShare(null, \OCP\Share::SHARE_TYPE_USER,  $nonShareAble, $user2, $user0, $user0, 31, null, null), 'You are not allowed to share path', true];
+               $data[] = [$this->createShare(null, \OCP\Share::SHARE_TYPE_GROUP, $nonShareAble, $group0, $user0, $user0, 31, null, null), 'You are not allowed to share path', true];
+               $data[] = [$this->createShare(null, \OCP\Share::SHARE_TYPE_LINK,  $nonShareAble, null, $user0, $user0, 31, null, null), 'You are not allowed to share path', true];
 
                $limitedPermssions = $this->getMock('\OCP\Files\File');
                $limitedPermssions->method('isShareable')->willReturn(true);
                $limitedPermssions->method('getPermissions')->willReturn(\OCP\Constants::PERMISSION_READ);
                $limitedPermssions->method('getPath')->willReturn('path');
 
-               $data[] = [$this->createShare(null, \OCP\Share::SHARE_TYPE_USER,  $limitedPermssions, $user2, $user, $user, null, null, null), 'A share requires permissions', true];
-               $data[] = [$this->createShare(null, \OCP\Share::SHARE_TYPE_GROUP, $limitedPermssions, $group, $user, $user, null, null, null), 'A share requires permissions', true];
-               $data[] = [$this->createShare(null, \OCP\Share::SHARE_TYPE_LINK,  $limitedPermssions, null, $user, $user, null, null, null), 'A share requires permissions', true];
+               $data[] = [$this->createShare(null, \OCP\Share::SHARE_TYPE_USER,  $limitedPermssions, $user2, $user0, $user0, null, null, null), 'A share requires permissions', true];
+               $data[] = [$this->createShare(null, \OCP\Share::SHARE_TYPE_GROUP, $limitedPermssions, $group0, $user0, $user0, null, null, null), 'A share requires permissions', true];
+               $data[] = [$this->createShare(null, \OCP\Share::SHARE_TYPE_LINK,  $limitedPermssions, null, $user0, $user0, null, null, null), 'A share requires permissions', true];
 
-               $data[] = [$this->createShare(null, \OCP\Share::SHARE_TYPE_USER,  $limitedPermssions, $user2, $user, $user, 31, null, null), 'Cannot increase permissions of path', true];
-               $data[] = [$this->createShare(null, \OCP\Share::SHARE_TYPE_GROUP, $limitedPermssions, $group, $user, $user, 17, null, null), 'Cannot increase permissions of path', true];
-               $data[] = [$this->createShare(null, \OCP\Share::SHARE_TYPE_LINK,  $limitedPermssions, null, $user, $user, 3, null, null), 'Cannot increase permissions of path', true];
+               $data[] = [$this->createShare(null, \OCP\Share::SHARE_TYPE_USER,  $limitedPermssions, $user2, $user0, $user0, 31, null, null), 'Cannot increase permissions of path', true];
+               $data[] = [$this->createShare(null, \OCP\Share::SHARE_TYPE_GROUP, $limitedPermssions, $group0, $user0, $user0, 17, null, null), 'Cannot increase permissions of path', true];
+               $data[] = [$this->createShare(null, \OCP\Share::SHARE_TYPE_LINK,  $limitedPermssions, null, $user0, $user0, 3, null, null), 'Cannot increase permissions of path', true];
 
                $allPermssions = $this->getMock('\OCP\Files\Folder');
                $allPermssions->method('isShareable')->willReturn(true);
                $allPermssions->method('getPermissions')->willReturn(\OCP\Constants::PERMISSION_ALL);
 
-               $data[] = [$this->createShare(null, \OCP\Share::SHARE_TYPE_USER,  $allPermssions, $user2, $user, $user, 30, null, null), 'Shares need at least read permissions', true];
-               $data[] = [$this->createShare(null, \OCP\Share::SHARE_TYPE_GROUP, $allPermssions, $group, $user, $user, 2, null, null), 'Shares need at least read permissions', true];
-               $data[] = [$this->createShare(null, \OCP\Share::SHARE_TYPE_LINK,  $allPermssions, null, $user, $user, 16, null, null), 'Shares need at least read permissions', true];
+               $data[] = [$this->createShare(null, \OCP\Share::SHARE_TYPE_USER,  $allPermssions, $user2, $user0, $user0, 30, null, null), 'Shares need at least read permissions', true];
+               $data[] = [$this->createShare(null, \OCP\Share::SHARE_TYPE_GROUP, $allPermssions, $group0, $user0, $user0, 2, null, null), 'Shares need at least read permissions', true];
+               $data[] = [$this->createShare(null, \OCP\Share::SHARE_TYPE_LINK,  $allPermssions, null, $user0, $user0, 16, null, null), 'Shares need at least read permissions', true];
 
-               $data[] = [$this->createShare(null, \OCP\Share::SHARE_TYPE_USER,  $allPermssions, $user2, $user, $user, 31, null, null), null, false];
-               $data[] = [$this->createShare(null, \OCP\Share::SHARE_TYPE_GROUP, $allPermssions, $group, $user, $user, 3, null, null), null, false];
-               $data[] = [$this->createShare(null, \OCP\Share::SHARE_TYPE_LINK,  $allPermssions, null, $user, $user, 17, null, null), null, false];
+               $data[] = [$this->createShare(null, \OCP\Share::SHARE_TYPE_USER,  $allPermssions, $user2, $user0, $user0, 31, null, null), null, false];
+               $data[] = [$this->createShare(null, \OCP\Share::SHARE_TYPE_GROUP, $allPermssions, $group0, $user0, $user0, 3, null, null), null, false];
+               $data[] = [$this->createShare(null, \OCP\Share::SHARE_TYPE_LINK,  $allPermssions, null, $user0, $user0, 17, null, null), null, false];
 
                return $data;
        }
@@ -583,6 +575,15 @@ class ManagerTest extends \Test\TestCase {
        public function testGeneralChecks($share, $exceptionMessage, $exception) {
                $thrown = null;
 
+               $this->userManager->method('userExists')->will($this->returnValueMap([
+                       ['user0', true],
+                       ['user1', true],
+               ]));
+
+               $this->groupManager->method('groupExists')->will($this->returnValueMap([
+                       ['group0', true],
+               ]));
+
                try {
                        $this->invokePrivate($this->manager, 'generalCreateChecks', [$share]);
                        $thrown = false;
@@ -795,7 +796,7 @@ class ManagerTest extends \Test\TestCase {
 
                $sharedBy = $this->getMock('\OCP\IUser');
                $sharedWith = $this->getMock('\OCP\IUser');
-               $share->setSharedBy($sharedBy)->setSharedWith($sharedWith);
+               $share->setSharedBy('sharedBy')->setSharedWith('sharedWith');
 
                $this->groupManager
                        ->method('getUserGroupIds')
@@ -806,6 +807,11 @@ class ManagerTest extends \Test\TestCase {
                                ])
                        );
 
+               $this->userManager->method('get')->will($this->returnValueMap([
+                       ['sharedBy', $sharedBy],
+                       ['sharedWith', $sharedWith],
+               ]));
+
                $this->config
                        ->method('getAppValue')
                        ->will($this->returnValueMap([
@@ -820,7 +826,7 @@ class ManagerTest extends \Test\TestCase {
 
                $sharedBy = $this->getMock('\OCP\IUser');
                $sharedWith = $this->getMock('\OCP\IUser');
-               $share->setSharedBy($sharedBy)->setSharedWith($sharedWith);
+               $share->setSharedBy('sharedBy')->setSharedWith('sharedWith');
 
                $path = $this->getMock('\OCP\Files\Node');
                $share->setNode($path);
@@ -834,6 +840,11 @@ class ManagerTest extends \Test\TestCase {
                                ])
                        );
 
+               $this->userManager->method('get')->will($this->returnValueMap([
+                       ['sharedBy', $sharedBy],
+                       ['sharedWith', $sharedWith],
+               ]));
+
                $this->config
                        ->method('getAppValue')
                        ->will($this->returnValueMap([
@@ -859,10 +870,10 @@ class ManagerTest extends \Test\TestCase {
                $sharedWith = $this->getMock('\OCP\IUser');
                $path = $this->getMock('\OCP\Files\Node');
 
-               $share->setSharedWith($sharedWith)->setNode($path)
+               $share->setSharedWith('sharedWith')->setNode($path)
                        ->setProviderId('foo')->setId('bar');
 
-               $share2->setSharedWith($sharedWith)->setNode($path)
+               $share2->setSharedWith('sharedWith')->setNode($path)
                        ->setProviderId('foo')->setId('baz');
 
                $this->defaultProvider
@@ -881,28 +892,32 @@ class ManagerTest extends \Test\TestCase {
                $share  = $this->manager->newShare();
 
                $sharedWith = $this->getMock('\OCP\IUser');
-               $owner = $this->getMock('\OCP\IUser');
+               $sharedWith->method('getUID')->willReturn('sharedWith');
+
+               $this->userManager->method('get')->with('sharedWith')->willReturn($sharedWith);
+
                $path = $this->getMock('\OCP\Files\Node');
 
-               $share->setSharedWith($sharedWith)
+               $share->setSharedWith('sharedWith')
                        ->setNode($path)
-                       ->setShareOwner($owner)
+                       ->setShareOwner('shareOwner')
                        ->setProviderId('foo')
                        ->setId('bar');
 
                $share2 = new \OC\Share20\Share();
                $owner2 = $this->getMock('\OCP\IUser');
                $share2->setShareType(\OCP\Share::SHARE_TYPE_GROUP)
-                       ->setShareOwner($owner2)
+                       ->setShareOwner('shareOwner2')
                        ->setProviderId('foo')
-                       ->setId('baz');
+                       ->setId('baz')
+                       ->setSharedWith('group');
 
                $group = $this->getMock('\OCP\IGroup');
                $group->method('inGroup')
                        ->with($sharedWith)
                        ->willReturn(true);
 
-               $share2->setSharedWith($group);
+               $this->groupManager->method('get')->with('group')->willReturn($group);
 
                $this->defaultProvider
                        ->method('getSharesByPath')
@@ -915,18 +930,18 @@ class ManagerTest extends \Test\TestCase {
        public function testUserCreateChecksIdenticalPathNotSharedWithUser() {
                $share = new \OC\Share20\Share();
                $sharedWith = $this->getMock('\OCP\IUser');
-               $owner = $this->getMock('\OCP\IUser');
                $path = $this->getMock('\OCP\Files\Node');
-               $share->setSharedWith($sharedWith)
+               $share->setSharedWith('sharedWith')
                        ->setNode($path)
-                       ->setShareOwner($owner)
+                       ->setShareOwner('shareOwner')
                        ->setProviderId('foo')
                        ->setId('bar');
 
+               $this->userManager->method('get')->with('sharedWith')->willReturn($sharedWith);
+
                $share2 = new \OC\Share20\Share();
-               $owner2 = $this->getMock('\OCP\IUser');
                $share2->setShareType(\OCP\Share::SHARE_TYPE_GROUP)
-                       ->setShareOwner($owner2)
+                       ->setShareOwner('shareOwner2')
                        ->setProviderId('foo')
                        ->setId('baz');
 
@@ -935,7 +950,9 @@ class ManagerTest extends \Test\TestCase {
                        ->with($sharedWith)
                        ->willReturn(false);
 
-               $share2->setSharedWith($group);
+               $this->groupManager->method('get')->with('group')->willReturn($group);
+
+               $share2->setSharedWith('group');
 
                $this->defaultProvider
                        ->method('getSharesByPath')
@@ -952,11 +969,14 @@ class ManagerTest extends \Test\TestCase {
        public function testGroupCreateChecksShareWithGroupMembersOnlyNotInGroup() {
                $share = new \OC\Share20\Share();
 
-               $sharedBy = $this->getMock('\OCP\IUser');
-               $sharedWith = $this->getMock('\OCP\IGroup');
-               $share->setSharedBy($sharedBy)->setSharedWith($sharedWith);
+               $user = $this->getMock('\OCP\IUser');
+               $group = $this->getMock('\OCP\IGroup');
+               $share->setSharedBy('user')->setSharedWith('group');
 
-               $sharedWith->method('inGroup')->with($sharedBy)->willReturn(false);
+               $group->method('inGroup')->with($user)->willReturn(false);
+
+               $this->groupManager->method('get')->with('group')->willReturn($group);
+               $this->userManager->method('get')->with('user')->willReturn($user);
 
                $this->config
                        ->method('getAppValue')
@@ -970,11 +990,14 @@ class ManagerTest extends \Test\TestCase {
        public function testGroupCreateChecksShareWithGroupMembersOnlyInGroup() {
                $share = new \OC\Share20\Share();
 
-               $sharedBy = $this->getMock('\OCP\IUser');
-               $sharedWith = $this->getMock('\OCP\IGroup');
-               $share->setSharedBy($sharedBy)->setSharedWith($sharedWith);
+               $user = $this->getMock('\OCP\IUser');
+               $group = $this->getMock('\OCP\IGroup');
+               $share->setSharedBy('user')->setSharedWith('group');
 
-               $sharedWith->method('inGroup')->with($sharedBy)->willReturn(true);
+               $this->userManager->method('get')->with('user')->willReturn($user);
+               $this->groupManager->method('get')->with('group')->willReturn($group);
+
+               $group->method('inGroup')->with($user)->willReturn(true);
 
                $path = $this->getMock('\OCP\Files\Node');
                $share->setNode($path);
@@ -999,15 +1022,14 @@ class ManagerTest extends \Test\TestCase {
        public function testGroupCreateChecksPathAlreadySharedWithSameGroup() {
                $share = $this->manager->newShare();
 
-               $sharedWith = $this->getMock('\OCP\IGroup');
                $path = $this->getMock('\OCP\Files\Node');
-               $share->setSharedWith($sharedWith)
+               $share->setSharedWith('sharedWith')
                        ->setNode($path)
                        ->setProviderId('foo')
                        ->setId('bar');
 
                $share2 = new \OC\Share20\Share();
-               $share2->setSharedWith($sharedWith)
+               $share2->setSharedWith('sharedWith')
                        ->setProviderId('foo')
                        ->setId('baz');
 
@@ -1021,15 +1043,13 @@ class ManagerTest extends \Test\TestCase {
        public function testGroupCreateChecksPathAlreadySharedWithDifferentGroup() {
                $share = new \OC\Share20\Share();
 
-               $sharedWith = $this->getMock('\OCP\IGroup');
-               $share->setSharedWith($sharedWith);
+               $share->setSharedWith('sharedWith');
 
                $path = $this->getMock('\OCP\Files\Node');
                $share->setNode($path);
 
                $share2 = new \OC\Share20\Share();
-               $sharedWith2 = $this->getMock('\OCP\IGroup');
-               $share2->setSharedWith($sharedWith2);
+               $share2->setSharedWith('sharedWith2');
 
                $this->defaultProvider->method('getSharesByPath')
                        ->with($path)
@@ -1238,7 +1258,9 @@ class ManagerTest extends \Test\TestCase {
                        ->with($user)
                        ->willReturn($groupIds);
 
-               $res = $this->manager->sharingDisabledForUser($user);
+               $this->userManager->method('get')->with('user')->willReturn($user);
+
+               $res = $this->manager->sharingDisabledForUser('user');
                $this->assertEquals($expected, $res);
        }
 
@@ -1278,7 +1300,7 @@ class ManagerTest extends \Test\TestCase {
 
                $user = $this->getMock('\OCP\IUser');
                $share = $this->manager->newShare();
-               $share->setSharedBy($user);
+               $share->setSharedBy('user');
 
                $res = $this->invokePrivate($manager, 'canShare', [$share]);
                $this->assertEquals($expected, $res);
@@ -1303,9 +1325,8 @@ class ManagerTest extends \Test\TestCase {
                        ->setMethods(['canShare', 'generalCreateChecks', 'userCreateChecks', 'pathCreateChecks'])
                        ->getMock();
 
-               $sharedWith = $this->getMock('\OCP\IUser');
-               $sharedBy = $this->getMock('\OCP\IUser');
                $shareOwner = $this->getMock('\OCP\IUser');
+               $shareOwner->method('getUID')->willReturn('shareOwner');
 
                $path = $this->getMock('\OCP\Files\File');
                $path->method('getOwner')->willReturn($shareOwner);
@@ -1315,8 +1336,8 @@ class ManagerTest extends \Test\TestCase {
                        null,
                        \OCP\Share::SHARE_TYPE_USER,
                        $path,
-                       $sharedWith,
-                       $sharedBy,
+                       'sharedWith',
+                       'sharedBy',
                        null,
                        \OCP\Constants::PERMISSION_ALL);
 
@@ -1342,7 +1363,7 @@ class ManagerTest extends \Test\TestCase {
 
                $share->expects($this->once())
                        ->method('setShareOwner')
-                       ->with($shareOwner);
+                       ->with('shareOwner');
                $share->expects($this->once())
                        ->method('setTarget')
                        ->with('/target');
@@ -1355,9 +1376,8 @@ class ManagerTest extends \Test\TestCase {
                        ->setMethods(['canShare', 'generalCreateChecks', 'groupCreateChecks', 'pathCreateChecks'])
                        ->getMock();
 
-               $sharedWith = $this->getMock('\OCP\IGroup');
-               $sharedBy = $this->getMock('\OCP\IUser');
                $shareOwner = $this->getMock('\OCP\IUser');
+               $shareOwner->method('getUID')->willReturn('shareOwner');
 
                $path = $this->getMock('\OCP\Files\File');
                $path->method('getOwner')->willReturn($shareOwner);
@@ -1367,8 +1387,8 @@ class ManagerTest extends \Test\TestCase {
                        null,
                        \OCP\Share::SHARE_TYPE_GROUP,
                        $path,
-                       $sharedWith,
-                       $sharedBy,
+                       'sharedWith',
+                       'sharedBy',
                        null,
                        \OCP\Constants::PERMISSION_ALL);
 
@@ -1394,7 +1414,7 @@ class ManagerTest extends \Test\TestCase {
 
                $share->expects($this->once())
                        ->method('setShareOwner')
-                       ->with($shareOwner);
+                       ->with('shareOwner');
                $share->expects($this->once())
                        ->method('setTarget')
                        ->with('/target');
@@ -1414,9 +1434,8 @@ class ManagerTest extends \Test\TestCase {
                        ])
                        ->getMock();
 
-               $sharedBy = $this->getMock('\OCP\IUser');
-               $sharedBy->method('getUID')->willReturn('sharedBy');
                $shareOwner = $this->getMock('\OCP\IUser');
+               $shareOwner->method('getUID')->willReturn('shareOwner');
 
                $path = $this->getMock('\OCP\Files\File');
                $path->method('getOwner')->willReturn($shareOwner);
@@ -1428,7 +1447,7 @@ class ManagerTest extends \Test\TestCase {
                $share = $this->manager->newShare();
                $share->setShareType(\OCP\Share::SHARE_TYPE_LINK)
                        ->setNode($path)
-                       ->setSharedBy($sharedBy)
+                       ->setSharedBy('sharedBy')
                        ->setPermissions(\OCP\Constants::PERMISSION_ALL)
                        ->setExpirationDate($date)
                        ->setPassword('password');
@@ -1515,7 +1534,7 @@ class ManagerTest extends \Test\TestCase {
                /** @var IShare $share */
                $share = $manager->createShare($share);
 
-               $this->assertSame($shareOwner, $share->getShareOwner());
+               $this->assertSame('shareOwner', $share->getShareOwner());
                $this->assertEquals('/target', $share->getTarget());
                $this->assertSame($date, $share->getExpirationDate());
                $this->assertEquals('token', $share->getToken());
@@ -1536,9 +1555,8 @@ class ManagerTest extends \Test\TestCase {
                        ])
                        ->getMock();
 
-               $sharedWith = $this->getMock('\OCP\IUser');
-               $sharedBy = $this->getMock('\OCP\IUser');
                $shareOwner = $this->getMock('\OCP\IUser');
+               $shareOwner->method('getUID')->willReturn('shareOwner');
 
                $path = $this->getMock('\OCP\Files\File');
                $path->method('getOwner')->willReturn($shareOwner);
@@ -1548,8 +1566,8 @@ class ManagerTest extends \Test\TestCase {
                        null,
                        \OCP\Share::SHARE_TYPE_USER,
                        $path,
-                       $sharedWith,
-                       $sharedBy,
+                       'sharedWith',
+                       'sharedBy',
                        null,
                        \OCP\Constants::PERMISSION_ALL);
 
@@ -1569,7 +1587,7 @@ class ManagerTest extends \Test\TestCase {
 
                $share->expects($this->once())
                        ->method('setShareOwner')
-                       ->with($shareOwner);
+                       ->with('shareOwner');
                $share->expects($this->once())
                        ->method('setTarget')
                        ->with('/target');
@@ -1591,7 +1609,8 @@ class ManagerTest extends \Test\TestCase {
                        $this->mountManager,
                        $this->groupManager,
                        $this->l,
-                       $factory
+                       $factory,
+                       $this->userManager
                );
 
                $share = $this->getMock('\OCP\Share\IShare');
@@ -1718,12 +1737,9 @@ class ManagerTest extends \Test\TestCase {
                        ])
                        ->getMock();
 
-               $origGroup = $this->getMock('\OCP\IGroup');
-               $newGroup = $this->getMock('\OCP\IGroup');
-
                $originalShare = new \OC\Share20\Share();
                $originalShare->setShareType(\OCP\Share::SHARE_TYPE_GROUP)
-                       ->setSharedWith($origGroup);
+                       ->setSharedWith('origGroup');
 
                $manager->expects($this->once())->method('canShare')->willReturn(true);
                $manager->expects($this->once())->method('getShareById')->with('foo:42')->willReturn($originalShare);
@@ -1732,7 +1748,7 @@ class ManagerTest extends \Test\TestCase {
                $share->setProviderId('foo')
                        ->setId('42')
                        ->setShareType(\OCP\Share::SHARE_TYPE_GROUP)
-                       ->setSharedWith($newGroup);
+                       ->setSharedWith('newGroup');
 
                $manager->updateShare($share);
        }
@@ -1749,12 +1765,9 @@ class ManagerTest extends \Test\TestCase {
                        ])
                        ->getMock();
 
-               $origUser = $this->getMock('\OCP\IUser');
-               $newUser = $this->getMock('\OCP\IUser');
-
                $originalShare = new \OC\Share20\Share();
                $originalShare->setShareType(\OCP\Share::SHARE_TYPE_USER)
-                       ->setSharedWith($origUser);
+                       ->setSharedWith('sharedWith');
 
                $manager->expects($this->once())->method('canShare')->willReturn(true);
                $manager->expects($this->once())->method('getShareById')->with('foo:42')->willReturn($originalShare);
@@ -1763,8 +1776,8 @@ class ManagerTest extends \Test\TestCase {
                $share->setProviderId('foo')
                        ->setId('42')
                        ->setShareType(\OCP\Share::SHARE_TYPE_USER)
-                       ->setSharedWith($newUser)
-                       ->setShareOwner($newUser);
+                       ->setSharedWith('newUser')
+                       ->setShareOwner('newUser');
 
                $manager->updateShare($share);
        }
@@ -1780,12 +1793,9 @@ class ManagerTest extends \Test\TestCase {
                        ])
                        ->getMock();
 
-               $origUser = $this->getMock('\OCP\IUser');
-               $newUser = $this->getMock('\OCP\IUser');
-
                $originalShare = new \OC\Share20\Share();
                $originalShare->setShareType(\OCP\Share::SHARE_TYPE_USER)
-                       ->setSharedWith($origUser);
+                       ->setSharedWith('origUser');
 
                $manager->expects($this->once())->method('canShare')->willReturn(true);
                $manager->expects($this->once())->method('getShareById')->with('foo:42')->willReturn($originalShare);
@@ -1794,8 +1804,8 @@ class ManagerTest extends \Test\TestCase {
                $share->setProviderId('foo')
                        ->setId('42')
                        ->setShareType(\OCP\Share::SHARE_TYPE_USER)
-                       ->setSharedWith($origUser)
-                       ->setShareOwner($newUser);
+                       ->setSharedWith('origUser')
+                       ->setShareOwner('newUser');
 
                $this->defaultProvider->expects($this->once())
                        ->method('update')
@@ -1821,12 +1831,9 @@ class ManagerTest extends \Test\TestCase {
                        ])
                        ->getMock();
 
-               $origGroup = $this->getMock('\OCP\IGroup');
-               $user = $this->getMock('\OCP\IUser');
-
                $originalShare = new \OC\Share20\Share();
                $originalShare->setShareType(\OCP\Share::SHARE_TYPE_GROUP)
-                       ->setSharedWith($origGroup);
+                       ->setSharedWith('origUser');
 
                $manager->expects($this->once())->method('canShare')->willReturn(true);
                $manager->expects($this->once())->method('getShareById')->with('foo:42')->willReturn($originalShare);
@@ -1835,8 +1842,8 @@ class ManagerTest extends \Test\TestCase {
                $share->setProviderId('foo')
                        ->setId('42')
                        ->setShareType(\OCP\Share::SHARE_TYPE_GROUP)
-                       ->setSharedWith($origGroup)
-                       ->setShareOwner($user);
+                       ->setSharedWith('origUser')
+                       ->setShareOwner('owner');
 
                $this->defaultProvider->expects($this->once())
                        ->method('update')
@@ -1864,9 +1871,6 @@ class ManagerTest extends \Test\TestCase {
                        ])
                        ->getMock();
 
-               $user = $this->getMock('\OCP\IUser');
-               $user->method('getUID')->willReturn('owner');
-
                $originalShare = new \OC\Share20\Share();
                $originalShare->setShareType(\OCP\Share::SHARE_TYPE_LINK);
 
@@ -1881,8 +1885,8 @@ class ManagerTest extends \Test\TestCase {
                $share->setProviderId('foo')
                        ->setId('42')
                        ->setShareType(\OCP\Share::SHARE_TYPE_LINK)
-                       ->setSharedBy($user)
-                       ->setShareOwner($user)
+                       ->setSharedBy('owner')
+                       ->setShareOwner('owner')
                        ->setPassword('password')
                        ->setExpirationDate($tomorrow)
                        ->setNode($file);
@@ -1930,24 +1934,20 @@ class ManagerTest extends \Test\TestCase {
                $share = $this->manager->newShare();
                $share->setShareType(\OCP\Share::SHARE_TYPE_USER);
 
-               $sharedWith = $this->getMock('\OCP\IUser');
-               $share->setSharedWith($sharedWith);
-
-               $recipient = $this->getMock('\OCP\IUser');
+               $share->setSharedWith('sharedWith');
 
-               $this->manager->moveShare($share, $recipient);
+               $this->manager->moveShare($share, 'recipient');
        }
 
        public function testMoveShareUser() {
                $share = $this->manager->newShare();
                $share->setShareType(\OCP\Share::SHARE_TYPE_USER);
 
-               $recipient = $this->getMock('\OCP\IUser');
-               $share->setSharedWith($recipient);
+               $share->setSharedWith('recipient');
 
-               $this->defaultProvider->method('move')->with($share, $recipient)->will($this->returnArgument(0));
+               $this->defaultProvider->method('move')->with($share, 'recipient')->will($this->returnArgument(0));
 
-               $this->manager->moveShare($share, $recipient);
+               $this->manager->moveShare($share, 'recipient');
        }
 
        /**
@@ -1959,27 +1959,33 @@ class ManagerTest extends \Test\TestCase {
                $share->setShareType(\OCP\Share::SHARE_TYPE_GROUP);
 
                $sharedWith = $this->getMock('\OCP\IGroup');
-               $share->setSharedWith($sharedWith);
+               $share->setSharedWith('shareWith');
 
                $recipient = $this->getMock('\OCP\IUser');
                $sharedWith->method('inGroup')->with($recipient)->willReturn(false);
 
-               $this->manager->moveShare($share, $recipient);
+               $this->groupManager->method('get')->with('shareWith')->willReturn($sharedWith);
+               $this->userManager->method('get')->with('recipient')->willReturn($recipient);
+
+               $this->manager->moveShare($share, 'recipient');
        }
 
        public function testMoveShareGroup() {
                $share = $this->manager->newShare();
                $share->setShareType(\OCP\Share::SHARE_TYPE_GROUP);
 
-               $sharedWith = $this->getMock('\OCP\IGroup');
-               $share->setSharedWith($sharedWith);
+               $group = $this->getMock('\OCP\IGroup');
+               $share->setSharedWith('group');
 
                $recipient = $this->getMock('\OCP\IUser');
-               $sharedWith->method('inGroup')->with($recipient)->willReturn(true);
+               $group->method('inGroup')->with($recipient)->willReturn(true);
 
-               $this->defaultProvider->method('move')->with($share, $recipient)->will($this->returnArgument(0));
+               $this->groupManager->method('get')->with('group')->willReturn($group);
+               $this->userManager->method('get')->with('recipient')->willReturn($recipient);
 
-               $this->manager->moveShare($share, $recipient);
+               $this->defaultProvider->method('move')->with($share, 'recipient')->will($this->returnArgument(0));
+
+               $this->manager->moveShare($share, 'recipient');
        }
 }