Exemple #1
0
 function testGetParents()
 {
     $fileinfo1 = $this->view->getFileInfo($this->folder);
     $fileinfo2 = $this->view->getFileInfo($this->folder . $this->subfolder . $this->subsubfolder);
     $fileinfo3 = $this->view->getFileInfo($this->folder . $this->subfolder . $this->subsubfolder . $this->filename);
     $this->assertTrue(\OCP\Share::shareItem('folder', $fileinfo1['fileid'], \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2, 31));
     $this->assertTrue(\OCP\Share::shareItem('folder', $fileinfo2['fileid'], \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER3, 31));
     $backend = new \OC_Share_Backend_Folder();
     $result = $backend->getParents($fileinfo3['fileid']);
     $this->assertSame(2, count($result));
     $count1 = 0;
     $count2 = 0;
     foreach ($result as $r) {
         if ($r['path'] === 'files' . $this->folder) {
             $this->assertSame(ltrim($this->folder, '/'), $r['collection']['path']);
             $count1++;
         } elseif ($r['path'] === 'files' . $this->folder . $this->subfolder . $this->subsubfolder) {
             $this->assertSame(ltrim($this->subsubfolder, '/'), $r['collection']['path']);
             $count2++;
         } else {
             $this->assertTrue(false, 'unexpected result');
         }
     }
     $this->assertSame(1, $count1);
     $this->assertSame(1, $count2);
     $result1 = $backend->getParents($fileinfo3['fileid'], self::TEST_FILES_SHARING_API_USER3);
     $this->assertSame(1, count($result1));
     $elemet = reset($result1);
     $this->assertSame('files' . $this->folder . $this->subfolder . $this->subsubfolder, $elemet['path']);
     $this->assertSame(ltrim($this->subsubfolder, '/'), $elemet['collection']['path']);
 }
 protected function setUp()
 {
     parent::setUp();
     self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
     // prepare user1's dir structure
     $textData = "dummy file data\n";
     $this->view->mkdir('container');
     $this->view->mkdir('container/shareddir');
     $this->view->mkdir('container/shareddir/subdir');
     $this->view->mkdir('container/shareddirrestricted');
     $this->view->mkdir('container/shareddirrestricted/subdir');
     $this->view->file_put_contents('container/shareddir/textfile.txt', $textData);
     $this->view->file_put_contents('container/shareddirrestricted/textfile1.txt', $textData);
     list($this->ownerStorage, $internalPath) = $this->view->resolvePath('');
     $this->ownerCache = $this->ownerStorage->getCache();
     $this->ownerStorage->getScanner()->scan('');
     // share "shareddir" with user2
     $fileinfo = $this->view->getFileInfo('container/shareddir');
     \OCP\Share::shareItem('folder', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2, 31);
     $fileinfo2 = $this->view->getFileInfo('container/shareddirrestricted');
     \OCP\Share::shareItem('folder', $fileinfo2['fileid'], \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2, 7);
     // login as user2
     self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
     // retrieve the shared storage
     $this->secondView = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER2);
     list($this->sharedStorage, $internalPath) = $this->secondView->resolvePath('files/shareddir');
     list($this->sharedStorageRestrictedShare, $internalPath) = $this->secondView->resolvePath('files/shareddirrestricted');
     $this->sharedCache = $this->sharedStorage->getCache();
     $this->sharedCacheRestrictedShare = $this->sharedStorageRestrictedShare->getCache();
 }
Exemple #3
0
 public function testSizePropagationWhenRecipientChangesFile()
 {
     $this->loginHelper(self::TEST_FILES_SHARING_API_USER1);
     $recipientView = new View('/' . self::TEST_FILES_SHARING_API_USER1 . '/files');
     $this->loginHelper(self::TEST_FILES_SHARING_API_USER2);
     $ownerView = new View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files');
     $ownerView->mkdir('/sharedfolder/subfolder');
     $ownerView->file_put_contents('/sharedfolder/subfolder/foo.txt', 'bar');
     $sharedFolderInfo = $ownerView->getFileInfo('/sharedfolder', false);
     $this->assertInstanceOf('\\OC\\Files\\FileInfo', $sharedFolderInfo);
     \OCP\Share::shareItem('folder', $sharedFolderInfo->getId(), \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER1, 31);
     $ownerRootInfo = $ownerView->getFileInfo('', false);
     $this->loginHelper(self::TEST_FILES_SHARING_API_USER1);
     $this->assertTrue($recipientView->file_exists('/sharedfolder/subfolder/foo.txt'));
     $recipientRootInfo = $recipientView->getFileInfo('', false);
     // when file changed as recipient
     $recipientView->file_put_contents('/sharedfolder/subfolder/foo.txt', 'foobar');
     // size of recipient's root stays the same
     $newRecipientRootInfo = $recipientView->getFileInfo('', false);
     $this->assertEquals($recipientRootInfo->getSize(), $newRecipientRootInfo->getSize());
     // size of owner's root increases
     $this->loginHelper(self::TEST_FILES_SHARING_API_USER2);
     $newOwnerRootInfo = $ownerView->getFileInfo('', false);
     $this->assertEquals($ownerRootInfo->getSize() + 3, $newOwnerRootInfo->getSize());
 }
 protected function setUp()
 {
     $app = new Application();
     $this->container = $app->getContainer();
     $this->container['Config'] = $this->getMockBuilder('\\OCP\\IConfig')->disableOriginalConstructor()->getMock();
     $this->container['AppName'] = 'files_sharing';
     $this->container['UserSession'] = $this->getMockBuilder('\\OC\\User\\Session')->disableOriginalConstructor()->getMock();
     $this->container['URLGenerator'] = $this->getMockBuilder('\\OC\\URLGenerator')->disableOriginalConstructor()->getMock();
     $this->urlGenerator = $this->container['URLGenerator'];
     $this->shareController = $this->container['ShareController'];
     // Store current user
     $this->oldUser = \OC_User::getUser();
     // Create a dummy user
     $this->user = \OC::$server->getSecureRandom()->getLowStrengthGenerator()->generate(12, ISecureRandom::CHAR_LOWER);
     \OC_User::createUser($this->user, $this->user);
     \OC_Util::tearDownFS();
     \OC_User::setUserId('');
     Filesystem::tearDown();
     \OC_User::setUserId($this->user);
     \OC_Util::setupFS($this->user);
     // Create a dummy shared file
     $view = new View('/' . $this->user . '/files');
     $view->file_put_contents('file1.txt', 'I am such an awesome shared file!');
     $this->token = \OCP\Share::shareItem(Filesystem::getFileInfo('file1.txt')->getType(), Filesystem::getFileInfo('file1.txt')->getId(), \OCP\Share::SHARE_TYPE_LINK, 'IAmPasswordProtected!', 1);
 }
 /**
  * "user1" is the admin who shares a folder "sub1/sub2/folder" with "user2" and "user3"
  * "user2" receives the folder and puts it in "sub1/sub2/folder"
  * "user3" receives the folder and puts it in "sub1/sub2/folder"
  * "user2" reshares the subdir "sub1/sub2/folder/inside" with "user4"
  * "user4" puts the received "inside" folder into "sub1/sub2/inside" (this is to check if it propagates across multiple subfolders)
  */
 private function setUpShares()
 {
     $this->fileIds[self::TEST_FILES_SHARING_API_USER1] = [];
     $this->fileIds[self::TEST_FILES_SHARING_API_USER2] = [];
     $this->fileIds[self::TEST_FILES_SHARING_API_USER3] = [];
     $this->fileIds[self::TEST_FILES_SHARING_API_USER4] = [];
     $this->rootView = new View('');
     $this->loginAsUser(self::TEST_FILES_SHARING_API_USER1);
     $view1 = new View('/' . self::TEST_FILES_SHARING_API_USER1 . '/files');
     $view1->mkdir('/sub1/sub2/folder/inside');
     $view1->mkdir('/directReshare');
     $view1->mkdir('/sub1/sub2/folder/other');
     $view1->mkdir('/sub1/sub2/folder/other');
     $view1->file_put_contents('/foo.txt', 'foobar');
     $view1->file_put_contents('/sub1/sub2/folder/file.txt', 'foobar');
     $view1->file_put_contents('/sub1/sub2/folder/inside/file.txt', 'foobar');
     $folderInfo = $view1->getFileInfo('/sub1/sub2/folder');
     $fileInfo = $view1->getFileInfo('/foo.txt');
     \OCP\Share::shareItem('file', $fileInfo->getId(), \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2, 31);
     \OCP\Share::shareItem('folder', $folderInfo->getId(), \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2, 31);
     \OCP\Share::shareItem('folder', $folderInfo->getId(), \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER3, 31);
     $folderInfo = $view1->getFileInfo('/directReshare');
     \OCP\Share::shareItem('folder', $folderInfo->getId(), \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2, 31);
     $this->fileIds[self::TEST_FILES_SHARING_API_USER1][''] = $view1->getFileInfo('')->getId();
     $this->fileIds[self::TEST_FILES_SHARING_API_USER1]['sub1'] = $view1->getFileInfo('sub1')->getId();
     $this->fileIds[self::TEST_FILES_SHARING_API_USER1]['sub1/sub2'] = $view1->getFileInfo('sub1/sub2')->getId();
     $this->loginAsUser(self::TEST_FILES_SHARING_API_USER2);
     $view2 = new View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files');
     $view2->mkdir('/sub1/sub2');
     $view2->rename('/folder', '/sub1/sub2/folder');
     $insideInfo = $view2->getFileInfo('/sub1/sub2/folder/inside');
     \OCP\Share::shareItem('folder', $insideInfo->getId(), \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER4, 31);
     $folderInfo = $view2->getFileInfo('/directReshare');
     \OCP\Share::shareItem('folder', $folderInfo->getId(), \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER4, 31);
     $this->fileIds[self::TEST_FILES_SHARING_API_USER2][''] = $view2->getFileInfo('')->getId();
     $this->fileIds[self::TEST_FILES_SHARING_API_USER2]['sub1'] = $view2->getFileInfo('sub1')->getId();
     $this->fileIds[self::TEST_FILES_SHARING_API_USER2]['sub1/sub2'] = $view2->getFileInfo('sub1/sub2')->getId();
     $this->loginAsUser(self::TEST_FILES_SHARING_API_USER3);
     $view3 = new View('/' . self::TEST_FILES_SHARING_API_USER3 . '/files');
     $view3->mkdir('/sub1/sub2');
     $view3->rename('/folder', '/sub1/sub2/folder');
     $this->fileIds[self::TEST_FILES_SHARING_API_USER3][''] = $view3->getFileInfo('')->getId();
     $this->fileIds[self::TEST_FILES_SHARING_API_USER3]['sub1'] = $view3->getFileInfo('sub1')->getId();
     $this->fileIds[self::TEST_FILES_SHARING_API_USER3]['sub1/sub2'] = $view3->getFileInfo('sub1/sub2')->getId();
     $this->loginAsUser(self::TEST_FILES_SHARING_API_USER4);
     $view4 = new View('/' . self::TEST_FILES_SHARING_API_USER4 . '/files');
     $view4->mkdir('/sub1/sub2');
     $view4->rename('/inside', '/sub1/sub2/inside');
     $this->fileIds[self::TEST_FILES_SHARING_API_USER4][''] = $view4->getFileInfo('')->getId();
     $this->fileIds[self::TEST_FILES_SHARING_API_USER4]['sub1'] = $view4->getFileInfo('sub1')->getId();
     $this->fileIds[self::TEST_FILES_SHARING_API_USER4]['sub1/sub2'] = $view4->getFileInfo('sub1/sub2')->getId();
     foreach ($this->fileIds as $user => $ids) {
         $this->loginAsUser($user);
         foreach ($ids as $id) {
             $path = $this->rootView->getPath($id);
             $this->fileEtags[$id] = $this->rootView->getFileInfo($path)->getEtag();
         }
     }
 }
 public function setUp()
 {
     parent::setUp();
     $this->userBackend = new \Test\Util\User\Dummy();
     \OC::$server->getUserManager()->registerBackend($this->userBackend);
     $this->ownerUid = $this->getUniqueID('owner_');
     $this->recipientUid = $this->getUniqueID('recipient_');
     $this->userBackend->createUser($this->ownerUid, '');
     $this->userBackend->createUser($this->recipientUid, '');
     $this->loginAsUser($this->ownerUid);
     Filesystem::mkdir('/foo');
     Filesystem::file_put_contents('/foo/bar.txt', 'asd');
     $fileId = Filesystem::getFileInfo('/foo/bar.txt')->getId();
     \OCP\Share::shareItem('file', $fileId, \OCP\Share::SHARE_TYPE_USER, $this->recipientUid, 31);
     $this->loginAsUser($this->recipientUid);
     $this->assertTrue(Filesystem::file_exists('bar.txt'));
 }
 /**
  * "user1" creates /test, /test/sub and shares with group1
  * "user2" (in group1) reshares /test with group2 and reshared /test/sub with group3
  * "user3" (in group 2)
  * "user4" (in group 3)
  */
 protected function setUpShares()
 {
     $this->fileIds[self::TEST_FILES_SHARING_API_USER1] = [];
     $this->fileIds[self::TEST_FILES_SHARING_API_USER2] = [];
     $this->fileIds[self::TEST_FILES_SHARING_API_USER3] = [];
     $this->fileIds[self::TEST_FILES_SHARING_API_USER4] = [];
     $this->rootView = new View('');
     $this->loginAsUser(self::TEST_FILES_SHARING_API_USER1);
     $view1 = new View('/' . self::TEST_FILES_SHARING_API_USER1 . '/files');
     $view1->mkdir('/test/sub');
     $folderInfo = $view1->getFileInfo('/test');
     \OCP\Share::shareItem('folder', $folderInfo->getId(), \OCP\Share::SHARE_TYPE_GROUP, 'group1', 31);
     $this->fileIds[self::TEST_FILES_SHARING_API_USER1][''] = $view1->getFileInfo('')->getId();
     $this->fileIds[self::TEST_FILES_SHARING_API_USER1]['test'] = $view1->getFileInfo('test')->getId();
     $this->fileIds[self::TEST_FILES_SHARING_API_USER1]['test/sub'] = $view1->getFileInfo('test/sub')->getId();
     $this->loginAsUser(self::TEST_FILES_SHARING_API_USER2);
     $view2 = new View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files');
     $folderInfo = $view2->getFileInfo('/test');
     $subFolderInfo = $view2->getFileInfo('/test/sub');
     \OCP\Share::shareItem('folder', $folderInfo->getId(), \OCP\Share::SHARE_TYPE_GROUP, 'group2', 31);
     \OCP\Share::shareItem('folder', $subFolderInfo->getId(), \OCP\Share::SHARE_TYPE_GROUP, 'group3', 31);
     $this->fileIds[self::TEST_FILES_SHARING_API_USER2][''] = $view2->getFileInfo('')->getId();
     $this->fileIds[self::TEST_FILES_SHARING_API_USER2]['test'] = $view2->getFileInfo('test')->getId();
     $this->fileIds[self::TEST_FILES_SHARING_API_USER2]['test/sub'] = $view2->getFileInfo('test/sub')->getId();
     $this->loginAsUser(self::TEST_FILES_SHARING_API_USER3);
     $view3 = new View('/' . self::TEST_FILES_SHARING_API_USER3 . '/files');
     $this->fileIds[self::TEST_FILES_SHARING_API_USER3][''] = $view3->getFileInfo('')->getId();
     $this->fileIds[self::TEST_FILES_SHARING_API_USER3]['test'] = $view3->getFileInfo('test')->getId();
     $this->fileIds[self::TEST_FILES_SHARING_API_USER3]['test/sub'] = $view3->getFileInfo('test/sub')->getId();
     $this->loginAsUser(self::TEST_FILES_SHARING_API_USER4);
     $view4 = new View('/' . self::TEST_FILES_SHARING_API_USER4 . '/files');
     $this->fileIds[self::TEST_FILES_SHARING_API_USER4][''] = $view4->getFileInfo('')->getId();
     $this->fileIds[self::TEST_FILES_SHARING_API_USER4]['sub'] = $view4->getFileInfo('sub')->getId();
     foreach ($this->fileIds as $user => $ids) {
         $this->loginAsUser($user);
         foreach ($ids as $id) {
             $path = $this->rootView->getPath($id);
             $this->fileEtags[$id] = $this->rootView->getFileInfo($path)->getEtag();
         }
     }
 }
 protected function setUp()
 {
     parent::setUp();
     $user = $this->getMockBuilder('\\OCP\\IUser')->disableOriginalConstructor()->getMock();
     $user->method('getUID')->willReturn(self::TEST_FILES_SHARING_API_USER1);
     $userSession = $this->getMockBuilder('\\OCP\\IUserSession')->disableOriginalConstructor()->getMock();
     $userSession->method('getUser')->willReturn(selF::TEST_FILES_SHARING_API_USER1);
     $this->propagationManager = $this->getMockBuilder('OCA\\Files_Sharing\\Propagation\\PropagationManager')->disableOriginalConstructor()->getMock();
     $this->groupManager = \OC::$server->getGroupManager();
     $this->groupPropagationManager = new GroupPropagationManager($userSession, $this->groupManager, $this->propagationManager);
     $this->groupPropagationManager->globalSetup();
     // since the sharing code is not mockable, we have to create a real folder
     $this->loginAsUser(self::TEST_FILES_SHARING_API_USER1);
     $view1 = new View('/' . self::TEST_FILES_SHARING_API_USER1 . '/files');
     $view1->mkdir('/folder');
     $this->fileInfo = $view1->getFileInfo('/folder');
     $this->recipientGroup = $this->groupManager->get(self::TEST_FILES_SHARING_API_GROUP1);
     $this->recipientUser = \OC::$server->getUserManager()->get(self::TEST_FILES_SHARING_API_USER3);
     Share::shareItem('folder', $this->fileInfo['fileid'], Share::SHARE_TYPE_GROUP, $this->recipientGroup->getGID(), \OCP\Constants::PERMISSION_READ);
     $this->loginAsUser($this->recipientUser->getUID());
 }
 public function shareLinks($data, $passwordInfo)
 {
     $tokens = array();
     for ($i = 0; $i < sizeof($data); $i++) {
         $itemType = $data[$i]['type'];
         $itemSource = $data[$i]['id'];
         $itemSourceName = $data[$i]['name'];
         $permissions = $data[$i]['permissions'];
         $shareType = \OCP\Share::SHARE_TYPE_LINK;
         $password = null;
         $passwordChanged = $passwordInfo['passwordChanged'] === 'true';
         if ($passwordInfo['password'] === '') {
             $passwordInfo = null;
         } else {
             $password = $passwordInfo['password'];
         }
         $token = \OCP\Share::shareItem($itemType, $itemSource, $shareType, $password, $permissions, $itemSourceName, !empty($_POST['expiration']) ? new \DateTime((string) $_POST['expiration']) : null, $passwordChanged);
         $tokens[$itemSourceName] = $token;
     }
     json_encode($tokens, JSON_PRETTY_PRINT);
     return new DataResponse($tokens);
 }
Exemple #10
0
 /**
  * @medium
  */
 function testpreUnlink()
 {
     $fileInfo2 = \OC\Files\Filesystem::getFileInfo($this->folder);
     $result = \OCP\Share::shareItem('folder', $fileInfo2->getId(), \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2, 31);
     $this->assertTrue($result);
     self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
     // one folder should be shared with the user
     $sharedFolders = \OCP\Share::getItemsSharedWith('folder');
     $this->assertSame(1, count($sharedFolders));
     // move shared folder to 'localDir'
     \OC\Files\Filesystem::mkdir('localDir');
     $result = \OC\Files\Filesystem::rename($this->folder, '/localDir/' . $this->folder);
     $this->assertTrue($result);
     \OC\Files\Filesystem::unlink('localDir');
     self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
     // after the parent directory was deleted the share should be unshared
     $sharedFolders = \OCP\Share::getItemsSharedWith('folder');
     $this->assertTrue(empty($sharedFolders));
     self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
     // the folder for the owner should still exists
     $this->assertTrue(\OC\Files\Filesystem::file_exists($this->folder));
 }
Exemple #11
0
 public function testGetPathByIdShareSubFolder()
 {
     self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
     \OC\Files\Filesystem::mkdir('foo');
     \OC\Files\Filesystem::mkdir('foo/bar');
     \OC\Files\Filesystem::touch('foo/bar/test.txt', 'bar');
     $folderInfo = \OC\Files\Filesystem::getFileInfo('foo');
     $fileInfo = \OC\Files\Filesystem::getFileInfo('foo/bar/test.txt');
     \OCP\Share::shareItem('folder', $folderInfo->getId(), \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2, \OCP\PERMISSION_ALL);
     \OC_Util::tearDownFS();
     self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
     $this->assertTrue(\OC\Files\Filesystem::file_exists('/foo'));
     list($sharedStorage) = \OC\Files\Filesystem::resolvePath('/' . self::TEST_FILES_SHARING_API_USER2 . '/files/foo');
     /**
      * @var \OC\Files\Storage\Shared $sharedStorage
      */
     $sharedCache = $sharedStorage->getCache();
     $this->assertEquals('', $sharedCache->getPathById($folderInfo->getId()));
     $this->assertEquals('bar/test.txt', $sharedCache->getPathById($fileInfo->getId()));
 }
Exemple #12
0
 public function testShareWithOwnerError()
 {
     \OC_User::setUserId($this->user1);
     $view = new \OC\Files\View('/' . $this->user1 . '/');
     $view->mkdir('files/folder1');
     $fileInfo = $view->getFileInfo('files/folder1');
     $this->assertInstanceOf('\\OC\\Files\\FileInfo', $fileInfo);
     $fileId = $fileInfo->getId();
     $this->assertTrue(\OCP\Share::shareItem('folder', $fileId, \OCP\Share::SHARE_TYPE_USER, $this->user2, \OCP\Constants::PERMISSION_ALL), 'Failed asserting that user 1 successfully shared "test" with user 2.');
     \OC_User::setUserId($this->user2);
     try {
         \OCP\Share::shareItem('folder', $fileId, \OCP\Share::SHARE_TYPE_USER, $this->user1, \OCP\Constants::PERMISSION_ALL);
         $this->fail();
     } catch (\Exception $e) {
         $this->assertEquals('Sharing failed, because the user ' . $this->user1 . ' is the original sharer', $e->getMessage());
     }
 }
Exemple #13
0
 /**
  * update password for public link share
  * @param array $share information about the share
  * @param array $params 'password'
  * @return \OC_OCS_Result
  */
 private static function updatePassword($share, $params)
 {
     $itemSource = $share['item_source'];
     $itemType = $share['item_type'];
     if ((int) $share['share_type'] !== \OCP\Share::SHARE_TYPE_LINK) {
         return new \OC_OCS_Result(null, 400, "password protection is only supported for public shares");
     }
     $shareWith = isset($params['_put']['password']) ? $params['_put']['password'] : null;
     if ($shareWith === '') {
         $shareWith = null;
     }
     $items = \OCP\Share::getItemShared($itemType, $itemSource);
     $checkExists = false;
     foreach ($items as $item) {
         if ($item['share_type'] === \OCP\Share::SHARE_TYPE_LINK) {
             $checkExists = true;
             $permissions = $item['permissions'];
         }
     }
     if (!$checkExists) {
         return new \OC_OCS_Result(null, 404, "share doesn't exists, can't change password");
     }
     try {
         $result = \OCP\Share::shareItem($itemType, $itemSource, \OCP\Share::SHARE_TYPE_LINK, $shareWith, $permissions);
     } catch (\Exception $e) {
         return new \OC_OCS_Result(null, 403, $e->getMessage());
     }
     if ($result) {
         return new \OC_OCS_Result();
     }
     return new \OC_OCS_Result(null, 404, "couldn't set password");
 }
Exemple #14
0
 /**
  * test expiration of files older then the max storage time defined for the trash
  * in this test we delete a shared file and check if both trash bins, the one from
  * the owner of the file and the one from the user who deleted the file get expired
  * correctly
  */
 public function testExpireOldFilesShared()
 {
     $currentTime = time();
     $folder = "trashTest-" . $currentTime . '/';
     $expiredDate = $currentTime - 3 * 24 * 60 * 60;
     // create some files
     \OC\Files\Filesystem::mkdir($folder);
     \OC\Files\Filesystem::file_put_contents($folder . 'user1-1.txt', 'file1');
     \OC\Files\Filesystem::file_put_contents($folder . 'user1-2.txt', 'file2');
     \OC\Files\Filesystem::file_put_contents($folder . 'user1-3.txt', 'file3');
     \OC\Files\Filesystem::file_put_contents($folder . 'user1-4.txt', 'file4');
     //share user1-4.txt with user2
     $fileInfo = \OC\Files\Filesystem::getFileInfo($folder);
     $result = \OCP\Share::shareItem('folder', $fileInfo->getId(), \OCP\Share::SHARE_TYPE_USER, self::TEST_TRASHBIN_USER2, 31);
     $this->assertTrue($result);
     // delete them so that they end up in the trash bin
     \OC\Files\Filesystem::unlink($folder . 'user1-1.txt');
     \OC\Files\Filesystem::unlink($folder . 'user1-2.txt');
     \OC\Files\Filesystem::unlink($folder . 'user1-3.txt');
     $filesInTrash = OCA\Files_Trashbin\Helper::getTrashFiles('/', self::TEST_TRASHBIN_USER1, 'name');
     $this->assertSame(3, count($filesInTrash));
     // every second file will get a date in the past so that it will get expired
     $this->manipulateDeleteTime($filesInTrash, $this->trashRoot1, $expiredDate);
     // login as user2
     self::loginHelper(self::TEST_TRASHBIN_USER2);
     $this->assertTrue(\OC\Files\Filesystem::file_exists($folder . "user1-4.txt"));
     // create some files
     \OC\Files\Filesystem::file_put_contents('user2-1.txt', 'file1');
     \OC\Files\Filesystem::file_put_contents('user2-2.txt', 'file2');
     // delete them so that they end up in the trash bin
     \OC\Files\Filesystem::unlink('user2-1.txt');
     \OC\Files\Filesystem::unlink('user2-2.txt');
     $filesInTrashUser2 = OCA\Files_Trashbin\Helper::getTrashFiles('/', self::TEST_TRASHBIN_USER2, 'name');
     $this->assertSame(2, count($filesInTrashUser2));
     // every second file will get a date in the past so that it will get expired
     $this->manipulateDeleteTime($filesInTrashUser2, $this->trashRoot2, $expiredDate);
     \OC\Files\Filesystem::unlink($folder . 'user1-4.txt');
     $this->runCommands();
     $filesInTrashUser2AfterDelete = OCA\Files_Trashbin\Helper::getTrashFiles('/', self::TEST_TRASHBIN_USER2);
     // user2-1.txt should have been expired
     $this->verifyArray($filesInTrashUser2AfterDelete, array('user2-2.txt', 'user1-4.txt'));
     self::loginHelper(self::TEST_TRASHBIN_USER1);
     // user1-1.txt and user1-3.txt should have been expired
     $filesInTrashUser1AfterDelete = OCA\Files_Trashbin\Helper::getTrashFiles('/', self::TEST_TRASHBIN_USER1);
     $this->verifyArray($filesInTrashUser1AfterDelete, array('user1-2.txt', 'user1-4.txt'));
 }
Exemple #15
0
 /**
  * Test whether versions are created when overwriting as share recipient
  */
 public function testStoreVersionAsRecipient()
 {
     $this->loginAsUser(self::TEST_VERSIONS_USER);
     \OC\Files\Filesystem::mkdir('folder');
     \OC\Files\Filesystem::file_put_contents('folder/test.txt', 'test file');
     $fileInfo = \OC\Files\Filesystem::getFileInfo('folder');
     \OCP\Share::shareItem('folder', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER, self::TEST_VERSIONS_USER2, \OCP\Constants::PERMISSION_ALL);
     $this->loginAsUser(self::TEST_VERSIONS_USER2);
     $this->createAndCheckVersions(\OC\Files\Filesystem::getView(), 'folder/test.txt');
 }
Exemple #16
0
 /**
  * create a new share
  * @param array $params
  * @return \OC_OCS_Result
  */
 public static function createShare($params)
 {
     $path = isset($_POST['path']) ? $_POST['path'] : null;
     if ($path === null) {
         return new \OC_OCS_Result(null, 400, "please specify a file or folder path");
     }
     $itemSource = self::getFileId($path);
     $itemSourceName = $itemSource;
     $itemType = self::getItemType($path);
     if ($itemSource === null) {
         return new \OC_OCS_Result(null, 404, "wrong path, file/folder doesn't exist.");
     }
     $shareWith = isset($_POST['shareWith']) ? $_POST['shareWith'] : null;
     $shareType = isset($_POST['shareType']) ? (int) $_POST['shareType'] : null;
     switch ($shareType) {
         case \OCP\Share::SHARE_TYPE_REMOTE:
             $shareWith = rtrim($shareWith, '/');
             $itemSourceName = basename($path);
         case \OCP\Share::SHARE_TYPE_USER:
         case \OCP\Share::SHARE_TYPE_GROUP:
             $permissions = isset($_POST['permissions']) ? (int) $_POST['permissions'] : 31;
             break;
         case \OCP\Share::SHARE_TYPE_LINK:
             //allow password protection
             $shareWith = isset($_POST['password']) ? $_POST['password'] : null;
             //check public link share
             $publicUploadEnabled = \OC::$server->getAppConfig()->getValue('core', 'shareapi_allow_public_upload', 'yes');
             if (isset($_POST['publicUpload']) && $publicUploadEnabled !== 'yes') {
                 return new \OC_OCS_Result(null, 403, "public upload disabled by the administrator");
             }
             $publicUpload = isset($_POST['publicUpload']) ? $_POST['publicUpload'] : 'false';
             // read, create, update (7) if public upload is enabled or
             // read (1) if public upload is disabled
             $permissions = $publicUpload === 'true' ? 7 : 1;
             break;
         default:
             return new \OC_OCS_Result(null, 400, "unknown share type");
     }
     if (($permissions & \OCP\Constants::PERMISSION_READ) === 0) {
         return new \OC_OCS_Result(null, 400, 'invalid permissions');
     }
     try {
         $token = \OCP\Share::shareItem($itemType, $itemSource, $shareType, $shareWith, $permissions, $itemSourceName);
     } catch (HintException $e) {
         return new \OC_OCS_Result(null, 400, $e->getHint());
     } catch (\Exception $e) {
         return new \OC_OCS_Result(null, 403, $e->getMessage());
     }
     if ($token) {
         $data = array();
         $data['id'] = 'unknown';
         $shares = \OCP\Share::getItemShared($itemType, $itemSource);
         if (is_string($token)) {
             //public link share
             foreach ($shares as $share) {
                 if ($share['token'] === $token) {
                     $data['id'] = $share['id'];
                     break;
                 }
             }
             $data['url'] = \OC::$server->getURLGenerator()->linkToRouteAbsolute('files_sharing.sharecontroller.showShare', ['token' => $token]);
             $data['token'] = $token;
         } else {
             foreach ($shares as $share) {
                 if ($share['share_with'] === $shareWith && $share['share_type'] === $shareType) {
                     $data['id'] = $share['id'];
                     break;
                 }
             }
         }
         return new \OC_OCS_Result($data);
     } else {
         return new \OC_OCS_Result(null, 404, "couldn't share file");
     }
 }
Exemple #17
0
 /**
  * Test that moving a mount point into a shared folder is forbidden
  */
 public function testMoveMountPointIntoSharedFolder()
 {
     $this->loginAsUser($this->user);
     list($mount1) = $this->createTestMovableMountPoints([$this->user . '/files/mount1']);
     $mount1->expects($this->never())->method('moveMount');
     $view = new \OC\Files\View('/' . $this->user . '/files/');
     $view->mkdir('shareddir');
     $view->mkdir('shareddir/sub');
     $view->mkdir('shareddir/sub2');
     $fileId = $view->getFileInfo('shareddir')->getId();
     $userObject = \OC::$server->getUserManager()->createUser('test2', 'IHateNonMockableStaticClasses');
     $this->assertTrue(\OCP\Share::shareItem('folder', $fileId, \OCP\Share::SHARE_TYPE_USER, 'test2', \OCP\Constants::PERMISSION_READ));
     $this->assertFalse($view->rename('mount1', 'shareddir'), 'Cannot overwrite shared folder');
     $this->assertFalse($view->rename('mount1', 'shareddir/sub'), 'Cannot move mount point into shared folder');
     $this->assertFalse($view->rename('mount1', 'shareddir/sub/sub2'), 'Cannot move mount point into shared subfolder');
     $this->assertTrue(\OCP\Share::unshare('folder', $fileId, \OCP\Share::SHARE_TYPE_USER, 'test2'));
     $userObject->delete();
 }
Exemple #18
0
 /**
  * @brief test moving a shared file out of the Shared folder
  */
 function testRename()
 {
     // login as admin
     \Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1);
     // save file with content
     $cryptedFile = file_put_contents('crypt:///' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files/' . $this->filename, $this->dataShort);
     // test that data was successfully written
     $this->assertTrue(is_int($cryptedFile));
     // get the file info from previous created file
     $fileInfo = $this->view->getFileInfo('/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files/' . $this->filename);
     // check if we have a valid file info
     $this->assertTrue(is_array($fileInfo));
     // share the file
     \OCP\Share::shareItem('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER, \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2, OCP\PERMISSION_ALL);
     // check if share key for user2exists
     $this->assertTrue($this->view->file_exists('/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/share-keys/' . $this->filename . '.' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '.shareKey'));
     // login as user2
     \Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2);
     $this->assertTrue($this->view->file_exists('/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '/files/Shared/' . $this->filename));
     // get file contents
     $retrievedCryptedFile = $this->view->file_get_contents('/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '/files/Shared/' . $this->filename);
     // check if data is the same as we previously written
     $this->assertEquals($this->dataShort, $retrievedCryptedFile);
     // move the file out of the shared folder
     $this->view->rename('/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '/files/Shared/' . $this->filename, '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '/files/' . $this->filename);
     // check if we can read the moved file
     $retrievedRenamedFile = $this->view->file_get_contents('/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '/files/' . $this->filename);
     // check if data is the same as we previously written
     $this->assertEquals($this->dataShort, $retrievedRenamedFile);
     // the owners file should be deleted
     $this->assertFalse($this->view->file_exists('/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files/' . $this->filename));
     // cleanup
     $this->view->unlink('/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '/files/' . $this->filename);
 }
Exemple #19
0
 /**
  * Test that deleted versions properly land in the trashbin when deleting as share recipient.
  */
 public function testDeleteVersionsOfFolderAsRecipient()
 {
     \OCA\Files_Versions\Hooks::connectHooks();
     $this->userView->mkdir('share');
     $this->userView->mkdir('share/folder');
     // trigger a version (multiple would not work because of the expire logic)
     $this->userView->file_put_contents('share/folder/test.txt', 'v1');
     $this->userView->file_put_contents('share/folder/test.txt', 'v2');
     $results = $this->rootView->getDirectoryContent($this->user . '/files_versions/share/folder/');
     $this->assertEquals(1, count($results));
     $recipientUser = $this->getUniqueId('recipient_');
     \OC::$server->getUserManager()->createUser($recipientUser, $recipientUser);
     $fileinfo = $this->userView->getFileInfo('share');
     $this->assertTrue(\OCP\Share::shareItem('folder', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_USER, $recipientUser, 31));
     $this->loginAsUser($recipientUser);
     // delete as recipient
     $recipientView = new \OC\Files\View('/' . $recipientUser . '/files');
     $recipientView->rmdir('share/folder');
     // rescan trash storage
     list($rootStorage, ) = $this->rootView->resolvePath($this->user . '/files_trashbin');
     $rootStorage->getScanner()->scan('');
     // check if versions are in trashbin for owner
     $results = $this->rootView->getDirectoryContent($this->user . '/files_trashbin/versions');
     $this->assertEquals(1, count($results));
     $name = $results[0]->getName();
     $this->assertEquals('folder.d', substr($name, 0, strlen('folder.d')));
     // check if file versions are in trashbin for owner
     $results = $this->rootView->getDirectoryContent($this->user . '/files_trashbin/versions/' . $name . '/');
     $this->assertEquals(1, count($results));
     $name = $results[0]->getName();
     $this->assertEquals('test.txt.v', substr($name, 0, strlen('test.txt.v')));
     // check if versions are in trashbin for recipient
     $results = $this->rootView->getDirectoryContent($recipientUser . '/files_trashbin/versions');
     $this->assertEquals(1, count($results));
     $name = $results[0]->getName();
     $this->assertEquals('folder.d', substr($name, 0, strlen('folder.d')));
     // check if file versions are in trashbin for recipient
     $results = $this->rootView->getDirectoryContent($recipientUser . '/files_trashbin/versions/' . $name . '/');
     $this->assertEquals(1, count($results));
     $name = $results[0]->getName();
     $this->assertEquals('test.txt.v', substr($name, 0, strlen('test.txt.v')));
     // versions deleted
     $results = $this->rootView->getDirectoryContent($recipientUser . '/files_versions/share/folder/');
     $this->assertEquals(0, count($results));
 }
Exemple #20
0
 function testDeleteHooksForSharedFiles()
 {
     self::logoutHelper();
     self::loginHelper(self::TEST_ENCRYPTION_HOOKS_USER1);
     \OC_User::setUserId(self::TEST_ENCRYPTION_HOOKS_USER1);
     // remember files_trashbin state
     $stateFilesTrashbin = \OC_App::isEnabled('files_trashbin');
     // we want to tests with app files_trashbin disabled
     \OC_App::disable('files_trashbin');
     // make sure that the trash bin is disabled
     $this->assertFalse(\OC_APP::isEnabled('files_trashbin'));
     $this->user1View->file_put_contents($this->filename, $this->data);
     // check if all keys are generated
     $this->assertTrue($this->rootView->file_exists(self::TEST_ENCRYPTION_HOOKS_USER1 . '/files_encryption/keys/' . $this->filename . '/' . self::TEST_ENCRYPTION_HOOKS_USER1 . '.shareKey'));
     $this->assertTrue($this->rootView->file_exists(self::TEST_ENCRYPTION_HOOKS_USER1 . '/files_encryption/keys/' . $this->filename . '/fileKey'));
     // get the file info from previous created file
     $fileInfo = $this->user1View->getFileInfo($this->filename);
     // check if we have a valid file info
     $this->assertTrue($fileInfo instanceof \OC\Files\FileInfo);
     // share the file with user2
     \OCP\Share::shareItem('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER, self::TEST_ENCRYPTION_HOOKS_USER2, \OCP\Constants::PERMISSION_ALL);
     // check if new share key exists
     $this->assertTrue($this->rootView->file_exists(self::TEST_ENCRYPTION_HOOKS_USER1 . '/files_encryption/keys/' . $this->filename . '/' . self::TEST_ENCRYPTION_HOOKS_USER2 . '.shareKey'));
     self::logoutHelper();
     self::loginHelper(self::TEST_ENCRYPTION_HOOKS_USER2);
     \OC_User::setUserId(self::TEST_ENCRYPTION_HOOKS_USER2);
     // user2 update the shared file
     $this->user2View->file_put_contents($this->filename, $this->data);
     // keys should be stored at user1s dir, not in user2s
     $this->assertFalse($this->rootView->file_exists(self::TEST_ENCRYPTION_HOOKS_USER2 . '/files_encryption/keys/' . $this->filename . '/' . self::TEST_ENCRYPTION_HOOKS_USER2 . '.shareKey'));
     $this->assertFalse($this->rootView->file_exists(self::TEST_ENCRYPTION_HOOKS_USER2 . '/files_encryption/keys/' . $this->filename . '/fileKey'));
     // delete the Shared file from user1 in data/user2/files/Shared
     $result = $this->user2View->unlink($this->filename);
     $this->assertTrue($result);
     // share key for user2 from user1s home should be gone, all other keys should still exists
     $this->assertTrue($this->rootView->file_exists(self::TEST_ENCRYPTION_HOOKS_USER1 . '/files_encryption/keys/' . $this->filename . '/' . self::TEST_ENCRYPTION_HOOKS_USER1 . '.shareKey'));
     $this->assertFalse($this->rootView->file_exists(self::TEST_ENCRYPTION_HOOKS_USER1 . '/files_encryption/keys/' . $this->filename . '/' . self::TEST_ENCRYPTION_HOOKS_USER2 . '.shareKey'));
     $this->assertTrue($this->rootView->file_exists(self::TEST_ENCRYPTION_HOOKS_USER1 . '/files_encryption/keys/' . $this->filename . '/fileKey'));
     // cleanup
     self::logoutHelper();
     self::loginHelper(self::TEST_ENCRYPTION_HOOKS_USER1);
     \OC_User::setUserId(self::TEST_ENCRYPTION_HOOKS_USER1);
     if ($stateFilesTrashbin) {
         \OC_App::enable('files_trashbin');
     } else {
         \OC_App::disable('files_trashbin');
     }
 }
Exemple #21
0
 public function testNameConflict()
 {
     self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
     $view1 = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER1 . '/files');
     $view1->mkdir('foo');
     $folderInfo1 = $view1->getFileInfo('foo');
     self::loginHelper(self::TEST_FILES_SHARING_API_USER3);
     $view3 = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER3 . '/files');
     $view3->mkdir('foo');
     $folderInfo2 = $view3->getFileInfo('foo');
     // share a folder with the same name from two different users to the same user
     self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
     \OCP\Share::shareItem('folder', $folderInfo1['fileid'], \OCP\Share::SHARE_TYPE_GROUP, self::TEST_FILES_SHARING_API_GROUP1, 31);
     self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
     self::loginHelper(self::TEST_FILES_SHARING_API_USER3);
     \OCP\Share::shareItem('folder', $folderInfo2['fileid'], \OCP\Share::SHARE_TYPE_GROUP, self::TEST_FILES_SHARING_API_GROUP1, 31);
     self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
     $view2 = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files');
     $this->assertTrue($view2->file_exists('/foo'));
     $this->assertTrue($view2->file_exists('/foo (2)'));
     $mount = $view2->getMount('/foo');
     $this->assertInstanceOf('\\OCA\\Files_Sharing\\SharedMount', $mount);
     /** @var \OC\Files\Storage\Shared $storage */
     $storage = $mount->getStorage();
     $source = $storage->getFile('');
     $this->assertEquals(self::TEST_FILES_SHARING_API_USER1, $source['uid_owner']);
 }
Exemple #22
0
 /**
  * if a folder gets renamed all children mount points should be renamed too
  */
 function testRename()
 {
     $fileinfo = \OC\Files\Filesystem::getFileInfo($this->folder);
     $result = \OCP\Share::shareItem('folder', $fileinfo->getId(), \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2, 31);
     $this->assertTrue($result);
     $this->loginHelper(self::TEST_FILES_SHARING_API_USER2);
     // make sure that the shared folder exists
     $this->assertTrue(\OC\Files\Filesystem::file_exists($this->folder));
     \OC\Files\Filesystem::mkdir('oldTarget');
     \OC\Files\Filesystem::mkdir('oldTarget/subfolder');
     \OC\Files\Filesystem::mkdir('newTarget');
     \OC\Files\Filesystem::rename($this->folder, 'oldTarget/subfolder/' . $this->folder);
     // re-login to make sure that the new mount points are initialized
     $this->loginHelper(self::TEST_FILES_SHARING_API_USER2);
     \OC\Files\Filesystem::rename('/oldTarget', '/newTarget/oldTarget');
     // re-login to make sure that the new mount points are initialized
     $this->loginHelper(self::TEST_FILES_SHARING_API_USER2);
     $this->assertTrue(\OC\Files\Filesystem::file_exists('/newTarget/oldTarget/subfolder/' . $this->folder));
     // cleanup
     $this->loginHelper(self::TEST_FILES_SHARING_API_USER1);
     $result = \OCP\Share::unshare('folder', $fileinfo->getId(), \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2);
     $this->assertTrue($result);
 }
Exemple #23
0
 /**
  * Make sure that a user cannot have multiple identical shares to remote users
  */
 public function testOnlyOneRemoteShare()
 {
     $oldHttpHelper = \OC::$server->query('HTTPHelper');
     $httpHelperMock = $this->getMockBuilder('OC\\HttpHelper')->disableOriginalConstructor()->getMock();
     $this->setHttpHelper($httpHelperMock);
     $httpHelperMock->expects($this->at(0))->method('post')->with($this->stringStartsWith('https://localhost/ocs/v1.php/cloud/shares'), $this->anything())->willReturn(['success' => true, 'result' => json_encode(['ocs' => ['meta' => ['statuscode' => 100]]])]);
     \OCP\Share::shareItem('test', 'test.txt', \OCP\Share::SHARE_TYPE_REMOTE, 'foo@localhost', \OCP\Constants::PERMISSION_READ);
     $shares = \OCP\Share::getItemShared('test', 'test.txt');
     $share = array_shift($shares);
     //Try share again
     try {
         \OCP\Share::shareItem('test', 'test.txt', \OCP\Share::SHARE_TYPE_REMOTE, 'foo@localhost', \OCP\Constants::PERMISSION_READ);
         $this->fail('Identical remote shares are not allowed');
     } catch (\Exception $e) {
         $this->assertEquals('Sharing test.txt failed, because this item is already shared with foo@localhost', $e->getMessage());
     }
     $httpHelperMock->expects($this->at(0))->method('post')->with($this->stringStartsWith('https://localhost/ocs/v1.php/cloud/shares/' . $share['id'] . '/unshare'), $this->anything())->willReturn(['success' => true, 'result' => json_encode(['ocs' => ['meta' => ['statuscode' => 100]]])]);
     \OCP\Share::unshare('test', 'test.txt', \OCP\Share::SHARE_TYPE_REMOTE, 'foo@localhost');
     $this->setHttpHelper($oldHttpHelper);
 }
Exemple #24
0
 function testFailShareFile()
 {
     // login as admin
     \Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1);
     // save file with content
     $cryptedFile = file_put_contents('crypt://' . $this->filename, $this->dataShort);
     // test that data was successfully written
     $this->assertTrue(is_int($cryptedFile));
     // disable encryption proxy to prevent recursive calls
     $proxyStatus = \OC_FileProxy::$enabled;
     \OC_FileProxy::$enabled = false;
     // get the file info from previous created file
     $fileInfo = $this->view->getFileInfo('/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files/' . $this->filename);
     // check if we have a valid file info
     $this->assertTrue(is_array($fileInfo));
     // check if the unencrypted file size is stored
     $this->assertGreaterThan(0, $fileInfo['unencrypted_size']);
     // break users public key
     $this->view->rename('/public-keys/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3 . '.public.key', '/public-keys/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3 . '.public.key_backup');
     // re-enable the file proxy
     \OC_FileProxy::$enabled = $proxyStatus;
     // share the file
     \OCP\Share::shareItem('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_GROUP, \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_GROUP1, OCP\PERMISSION_ALL);
     // login as admin
     \Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1);
     // check if share key for user1 not exists
     $this->assertFalse($this->view->file_exists('/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/share-keys/' . $this->filename . '.' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3 . '.shareKey'));
     // disable encryption proxy to prevent recursive calls
     $proxyStatus = \OC_FileProxy::$enabled;
     \OC_FileProxy::$enabled = false;
     // break user1 public key
     $this->view->rename('/public-keys/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3 . '.public.key_backup', '/public-keys/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3 . '.public.key');
     // remove share file
     $this->view->unlink('/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/share-keys/' . $this->filename . '.' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3 . '.shareKey');
     // re-enable the file proxy
     \OC_FileProxy::$enabled = $proxyStatus;
     // unshare the file with user1
     \OCP\Share::unshare('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_GROUP, \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_GROUP1);
     // check if share key not exists
     $this->assertFalse($this->view->file_exists('/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/share-keys/' . $this->filename . '.' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3 . '.shareKey'));
     // cleanup
     $this->view->unlink('/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files/' . $this->filename);
 }
Exemple #25
0
 function testGetPermissions()
 {
     $fileinfoFolder = $this->view->getFileInfo($this->folder);
     $result = \OCP\Share::shareItem('folder', $fileinfoFolder['fileid'], \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2, 1);
     $this->assertTrue($result);
     self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
     $this->assertTrue(\OC\Files\Filesystem::is_dir($this->folder));
     // for the share root we expect:
     // the shared permissions (1)
     // the delete permission (8), to enable unshare
     // the update permission (2), to allow renaming of the mount point
     $rootInfo = \OC\Files\Filesystem::getFileInfo($this->folder);
     $this->assertSame(11, $rootInfo->getPermissions());
     // for the file within the shared folder we expect:
     // the shared permissions (1)
     $subfileInfo = \OC\Files\Filesystem::getFileInfo($this->folder . $this->filename);
     $this->assertSame(1, $subfileInfo->getPermissions());
     //cleanup
     self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
     $result = \OCP\Share::unshare('folder', $fileinfoFolder['fileid'], \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2);
     $this->assertTrue($result);
 }
Exemple #26
0
 /**
  * share file with a group if a user renames the file the filename should not change
  * for the other users
  */
 function testMoveGroupShare()
 {
     \OC_Group::createGroup('testGroup');
     \OC_Group::addToGroup(self::TEST_FILES_SHARING_API_USER1, 'testGroup');
     \OC_Group::addToGroup(self::TEST_FILES_SHARING_API_USER2, 'testGroup');
     \OC_Group::addToGroup(self::TEST_FILES_SHARING_API_USER3, 'testGroup');
     $fileinfo = $this->view->getFileInfo($this->filename);
     $result = \OCP\Share::shareItem('file', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_GROUP, "testGroup", 31);
     self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
     $this->assertTrue(\OC\Files\Filesystem::file_exists($this->filename));
     \OC\Files\Filesystem::rename($this->filename, "newFileName");
     $this->assertTrue(\OC\Files\Filesystem::file_exists('newFileName'));
     $this->assertFalse(\OC\Files\Filesystem::file_exists($this->filename));
     self::loginHelper(self::TEST_FILES_SHARING_API_USER3);
     $this->assertTrue(\OC\Files\Filesystem::file_exists($this->filename));
     $this->assertFalse(\OC\Files\Filesystem::file_exists("newFileName"));
     self::loginHelper(self::TEST_FILES_SHARING_API_USER3);
     $this->assertTrue(\OC\Files\Filesystem::file_exists($this->filename));
     $this->assertFalse(\OC\Files\Filesystem::file_exists("newFileName"));
     //cleanup
     \OCP\Share::unshare('file', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_GROUP, 'testGroup');
     \OC_Group::removeFromGroup(self::TEST_FILES_SHARING_API_USER1, 'testGroup');
     \OC_Group::removeFromGroup(self::TEST_FILES_SHARING_API_USER2, 'testGroup');
     \OC_Group::removeFromGroup(self::TEST_FILES_SHARING_API_USER3, 'testGroup');
 }
Exemple #27
0
 public function testDefaultExpireDate()
 {
     \Test_Files_Sharing_Api::loginHelper(\Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER1);
     // TODO drop this once all code paths use the DI version - otherwise
     // the cache inside this config object is out of date because
     // OC_Appconfig is used and bypasses this cache which lead to integrity
     // constraint violations
     $config = \OC::$server->getConfig();
     $config->deleteAppValue('core', 'shareapi_default_expire_date');
     $config->deleteAppValue('core', 'shareapi_enforce_expire_date');
     $config->deleteAppValue('core', 'shareapi_expire_after_n_days');
     $config->setAppValue('core', 'shareapi_default_expire_date', 'yes');
     $config->setAppValue('core', 'shareapi_enforce_expire_date', 'yes');
     $config->setAppValue('core', 'shareapi_expire_after_n_days', '2');
     // default expire date is set to 2 days
     // the time when the share was created is set to 3 days in the past
     // user defined expire date is set to +2 days from now on
     // -> link should be already expired by the default expire date but the user
     //    share should still exists.
     $now = time();
     $dateFormat = 'Y-m-d H:i:s';
     $shareCreated = $now - 3 * 24 * 60 * 60;
     $expireDate = date($dateFormat, $now + 2 * 24 * 60 * 60);
     $info = OC\Files\Filesystem::getFileInfo($this->filename);
     $this->assertTrue($info instanceof \OC\Files\FileInfo);
     $result = \OCP\Share::shareItem('file', $info->getId(), \OCP\Share::SHARE_TYPE_LINK, null, \OCP\Constants::PERMISSION_READ);
     $this->assertTrue(is_string($result));
     $result = \OCP\Share::shareItem('file', $info->getId(), \OCP\Share::SHARE_TYPE_USER, \Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER2, 31);
     $this->assertTrue($result);
     $result = \OCP\Share::setExpirationDate('file', $info->getId(), $expireDate, $now);
     $this->assertTrue($result);
     //manipulate stime so that both shares are older then the default expire date
     $statement = "UPDATE `*PREFIX*share` SET `stime` = ? WHERE `share_type` = ?";
     $query = \OCP\DB::prepare($statement);
     $result = $query->execute(array($shareCreated, \OCP\Share::SHARE_TYPE_LINK));
     $this->assertSame(1, $result);
     $query = \OCP\DB::prepare($statement);
     $result = $query->execute(array($shareCreated, \OCP\Share::SHARE_TYPE_USER));
     $this->assertSame(1, $result);
     // now the link share should expire because of enforced default expire date
     // the user share should still exist
     $result = \OCP\Share::getItemShared('file', $info->getId());
     $this->assertTrue(is_array($result));
     $this->assertSame(1, count($result));
     $share = reset($result);
     $this->assertSame(\OCP\Share::SHARE_TYPE_USER, $share['share_type']);
     //cleanup
     $result = \OCP\Share::unshare('file', $info->getId(), \OCP\Share::SHARE_TYPE_USER, \Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER2);
     $this->assertTrue($result);
     $config->setAppValue('core', 'shareapi_default_expire_date', 'no');
     $config->setAppValue('core', 'shareapi_enforce_expire_date', 'no');
 }
 function testRenameSharedFile()
 {
     \OC\Files\Filesystem::file_put_contents("test.txt", "test file");
     $fileInfo = \OC\Files\Filesystem::getFileInfo('test.txt');
     $t1 = time();
     // second version is two weeks older, this way we make sure that no
     // version will be expired
     $t2 = $t1 - 60 * 60 * 24 * 14;
     $this->rootView->mkdir(self::USERS_VERSIONS_ROOT);
     // create some versions
     $v1 = self::USERS_VERSIONS_ROOT . '/test.txt.v' . $t1;
     $v2 = self::USERS_VERSIONS_ROOT . '/test.txt.v' . $t2;
     // the renamed versions should not exist! Because we only moved the mount point!
     $v1Renamed = self::USERS_VERSIONS_ROOT . '/test2.txt.v' . $t1;
     $v2Renamed = self::USERS_VERSIONS_ROOT . '/test2.txt.v' . $t2;
     $this->rootView->file_put_contents($v1, 'version1');
     $this->rootView->file_put_contents($v2, 'version2');
     \OCP\Share::shareItem('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER, self::TEST_VERSIONS_USER2, OCP\PERMISSION_ALL);
     self::loginHelper(self::TEST_VERSIONS_USER2);
     $this->assertTrue(\OC\Files\Filesystem::file_exists('test.txt'));
     // execute rename hook of versions app
     \OC\Files\Filesystem::rename('test.txt', 'test2.txt');
     self::loginHelper(self::TEST_VERSIONS_USER);
     $this->assertTrue($this->rootView->file_exists($v1));
     $this->assertTrue($this->rootView->file_exists($v2));
     $this->assertFalse($this->rootView->file_exists($v1Renamed));
     $this->assertFalse($this->rootView->file_exists($v2Renamed));
     //cleanup
     \OC\Files\Filesystem::unlink('/test.txt');
 }
 public function testDoNotExpireOtherShares()
 {
     $this->loginAsUser($this->user1);
     $view = new \OC\Files\View('/' . $this->user1 . '/');
     $view->mkdir('files/test');
     $fileInfo = $view->getFileInfo('files/test');
     $this->assertNotNull(\OCP\Share::shareItem('folder', $fileInfo->getId(), \OCP\Share::SHARE_TYPE_USER, $this->user2, \OCP\Constants::PERMISSION_READ), 'Failed asserting that user 1 successfully shared "test" by link with user2.');
     $shares = $this->getShares();
     $this->assertCount(1, $shares);
     reset($shares);
     $share = current($shares);
     $this->logout();
     $this->job->run([]);
     $shares = $this->getShares();
     $this->assertCount(1, $shares);
 }
Exemple #30
0
 /**
  * @dataProvider dataProviderGetUsersSharingFile
  *
  * @param string $groupName name of group to share with
  * @param bool $includeOwner whether to include the owner in the result
  * @param bool $includePaths whether to include paths in the result
  * @param array $expectedResult expected result of the API call
  */
 public function testGetUsersSharingFile($groupName, $includeOwner, $includePaths, $expectedResult)
 {
     $fileinfo = $this->view->getFileInfo($this->folder);
     $result = \OCP\Share::shareItem('folder', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_GROUP, $groupName, \OCP\Constants::PERMISSION_READ);
     $this->assertTrue($result);
     // public share
     $result = \OCP\Share::shareItem('folder', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_LINK, null, \OCP\Constants::PERMISSION_READ);
     $this->assertNotNull($result);
     // returns the token!
     // owner renames after sharing
     $this->view->rename($this->folder, $this->folder . '_owner_renamed');
     self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
     $user2View = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files');
     $user2View->rename($this->folder, $this->folder . '_renamed');
     $ownerPath = $this->folder . '_owner_renamed';
     $owner = self::TEST_FILES_SHARING_API_USER1;
     $result = \OCP\Share::getUsersSharingFile($ownerPath, $owner, $includeOwner, $includePaths);
     // sort users to make sure it matches
     if ($includePaths) {
         ksort($result);
     } else {
         sort($result['users']);
     }
     $this->assertEquals($expectedResult, $result);
 }