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()); }
public function testGetShareByIdRemoteShare() { $qb = $this->dbConn->getQueryBuilder(); $qb->insert('share')->values(['share_type' => $qb->expr()->literal(\OCP\Share::SHARE_TYPE_REMOTE), '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(); $id = $cursor->fetch(); $id = $id['id']; $cursor->closeCursor(); $storage = $this->getMock('OC\\Files\\Storage\\Storage'); $storage->expects($this->once())->method('getOwner')->willReturn('shareOwner'); $path = $this->getMock('OCP\\Files\\Node'); $path->expects($this->once())->method('getStorage')->wilLReturn($storage); $this->userFolder->expects($this->once())->method('getById')->with(42)->willReturn([$path]); $sharedBy = $this->getMock('OCP\\IUser'); $shareOwner = $this->getMock('OCP\\IUser'); $this->userManager->method('get')->will($this->returnValueMap([['sharedBy', $sharedBy], ['shareOwner', $shareOwner]])); $share = $this->provider->getShareById($id); $this->assertEquals($id, $share->getId()); $this->assertEquals(\OCP\Share::SHARE_TYPE_REMOTE, $share->getShareType()); $this->assertEquals('sharedWith', $share->getSharedWith()); $this->assertEquals($sharedBy, $share->getSharedBy()); $this->assertEquals($shareOwner, $share->getShareOwner()); $this->assertEquals($path, $share->getPath()); $this->assertEquals(13, $share->getPermissions()); $this->assertEquals(null, $share->getToken()); $this->assertEquals(null, $share->getExpirationDate()); $this->assertEquals('myTarget', $share->getTarget()); }
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(); }
/** * @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); }
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); }
public function testGetShareByIdLinkShare() { $qb = $this->dbConn->getQueryBuilder(); $qb->insert('share')->values(['share_type' => $qb->expr()->literal(\OCP\Share::SHARE_TYPE_LINK), '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), 'token' => $qb->expr()->literal('token'), 'expiration' => $qb->expr()->literal('2000-01-02 00:00:00')]); $this->assertEquals(1, $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(); $sharedBy = $this->getMock('OCP\\IUser'); $sharedBy->method('getUID')->willReturn('sharedBy'); $shareOwner = $this->getMock('OCP\\IUser'); $shareOwner->method('getUID')->willReturn('shareOwner'); $sharedByPath = $this->getMock('\\OCP\\Files\\Folder'); $ownerPath = $this->getMock('\\OCP\\Files\\Folder'); $sharedByPath->method('getOwner')->willReturn($shareOwner); $sharedByFolder = $this->getMock('\\OCP\\Files\\Folder'); $sharedByFolder->method('getById')->with(42)->willReturn([$sharedByPath]); $shareOwnerFolder = $this->getMock('\\OCP\\Files\\Folder'); $shareOwnerFolder->method('getById')->with(42)->willReturn([$ownerPath]); $this->rootFolder->method('getUserFolder')->will($this->returnValueMap([['sharedBy', $sharedByFolder], ['shareOwner', $shareOwnerFolder]])); $this->userManager->method('get')->will($this->returnValueMap([['sharedBy', $sharedBy], ['shareOwner', $shareOwner]])); $share = $this->provider->getShareById($id); $this->assertEquals($id, $share->getId()); $this->assertEquals(\OCP\Share::SHARE_TYPE_LINK, $share->getShareType()); $this->assertEquals('sharedWith', $share->getPassword()); $this->assertEquals($sharedBy, $share->getSharedBy()); $this->assertEquals($shareOwner, $share->getShareOwner()); $this->assertEquals($ownerPath, $share->getPath()); $this->assertEquals(13, $share->getPermissions()); $this->assertEquals('token', $share->getToken()); $this->assertEquals(\DateTime::createFromFormat('Y-m-d H:i:s', '2000-01-02 00:00:00'), $share->getExpirationDate()); $this->assertEquals('myTarget', $share->getTarget()); }