public function testMoveGroupShare()
 {
     $id = $this->addShareToDB(\OCP\Share::SHARE_TYPE_GROUP, 'group0', 'user1', 'user1', 'file', 42, 'mytaret', 31, null, null);
     $user0 = $this->getMock('\\OCP\\IUser');
     $user0->method('getUID')->willReturn('user0');
     $user1 = $this->getMock('\\OCP\\IUser');
     $user1->method('getUID')->willReturn('user1');
     $group0 = $this->getMock('\\OCP\\IGroup');
     $group0->method('getGID')->willReturn('group0');
     $group0->method('inGroup')->with($user0)->willReturn(true);
     $this->groupManager->method('get')->with('group0')->willReturn($group0);
     $this->userManager->method('get')->will($this->returnValueMap([['user0', $user0], ['user1', $user1]]));
     $folder = $this->getMock('\\OCP\\Files\\Folder');
     $folder->method('getId')->willReturn(42);
     $this->rootFolder->method('getUserFolder')->with('user1')->will($this->returnSelf());
     $this->rootFolder->method('getById')->willReturn([$folder]);
     $share = $this->provider->getShareById($id, 'user0');
     $share->setTarget('/newTarget');
     $this->provider->move($share, 'user0');
     $share = $this->provider->getShareById($id, 'user0');
     $this->assertSame('/newTarget', $share->getTarget());
     $share->setTarget('/ultraNewTarget');
     $this->provider->move($share, 'user0');
     $share = $this->provider->getShareById($id, 'user0');
     $this->assertSame('/ultraNewTarget', $share->getTarget());
 }
예제 #2
0
 public function testUpdateGroupSubShares()
 {
     $id = $this->addShareToDB(\OCP\Share::SHARE_TYPE_GROUP, 'group0', 'user1', 'user2', 'file', 42, 'target', 31, null, null);
     $id2 = $this->addShareToDB(2, 'user0', 'user1', 'user2', 'file', 42, 'mytarget', 31, null, null, $id);
     $id3 = $this->addShareToDB(2, 'user3', 'user1', 'user2', 'file', 42, 'mytarget2', 0, null, null, $id);
     $users = [];
     for ($i = 0; $i < 6; $i++) {
         $user = $this->getMock('\\OCP\\IUser');
         $user->method('getUID')->willReturn('user' . $i);
         $users['user' . $i] = $user;
     }
     $this->userManager->method('get')->will($this->returnCallback(function ($userId) use($users) {
         return $users[$userId];
     }));
     $groups = [];
     for ($i = 0; $i < 2; $i++) {
         $group = $this->getMock('\\OCP\\IGroup');
         $group->method('getGID')->willReturn('group' . $i);
         $groups['group' . $i] = $group;
     }
     $this->groupManager->method('get')->will($this->returnCallback(function ($groupId) use($groups) {
         return $groups[$groupId];
     }));
     $file1 = $this->getMock('\\OCP\\Files\\File');
     $file1->method('getId')->willReturn(42);
     $file2 = $this->getMock('\\OCP\\Files\\File');
     $file2->method('getId')->willReturn(43);
     $folder1 = $this->getMock('\\OCP\\Files\\Folder');
     $folder1->method('getById')->with(42)->willReturn([$file1]);
     $folder2 = $this->getMock('\\OCP\\Files\\Folder');
     $folder2->method('getById')->with(43)->willReturn([$file2]);
     $this->rootFolder->method('getUserFolder')->will($this->returnValueMap([['user2', $folder1], ['user5', $folder2]]));
     $share = $this->provider->getShareById($id);
     $share->setSharedWith($groups['group0']);
     $share->setSharedBy($users['user4']);
     $share->setShareOwner($users['user5']);
     $share->setNode($file2);
     $share->setPermissions(1);
     $share2 = $this->provider->update($share);
     $this->assertEquals($id, $share2->getId());
     // Group shares do not allow updating the recipient
     $this->assertSame($groups['group0'], $share2->getSharedWith());
     $this->assertSame($users['user4'], $share2->getSharedBy());
     $this->assertSame($users['user5'], $share2->getShareOwner());
     $this->assertSame(1, $share2->getPermissions());
     $qb = $this->dbConn->getQueryBuilder();
     $stmt = $qb->select('*')->from('share')->where($qb->expr()->eq('parent', $qb->createNamedParameter($id)))->orderBy('id')->execute();
     $shares = $stmt->fetchAll();
     $this->assertSame('user0', $shares[0]['share_with']);
     $this->assertSame('user4', $shares[0]['uid_initiator']);
     $this->assertSame('user5', $shares[0]['uid_owner']);
     $this->assertSame(1, (int) $shares[0]['permissions']);
     $this->assertSame('user3', $shares[1]['share_with']);
     $this->assertSame('user4', $shares[1]['uid_initiator']);
     $this->assertSame('user5', $shares[1]['uid_owner']);
     $this->assertSame(0, (int) $shares[1]['permissions']);
     $stmt->closeCursor();
 }
 public function testGetChildren()
 {
     $qb = $this->dbConn->getQueryBuilder();
     $qb->insert('share')->values(['share_type' => $qb->expr()->literal(\OCP\Share::SHARE_TYPE_USER), 'share_with' => $qb->expr()->literal('sharedWith'), 'uid_owner' => $qb->expr()->literal('sharedBy'), 'item_type' => $qb->expr()->literal('file'), 'file_source' => $qb->expr()->literal(42), 'file_target' => $qb->expr()->literal('myTarget'), 'permissions' => $qb->expr()->literal(13)]);
     $qb->execute();
     // Get the id
     $qb = $this->dbConn->getQueryBuilder();
     $cursor = $qb->select('id')->from('share')->setMaxResults(1)->orderBy('id', 'DESC')->execute();
     $id = $cursor->fetch();
     $id = $id['id'];
     $cursor->closeCursor();
     $qb = $this->dbConn->getQueryBuilder();
     $qb->insert('share')->values(['share_type' => $qb->expr()->literal(\OCP\Share::SHARE_TYPE_USER), 'share_with' => $qb->expr()->literal('user1'), 'uid_owner' => $qb->expr()->literal('user2'), 'item_type' => $qb->expr()->literal('file'), 'file_source' => $qb->expr()->literal(1), 'file_target' => $qb->expr()->literal('myTarget1'), 'permissions' => $qb->expr()->literal(2), 'parent' => $qb->expr()->literal($id)]);
     $qb->execute();
     $qb = $this->dbConn->getQueryBuilder();
     $qb->insert('share')->values(['share_type' => $qb->expr()->literal(\OCP\Share::SHARE_TYPE_GROUP), 'share_with' => $qb->expr()->literal('group1'), 'uid_owner' => $qb->expr()->literal('user3'), 'item_type' => $qb->expr()->literal('folder'), 'file_source' => $qb->expr()->literal(3), 'file_target' => $qb->expr()->literal('myTarget2'), 'permissions' => $qb->expr()->literal(4), 'parent' => $qb->expr()->literal($id)]);
     $qb->execute();
     $storage = $this->getMock('OC\\Files\\Storage\\Storage');
     $storage->method('getOwner')->willReturn('shareOwner');
     $path1 = $this->getMock('OCP\\Files\\File');
     $path1->expects($this->once())->method('getStorage')->willReturn($storage);
     $path2 = $this->getMock('OCP\\Files\\Folder');
     $path2->expects($this->once())->method('getStorage')->willReturn($storage);
     $this->userFolder->method('getById')->will($this->returnValueMap([[1, [$path1]], [3, [$path2]]]));
     $shareOwner = $this->getMock('OCP\\IUser');
     $user1 = $this->getMock('OCP\\IUser');
     $user2 = $this->getMock('OCP\\IUser');
     $user3 = $this->getMock('OCP\\IUser');
     $this->userManager->method('get')->will($this->returnValueMap([['shareOwner', $shareOwner], ['user1', $user1], ['user2', $user2], ['user3', $user3]]));
     $group1 = $this->getMock('OCP\\IGroup');
     $this->groupManager->method('get')->will($this->returnValueMap([['group1', $group1]]));
     $share = $this->getMock('\\OC\\Share20\\IShare');
     $share->method('getId')->willReturn($id);
     $children = $this->provider->getChildren($share);
     $this->assertCount(2, $children);
     //Child1
     $this->assertEquals(\OCP\Share::SHARE_TYPE_USER, $children[0]->getShareType());
     $this->assertEquals($user1, $children[0]->getSharedWith());
     $this->assertEquals($user2, $children[0]->getSharedBy());
     $this->assertEquals($shareOwner, $children[0]->getShareOwner());
     $this->assertEquals($path1, $children[0]->getPath());
     $this->assertEquals(2, $children[0]->getPermissions());
     $this->assertEquals(null, $children[0]->getToken());
     $this->assertEquals(null, $children[0]->getExpirationDate());
     $this->assertEquals('myTarget1', $children[0]->getTarget());
     //Child2
     $this->assertEquals(\OCP\Share::SHARE_TYPE_GROUP, $children[1]->getShareType());
     $this->assertEquals($group1, $children[1]->getSharedWith());
     $this->assertEquals($user3, $children[1]->getSharedBy());
     $this->assertEquals($shareOwner, $children[1]->getShareOwner());
     $this->assertEquals($path2, $children[1]->getPath());
     $this->assertEquals(4, $children[1]->getPermissions());
     $this->assertEquals(null, $children[1]->getToken());
     $this->assertEquals(null, $children[1]->getExpirationDate());
     $this->assertEquals('myTarget2', $children[1]->getTarget());
 }
예제 #4
0
 /**
  * @expectedException \OC\Share20\Exception\ProviderException
  * @expectedExceptionMessage Invalid shareType
  */
 public function testDeleteFromSelfLink()
 {
     $qb = $this->dbConn->getQueryBuilder();
     $stmt = $qb->insert('share')->values(['share_type' => $qb->expr()->literal(\OCP\Share::SHARE_TYPE_LINK), 'uid_owner' => $qb->expr()->literal('user1'), 'uid_initiator' => $qb->expr()->literal('user1'), 'item_type' => $qb->expr()->literal('file'), 'file_source' => $qb->expr()->literal(1), 'file_target' => $qb->expr()->literal('myTarget1'), 'permissions' => $qb->expr()->literal(2), 'token' => $qb->expr()->literal('token')])->execute();
     $this->assertEquals(1, $stmt);
     $id = $qb->getLastInsertId();
     $user1 = $this->getMock('\\OCP\\IUser');
     $user1->method('getUID')->willReturn('user1');
     $this->userManager->method('get')->will($this->returnValueMap([['user1', $user1]]));
     $file = $this->getMock('\\OCP\\Files\\File');
     $file->method('getId')->willReturn(1);
     $this->rootFolder->method('getUserFolder')->with('user1')->will($this->returnSelf());
     $this->rootFolder->method('getById')->with(1)->willReturn([$file]);
     $share = $this->provider->getShareById($id);
     $this->provider->deleteFromSelf($share, $user1);
 }
 /**
  * Given a group share with 'group1'
  * And a user specific group share with 'user1'.
  * User $user is deleted from group $gid.
  *
  * @dataProvider dataUserDeletedFromGroup
  *
  * @param string $group
  * @param string $user
  * @param bool $toDelete
  */
 public function testUserDeletedFromGroup($group, $user, $toDelete)
 {
     $qb = $this->dbConn->getQueryBuilder();
     $qb->insert('share')->setValue('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP))->setValue('uid_owner', $qb->createNamedParameter('owner'))->setValue('uid_initiator', $qb->createNamedParameter('initiator'))->setValue('share_with', $qb->createNamedParameter('group1'))->setValue('item_type', $qb->createNamedParameter('file'))->setValue('item_source', $qb->createNamedParameter(42))->setValue('file_source', $qb->createNamedParameter(42));
     $qb->execute();
     $id1 = $qb->getLastInsertId();
     $qb = $this->dbConn->getQueryBuilder();
     $qb->insert('share')->setValue('share_type', $qb->createNamedParameter(2))->setValue('uid_owner', $qb->createNamedParameter('owner'))->setValue('uid_initiator', $qb->createNamedParameter('initiator'))->setValue('share_with', $qb->createNamedParameter('user1'))->setValue('item_type', $qb->createNamedParameter('file'))->setValue('item_source', $qb->createNamedParameter(42))->setValue('file_source', $qb->createNamedParameter(42))->setValue('parent', $qb->createNamedParameter($id1));
     $qb->execute();
     $id2 = $qb->getLastInsertId();
     $this->provider->userDeletedFromGroup($user, $group);
     $qb = $this->dbConn->getQueryBuilder();
     $qb->select('*')->from('share')->where($qb->expr()->eq('id', $qb->createNamedParameter($id2)));
     $cursor = $qb->execute();
     $data = $cursor->fetchAll();
     $cursor->closeCursor();
     $this->assertCount($toDelete ? 0 : 1, $data);
 }
예제 #6
0
 public function testDeleteNestedShares()
 {
     $qb = $this->dbConn->getQueryBuilder();
     $qb->insert('share')->values(['share_type' => $qb->expr()->literal(\OCP\Share::SHARE_TYPE_USER), 'share_with' => $qb->expr()->literal('sharedWith'), 'uid_owner' => $qb->expr()->literal('sharedBy'), 'item_type' => $qb->expr()->literal('file'), 'file_source' => $qb->expr()->literal(42), 'file_target' => $qb->expr()->literal('myTarget'), 'permissions' => $qb->expr()->literal(13)]);
     $this->assertEquals(1, $qb->execute());
     // Get the id
     $qb = $this->dbConn->getQueryBuilder();
     $cursor = $qb->select('id')->from('share')->setMaxResults(1)->orderBy('id', 'DESC')->execute();
     $id1 = $cursor->fetch();
     $id1 = $id1['id'];
     $cursor->closeCursor();
     $qb = $this->dbConn->getQueryBuilder();
     $qb->insert('share')->values(['share_type' => $qb->expr()->literal(\OCP\Share::SHARE_TYPE_USER), 'share_with' => $qb->expr()->literal('sharedWith'), 'uid_owner' => $qb->expr()->literal('sharedBy'), 'item_type' => $qb->expr()->literal('file'), 'file_source' => $qb->expr()->literal(42), 'file_target' => $qb->expr()->literal('myTarget'), 'permissions' => $qb->expr()->literal(13), 'parent' => $qb->expr()->literal($id1)]);
     $this->assertEquals(1, $qb->execute());
     // Get the id
     $qb = $this->dbConn->getQueryBuilder();
     $cursor = $qb->select('id')->from('share')->setMaxResults(1)->orderBy('id', 'DESC')->execute();
     $id2 = $cursor->fetch();
     $id2 = $id2['id'];
     $cursor->closeCursor();
     $qb = $this->dbConn->getQueryBuilder();
     $qb->insert('share')->values(['share_type' => $qb->expr()->literal(\OCP\Share::SHARE_TYPE_USER), 'share_with' => $qb->expr()->literal('sharedWith'), 'uid_owner' => $qb->expr()->literal('sharedBy'), 'item_type' => $qb->expr()->literal('file'), 'file_source' => $qb->expr()->literal(42), 'file_target' => $qb->expr()->literal('myTarget'), 'permissions' => $qb->expr()->literal(13), 'parent' => $qb->expr()->literal($id2)]);
     $this->assertEquals(1, $qb->execute());
     $storage = $this->getMock('OC\\Files\\Storage\\Storage');
     $storage->method('getOwner')->willReturn('shareOwner');
     $path = $this->getMock('OCP\\Files\\Node');
     $path->method('getStorage')->wilLReturn($storage);
     $this->userFolder->method('getById')->with(42)->willReturn([$path]);
     $sharedWith = $this->getMock('OCP\\IUser');
     $sharedWith->method('getUID')->willReturn('sharedWith');
     $sharedBy = $this->getMock('OCP\\IUser');
     $sharedBy->method('getUID')->willReturn('sharedBy');
     $shareOwner = $this->getMock('OCP\\IUser');
     $this->userManager->method('get')->will($this->returnValueMap([['sharedWith', $sharedWith], ['sharedBy', $sharedBy], ['shareOwner', $shareOwner]]));
     $share = $this->provider->getShareById($id1);
     $this->provider->delete($share);
     $qb = $this->dbConn->getQueryBuilder();
     $qb->select('*')->from('share');
     $cursor = $qb->execute();
     $result = $cursor->fetchAll();
     $cursor->closeCursor();
     $this->assertEmpty($result);
 }
예제 #7
0
 public function testCreateLinkShare()
 {
     $share = new \OC\Share20\Share();
     $sharedBy = $this->getMock('OCP\\IUser');
     $sharedBy->method('getUID')->willReturn('sharedBy');
     $shareOwner = $this->getMock('OCP\\IUser');
     $shareOwner->method('getUID')->WillReturn('shareOwner');
     $this->userManager->method('get')->will($this->returnValueMap([['sharedBy', $sharedBy], ['shareOwner', $shareOwner]]));
     $path = $this->getMock('\\OCP\\Files\\Folder');
     $path->method('getId')->willReturn(100);
     $path->method('getOwner')->willReturn($shareOwner);
     $ownerFolder = $this->getMock('OCP\\Files\\Folder');
     $userFolder = $this->getMock('OCP\\Files\\Folder');
     $this->rootFolder->method('getUserFolder')->will($this->returnValueMap([['sharedBy', $userFolder], ['shareOwner', $ownerFolder]]));
     $userFolder->method('getById')->with(100)->willReturn([$path]);
     $ownerFolder->method('getById')->with(100)->willReturn([$path]);
     $share->setShareType(\OCP\Share::SHARE_TYPE_LINK);
     $share->setSharedBy($sharedBy);
     $share->setShareOwner($shareOwner);
     $share->setPath($path);
     $share->setPermissions(1);
     $share->setPassword('password');
     $share->setToken('token');
     $expireDate = new \DateTime();
     $share->setExpirationDate($expireDate);
     $share->setTarget('/target');
     $share2 = $this->provider->create($share);
     $this->assertNotNull($share2->getId());
     $this->assertSame('ocinternal:' . $share2->getId(), $share2->getFullId());
     $this->assertSame(\OCP\Share::SHARE_TYPE_LINK, $share2->getShareType());
     $this->assertSame($sharedBy, $share2->getSharedBy());
     $this->assertSame($shareOwner, $share2->getShareOwner());
     $this->assertSame(1, $share2->getPermissions());
     $this->assertSame('/target', $share2->getTarget());
     $this->assertLessThanOrEqual(time(), $share2->getSharetime());
     $this->assertSame($path, $share2->getPath());
     $this->assertSame('password', $share2->getPassword());
     $this->assertSame('token', $share2->getToken());
     $this->assertEquals($expireDate, $share2->getExpirationDate());
 }
 /**
  * @expectedException \OC\Share20\Exception\ShareNotFound
  */
 public function testGetShareByTokenNotFound()
 {
     $this->provider->getShareByToken('invalidtoken');
 }