Esempio n. 1
0
 /**
  * @param $fileId the fileId of the file
  * @param $shareWIth the ownCloud user to share the file with
  */
 private function unShare($fileId, $shareWIth)
 {
     try {
         \OCP\Share::unshare('file', $fileId, \OCP\Share::SHARE_TYPE_USER, $shareWIth);
     } catch (\Exception $e) {
     }
 }
Esempio n. 2
0
 function tearDown()
 {
     $this->sharedCache->clear();
     self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
     $fileinfo = $this->view->getFileInfo('container/shareddir');
     \OCP\Share::unshare('folder', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2);
     $this->view->deleteAll('container');
     $this->ownerCache->clear();
     parent::tearDown();
 }
Esempio n. 3
0
 /**
  * decline server-to-server share
  *
  * @param array $params
  * @return \OC_OCS_Result
  */
 public function declineShare($params)
 {
     if (!$this->isS2SEnabled()) {
         return new \OC_OCS_Result(null, 503, 'Server does not support federated cloud sharing');
     }
     $id = $params['id'];
     $token = isset($_POST['token']) ? $_POST['token'] : null;
     $share = $this->getShare($id, $token);
     if ($share) {
         // userId must be set to the user who unshares
         \OCP\Share::unshare($share['item_type'], $share['item_source'], $share['share_type'], null, $share['uid_owner']);
         list($file, $link) = $this->getFile($share['uid_owner'], $share['file_source']);
         \OC::$server->getActivityManager()->publishActivity('files_sharing', \OCA\Files_Sharing\Activity::SUBJECT_REMOTE_SHARE_DECLINED, array($share['share_with'], basename($file)), '', array(), $file, $link, $share['uid_owner'], \OCA\Files_Sharing\Activity::TYPE_REMOTE_SHARE, \OCA\Files_Sharing\Activity::PRIORITY_LOW);
     }
     return new \OC_OCS_Result();
 }
Esempio n. 4
0
 /**
  * Makes the background job do its work
  *
  * @param array $argument unused argument
  */
 public function run($argument)
 {
     $connection = \OC::$server->getDatabaseConnection();
     $logger = \OC::$server->getLogger();
     //Current time
     $now = new \DateTime();
     $now = $now->format('Y-m-d H:i:s');
     /*
      * Expire file link shares only (for now)
      */
     $qb = $connection->getQueryBuilder();
     $qb->select('id', 'file_source', 'uid_owner', 'item_type')->from('share')->where($qb->expr()->andX($qb->expr()->eq('share_type', $qb->expr()->literal(\OCP\Share::SHARE_TYPE_LINK)), $qb->expr()->lte('expiration', $qb->expr()->literal($now)), $qb->expr()->orX($qb->expr()->eq('item_type', $qb->expr()->literal('file')), $qb->expr()->eq('item_type', $qb->expr()->literal('folder')))));
     $shares = $qb->execute();
     while ($share = $shares->fetch()) {
         \OCP\Share::unshare($share['item_type'], $share['file_source'], \OCP\Share::SHARE_TYPE_LINK, null, $share['uid_owner']);
     }
     $shares->closeCursor();
 }
Esempio n. 5
0
 /**
  * if a file was shared as group share and as individual share they should be grouped
  */
 public function testGroupingOfShares()
 {
     $fileinfo = $this->view->getFileInfo($this->filename);
     $result = \OCP\Share::shareItem('file', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_GROUP, \Test_Files_Sharing::TEST_FILES_SHARING_API_GROUP1, \OCP\Constants::PERMISSION_READ);
     $this->assertTrue($result);
     $result = \OCP\Share::shareItem('file', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_USER, \Test_Files_Sharing::TEST_FILES_SHARING_API_USER2, \OCP\Constants::PERMISSION_UPDATE);
     $this->assertTrue($result);
     self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
     $result = \OCP\Share::getItemSharedWith('file', null);
     $this->assertTrue(is_array($result));
     // test should return exactly one shares created from testCreateShare()
     $this->assertSame(1, count($result));
     $share = reset($result);
     $this->assertSame(\OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE, $share['permissions']);
     \OC\Files\Filesystem::rename($this->filename, $this->filename . '-renamed');
     $result = \OCP\Share::getItemSharedWith('file', null);
     $this->assertTrue(is_array($result));
     // test should return exactly one shares created from testCreateShare()
     $this->assertSame(1, count($result));
     $share = reset($result);
     $this->assertSame(\OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE, $share['permissions']);
     $this->assertSame($this->filename . '-renamed', $share['file_target']);
     self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
     // unshare user share
     $result = \OCP\Share::unshare('file', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_USER, \Test_Files_Sharing::TEST_FILES_SHARING_API_USER2);
     $this->assertTrue($result);
     self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
     $result = \OCP\Share::getItemSharedWith('file', null);
     $this->assertTrue(is_array($result));
     // test should return the remaining group share
     $this->assertSame(1, count($result));
     $share = reset($result);
     // only the group share permissions should be available now
     $this->assertSame(\OCP\Constants::PERMISSION_READ, $share['permissions']);
     $this->assertSame($this->filename . '-renamed', $share['file_target']);
 }
Esempio n. 6
0
 /**
  * @medium
  */
 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:///' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files/' . $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
     try {
         \OCP\Share::shareItem('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_GROUP, \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_GROUP1, OCP\PERMISSION_ALL);
     } catch (Exception $e) {
         $this->assertEquals(0, strpos($e->getMessage(), "Following users are not set up for encryption"));
     }
     // 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->chroot('/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files/');
     $this->view->unlink($this->filename);
     $this->view->chroot('/');
 }
Esempio n. 7
0
 /**
  * decline server-to-server share
  *
  * @param array $params
  * @return \OC_OCS_Result
  */
 public function declineShare($params)
 {
     if (!$this->isS2SEnabled()) {
         return new \OC_OCS_Result(null, 503, 'Server does not support federated cloud sharing');
     }
     $id = $params['id'];
     $token = isset($_POST['token']) ? $_POST['token'] : null;
     $share = $this->getShare($id, $token);
     if ($share) {
         // userId must be set to the user who unshares
         \OCP\Share::unshare($share['item_type'], $share['item_source'], $share['share_type'], null, $share['uid_owner']);
         list($file, $link) = $this->getFile($share['uid_owner'], $share['file_source']);
         $event = \OC::$server->getActivityManager()->generateEvent();
         $event->setApp(Activity::FILES_SHARING_APP)->setType(Activity::TYPE_REMOTE_SHARE)->setAffectedUser($share['uid_owner'])->setSubject(Activity::SUBJECT_REMOTE_SHARE_DECLINED, [$share['share_with'], basename($file)])->setObject('files', $share['file_source'], $file)->setLink($link);
         \OC::$server->getActivityManager()->publish($event);
     }
     return new \OC_OCS_Result();
 }
Esempio n. 8
0
 public function testOwnerUnshares()
 {
     $this->loginAsUser(self::TEST_FILES_SHARING_API_USER1);
     $folderInfo = $this->rootView->getFileInfo('/' . self::TEST_FILES_SHARING_API_USER1 . '/files/sub1/sub2/folder');
     $folderId = $folderInfo->getId();
     $this->assertTrue(\OCP\Share::unshare('folder', $folderId, \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2));
     $this->assertEtagsForFoldersChanged([self::TEST_FILES_SHARING_API_USER2, self::TEST_FILES_SHARING_API_USER4]);
     $this->assertAllUnchaged();
 }
 /**
  * @NoAdminRequired
  * @NoCSRFRequired
  * @SSOCORS
  */
 public function unshare($id, $type)
 {
     $shareWith = null;
     $path = \OC\Files\Filesystem::getPath($id);
     $response = array('id' => $id);
     if ($path === null) {
         if ($type == 'file') {
             $error_msg = self::msg_idNotExist;
         } else {
             $replacement = '${1}folder${3}';
             $error_msg = preg_replace($this->fileTypePattern, $replacement, self::msg_idNotExist);
         }
         return new DataResponse(array('data' => $response, 'status' => 'error', 'message' => $error_msg));
     }
     if (\OC\Files\Filesystem::filetype($path) !== $type) {
         $replacement = '${1}\'' . $type . '\'${3}' . 'id: ' . $id;
         $error_msg = preg_replace($this->errorTypePattern, $replacement, self::msg_errorType);
         return new DataResponse(array('data' => $response, 'status' => 'error', 'message' => $error_msg));
     }
     if ($type == 'dir') {
         $type = 'folder';
     }
     $unshare = \OCP\Share::unshare((string) $type, (string) $id, (int) $this->shareType, $shareWith);
     if ($unshare) {
         return new DataResponse(array('data' => $response, 'status' => 'success'));
     } else {
         $replacement = '${1}folder${3}';
         $error_msg = preg_replace($this->fileTypePattern, $replacement, self::msg_noRequireUnshareBeforeShare);
         return new DataResponse(array('data' => $response, 'status' => 'error', 'message' => $error_msg));
     }
 }
Esempio n. 10
0
 /**
  * If the permissions on a group share are upgraded be sure to still respect 
  * removed shares by a member of that group
  */
 function testPermissionUpgradeOnUserDeletedGroupShare()
 {
     \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');
     $connection = \OC::$server->getDatabaseConnection();
     // Share item with group
     $fileinfo = $this->view->getFileInfo($this->folder);
     $this->assertTrue(\OCP\Share::shareItem('folder', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_GROUP, "testGroup", \OCP\Constants::PERMISSION_READ));
     // Login as user 2 and verify the item exists
     self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
     $this->assertTrue(\OC\Files\Filesystem::file_exists($this->folder));
     $result = \OCP\Share::getItemSharedWithBySource('folder', $fileinfo['fileid']);
     $this->assertNotEmpty($result);
     $this->assertEquals(\OCP\Constants::PERMISSION_READ, $result['permissions']);
     // Delete the share
     $this->assertTrue(\OC\Files\Filesystem::rmdir($this->folder));
     $this->assertFalse(\OC\Files\Filesystem::file_exists($this->folder));
     // Verify we do not get a share
     $result = \OCP\Share::getItemSharedWithBySource('folder', $fileinfo['fileid']);
     $this->assertEmpty($result);
     // Verify that the permission is correct in the DB
     $qb = $connection->getQueryBuilder();
     $qb->select('*')->from('share')->where($qb->expr()->eq('file_source', $qb->createParameter('fileSource')))->andWhere($qb->expr()->eq('share_type', $qb->createParameter('shareType')))->setParameter(':fileSource', $fileinfo['fileid'])->setParameter(':shareType', 2);
     $res = $qb->execute()->fetchAll();
     $this->assertCount(1, $res);
     $this->assertEquals(0, $res[0]['permissions']);
     // Login as user 1 again and change permissions
     self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
     $this->assertTrue(\OCP\Share::setPermissions('folder', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_GROUP, "testGroup", \OCP\Constants::PERMISSION_ALL));
     // Login as user 2 and verify
     self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
     $this->assertFalse(\OC\Files\Filesystem::file_exists($this->folder));
     $result = \OCP\Share::getItemSharedWithBySource('folder', $fileinfo['fileid']);
     $this->assertEmpty($result);
     $connection = \OC::$server->getDatabaseConnection();
     $qb = $connection->getQueryBuilder();
     $qb->select('*')->from('share')->where($qb->expr()->eq('file_source', $qb->createParameter('fileSource')))->andWhere($qb->expr()->eq('share_type', $qb->createParameter('shareType')))->setParameter(':fileSource', $fileinfo['fileid'])->setParameter(':shareType', 2);
     $res = $qb->execute()->fetchAll();
     $this->assertCount(1, $res);
     $this->assertEquals(0, $res[0]['permissions']);
     //cleanup
     self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
     \OCP\Share::unshare('folder', $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');
 }
Esempio n. 11
0
 function testGetFolderContentsWhenSubSubdirShared()
 {
     self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
     $fileinfo = $this->view->getFileInfo('container/shareddir/subdir');
     \OCP\Share::shareItem('folder', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER3, 31);
     self::loginHelper(self::TEST_FILES_SHARING_API_USER3);
     $thirdView = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER3 . '/files');
     $results = $thirdView->getDirectoryContent('/subdir');
     $this->verifyFiles(array(array('name' => 'another too.txt', 'path' => 'another too.txt', 'mimetype' => 'text/plain', 'uid_owner' => self::TEST_FILES_SHARING_API_USER1, 'displayname_owner' => 'User One'), array('name' => 'another.txt', 'path' => 'another.txt', 'mimetype' => 'text/plain', 'uid_owner' => self::TEST_FILES_SHARING_API_USER1, 'displayname_owner' => 'User One'), array('name' => 'not a text file.xml', 'path' => 'not a text file.xml', 'mimetype' => 'application/xml', 'uid_owner' => self::TEST_FILES_SHARING_API_USER1, 'displayname_owner' => 'User One')), $results);
     self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
     \OCP\Share::unshare('folder', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER3);
 }
Esempio n. 12
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();
 }
Esempio n. 13
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');
 }
Esempio n. 14
0
 /**
  * unshare a file/folder
  * @param array $params contains the shareID 'id' which should be unshared
  * @return \OC_OCS_Result
  */
 public static function deleteShare($params)
 {
     $share = self::getShareFromId($params['id']);
     $fileSource = isset($share['file_source']) ? $share['file_source'] : null;
     $itemType = isset($share['item_type']) ? $share['item_type'] : null;
     if ($fileSource === null) {
         return new \OC_OCS_Result(null, 404, "wrong share ID, share doesn't exist.");
     }
     $shareWith = isset($share['share_with']) ? $share['share_with'] : null;
     $shareType = isset($share['share_type']) ? (int) $share['share_type'] : null;
     if ($shareType === \OCP\Share::SHARE_TYPE_LINK) {
         $shareWith = null;
     }
     try {
         $return = \OCP\Share::unshare($itemType, $fileSource, $shareType, $shareWith);
     } catch (\Exception $e) {
         return new \OC_OCS_Result(null, 404, $e->getMessage());
     }
     if ($return) {
         return new \OC_OCS_Result();
     } else {
         $msg = "Unshare Failed";
         return new \OC_OCS_Result(null, 404, $msg);
     }
 }
Esempio n. 15
0
 /**
  * shared files should never have delete permissions
  * @dataProvider  DataProviderTestFileSharePermissions
  */
 function testFileSharePermissions($permission, $expectedPermissions)
 {
     $fileinfo = $this->view->getFileInfo($this->filename);
     $result = \OCP\Share::shareItem('file', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_USER, \Test_Files_Sharing::TEST_FILES_SHARING_API_USER2, $permission);
     $this->assertTrue($result);
     $result = \OCP\Share::getItemShared('file', null);
     $this->assertTrue(is_array($result));
     // test should return exactly one shares created from testCreateShare()
     $this->assertTrue(count($result) === 1);
     $share = reset($result);
     $this->assertSame($expectedPermissions, $share['permissions']);
     \OCP\Share::unshare('file', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_USER, \Test_Files_Sharing::TEST_FILES_SHARING_API_USER2);
 }
Esempio n. 16
0
 function testDeleteHooksForSharedFiles()
 {
     \Test_Encryption_Util::logoutHelper();
     \Test_Encryption_Util::loginHelper(\Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER1);
     \OC_User::setUserId(\Test_Encryption_Hooks::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/share-keys/' . $this->filename . '.' . \Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER1 . '.shareKey'));
     $this->assertTrue($this->rootView->file_exists(self::TEST_ENCRYPTION_HOOKS_USER1 . '/files_encryption/keyfiles/' . $this->filename . '.key'));
     // get the file info from previous created file
     $fileInfo = $this->user1View->getFileInfo($this->filename);
     // check if we have a valid file info
     $this->assertTrue(is_array($fileInfo));
     // share the file with user2
     \OCP\Share::shareItem('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER, self::TEST_ENCRYPTION_HOOKS_USER2, OCP\PERMISSION_ALL);
     // check if new share key exists
     $this->assertTrue($this->rootView->file_exists(self::TEST_ENCRYPTION_HOOKS_USER1 . '/files_encryption/share-keys/' . $this->filename . '.' . \Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER2 . '.shareKey'));
     \Test_Encryption_Util::logoutHelper();
     \Test_Encryption_Util::loginHelper(\Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER2);
     \OC_User::setUserId(\Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER2);
     // user2 has a local file with the same name
     $this->user2View->file_put_contents($this->filename, $this->data);
     // check if all keys are generated
     $this->assertTrue($this->rootView->file_exists(self::TEST_ENCRYPTION_HOOKS_USER2 . '/files_encryption/share-keys/' . $this->filename . '.' . \Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER2 . '.shareKey'));
     $this->assertTrue($this->rootView->file_exists(self::TEST_ENCRYPTION_HOOKS_USER2 . '/files_encryption/keyfiles/' . $this->filename . '.key'));
     // delete the Shared file from user1 in data/user2/files/Shared
     $this->user2View->unlink('/Shared/' . $this->filename);
     // now keys from user1s home should be gone
     $this->assertFalse($this->rootView->file_exists(self::TEST_ENCRYPTION_HOOKS_USER1 . '/files_encryption/share-keys/' . $this->filename . '.' . \Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER1 . '.shareKey'));
     $this->assertFalse($this->rootView->file_exists(self::TEST_ENCRYPTION_HOOKS_USER1 . '/files_encryption/share-keys/' . $this->filename . '.' . \Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER2 . '.shareKey'));
     $this->assertFalse($this->rootView->file_exists(self::TEST_ENCRYPTION_HOOKS_USER1 . '/files_encryption/keyfiles/' . $this->filename . '.key'));
     // but user2 keys should still exist
     $this->assertTrue($this->rootView->file_exists(self::TEST_ENCRYPTION_HOOKS_USER2 . '/files_encryption/share-keys/' . $this->filename . '.' . \Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER2 . '.shareKey'));
     $this->assertTrue($this->rootView->file_exists(self::TEST_ENCRYPTION_HOOKS_USER2 . '/files_encryption/keyfiles/' . $this->filename . '.key'));
     // cleanup
     $this->user2View->unlink($this->filename);
     \Test_Encryption_Util::logoutHelper();
     \Test_Encryption_Util::loginHelper(\Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER1);
     \OC_User::setUserId(\Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER1);
     // unshare the file
     \OCP\Share::unshare('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER, self::TEST_ENCRYPTION_HOOKS_USER2);
     $this->user1View->unlink($this->filename);
     if ($stateFilesTrashbin) {
         OC_App::enable('files_trashbin');
     } else {
         OC_App::disable('files_trashbin');
     }
 }
Esempio n. 17
0
	/**
	 * @dataProvider dataRemoteShareUrlCalls
	 *
	 * @param string $shareWith
	 * @param string $urlHost
	 */
	public function testRemoteShareUrlCalls($shareWith, $urlHost) {
		$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://' . $urlHost . '/ocs/v1.php/cloud/shares'), $this->anything())
			->willReturn(['success' => false, 'result' => 'Exception']);
		$httpHelperMock->expects($this->at(1))
			->method('post')
			->with($this->stringStartsWith('http://' . $urlHost . '/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, $shareWith, \OCP\Constants::PERMISSION_READ);
		$shares = \OCP\Share::getItemShared('test', 'test.txt');
		$share = array_shift($shares);

		$httpHelperMock->expects($this->at(0))
			->method('post')
			->with($this->stringStartsWith('https://' . $urlHost . '/ocs/v1.php/cloud/shares/' . $share['id'] . '/unshare'), $this->anything())
			->willReturn(['success' => false, 'result' => 'Exception']);
		$httpHelperMock->expects($this->at(1))
			->method('post')
			->with($this->stringStartsWith('http://' . $urlHost . '/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, $shareWith);
		$this->setHttpHelper($oldHttpHelper);
	}
Esempio n. 18
0
 /**
  * Tests mounting a folder that is an external storage mount point.
  */
 public function testShareStorageMountPoint()
 {
     self::$tempStorage = new \OC\Files\Storage\Temporary(array());
     self::$tempStorage->file_put_contents('test.txt', 'abcdef');
     self::$tempStorage->getScanner()->scan('');
     // needed because the sharing code sometimes switches the user internally and mounts the user's
     // storages. In our case the temp storage isn't mounted automatically, so doing it in the post hook
     // (similar to how ext storage works)
     OCP\Util::connectHook('OC_Filesystem', 'post_initMountPoints', '\\Test_Files_Sharing_Api', 'initTestMountPointsHook');
     // logging in will auto-mount the temp storage for user1 as well
     \Test_Files_Sharing_Api::loginHelper(\Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER1);
     $fileInfo = $this->view->getFileInfo($this->folder);
     // user 1 shares the mount point folder with user2
     $result = \OCP\Share::shareItem('folder', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER, \Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER2, 31);
     $this->assertTrue($result);
     // user2: check that mount point name appears correctly
     \Test_Files_Sharing_Api::loginHelper(\Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER2);
     $view = new \OC\Files\View('/' . \Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER2 . '/files/Shared');
     $this->assertTrue($view->file_exists($this->folder));
     $this->assertTrue($view->file_exists($this->folder . '/test.txt'));
     \Test_Files_Sharing_Api::loginHelper(\Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER1);
     \OCP\Share::unshare('folder', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER, \Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER2);
     \OC_Hook::clear('OC_Filesystem', 'post_initMountPoints', '\\Test_Files_Sharing_Api', 'initTestMountPointsHook');
 }
Esempio n. 19
0
 public function testFopenWithCreateOnlyPermission()
 {
     $this->view->file_put_contents($this->folder . '/existing.txt', 'foo');
     $fileinfoFolder = $this->view->getFileInfo($this->folder);
     $share = $this->share(\OCP\Share::SHARE_TYPE_USER, $this->folder, self::TEST_FILES_SHARING_API_USER1, self::TEST_FILES_SHARING_API_USER2, \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_CREATE);
     self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
     $user2View = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files');
     // create part file allowed
     $handle = $user2View->fopen($this->folder . '/test.txt.part', 'w');
     $this->assertNotFalse($handle);
     fclose($handle);
     // create regular file allowed
     $handle = $user2View->fopen($this->folder . '/test-create.txt', 'w');
     $this->assertNotFalse($handle);
     fclose($handle);
     // rename file never allowed
     $this->assertFalse($user2View->rename($this->folder . '/test-create.txt', $this->folder . '/newtarget.txt'));
     $this->assertFalse($user2View->file_exists($this->folder . '/newtarget.txt'));
     // rename file not allowed if target exists
     $this->assertFalse($user2View->rename($this->folder . '/newtarget.txt', $this->folder . '/existing.txt'));
     // overwriting file not allowed
     $handle = $user2View->fopen($this->folder . '/existing.txt', 'w');
     $this->assertFalse($handle);
     // overwrite forbidden (no update permission)
     $this->assertFalse($user2View->rename($this->folder . '/test.txt.part', $this->folder . '/existing.txt'));
     // delete forbidden
     $this->assertFalse($user2View->unlink($this->folder . '/existing.txt'));
     //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);
 }
Esempio n. 20
0
 public function testDefaultExpireDate()
 {
     \Test_Files_Sharing_Api::loginHelper(\Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER1);
     \OC_Appconfig::setValue('core', 'shareapi_default_expire_date', 'yes');
     \OC_Appconfig::setValue('core', 'shareapi_enforce_expire_date', 'yes');
     \OC_Appconfig::setValue('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\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);
     $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);
     \OC_Appconfig::setValue('core', 'shareapi_default_expire_date', 'no');
     \OC_Appconfig::setValue('core', 'shareapi_enforce_expire_date', 'no');
 }
Esempio n. 21
0
 public function testFopenWithDeleteOnlyPermission()
 {
     $this->view->file_put_contents($this->folder . '/existing.txt', 'foo');
     $fileinfoFolder = $this->view->getFileInfo($this->folder);
     $result = \OCP\Share::shareItem('folder', $fileinfoFolder['fileid'], \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2, \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_DELETE);
     $this->assertTrue($result);
     self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
     $user2View = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files');
     // part file should be forbidden
     $handle = $user2View->fopen($this->folder . '/test.txt.part', 'w');
     $this->assertFalse($handle);
     // regular file forbidden
     $handle = $user2View->fopen($this->folder . '/test.txt', 'w');
     $this->assertFalse($handle);
     // rename forbidden
     $this->assertFalse($user2View->rename($this->folder . '/existing.txt', $this->folder . '/existing2.txt'));
     // delete allowed
     $this->assertTrue($user2View->unlink($this->folder . '/existing.txt'));
     //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);
 }
Esempio n. 22
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);
 }
Esempio n. 23
0
 public function testDefaultExpireDate()
 {
     self::loginHelper(self::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, self::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, self::TEST_FILES_SHARING_API_USER2);
     $this->assertTrue($result);
     $config->setAppValue('core', 'shareapi_default_expire_date', 'no');
     $config->setAppValue('core', 'shareapi_enforce_expire_date', 'no');
 }
Esempio n. 24
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);
 }
Esempio n. 25
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);
 }
Esempio n. 26
0
File: api.php Progetto: evanjt/core
 public function testCreatePublicLinkExpireDateValid()
 {
     $config = \OC::$server->getConfig();
     // enforce expire date, by default 7 days after the file was shared
     $config->setAppValue('core', 'shareapi_default_expire_date', 'yes');
     $config->setAppValue('core', 'shareapi_enforce_expire_date', 'yes');
     $date = new \DateTime();
     $date->add(new \DateInterval('P5D'));
     $_POST['path'] = $this->folder;
     $_POST['shareType'] = \OCP\Share::SHARE_TYPE_LINK;
     $_POST['expireDate'] = $date->format('Y-m-d');
     $result = \OCA\Files_Sharing\API\Local::createShare([]);
     $this->assertTrue($result->succeeded());
     $data = $result->getData();
     $this->assertTrue(is_string($data['token']));
     $this->assertEquals($date->format('Y-m-d') . ' 00:00:00', $data['expiration']);
     // check for correct link
     $url = \OC::$server->getURLGenerator()->getAbsoluteURL('/index.php/s/' . $data['token']);
     $this->assertEquals($url, $data['url']);
     $share = $this->getShareFromId($data['id']);
     $items = \OCP\Share::getItemShared('file', $share['item_source']);
     $this->assertTrue(!empty($items));
     $item = reset($items);
     $this->assertTrue(is_array($item));
     $this->assertEquals($date->format('Y-m-d'), substr($item['expiration'], 0, 10));
     $fileinfo = $this->view->getFileInfo($this->folder);
     \OCP\Share::unshare('folder', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_LINK, null);
     $config->setAppValue('core', 'shareapi_default_expire_date', 'no');
     $config->setAppValue('core', 'shareapi_enforce_expire_date', 'no');
 }
Esempio n. 27
0
 /**
  * @medium
  */
 function testUpdateShareUpload()
 {
     $fileInfo = $this->view->getFileInfo($this->folder);
     $result = \OCP\Share::shareItem('folder', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_LINK, null, 1);
     // share was successful?
     $this->assertTrue(is_string($result));
     $items = \OCP\Share::getItemShared('file', null);
     // make sure that we found a link share and a user share
     $this->assertEquals(count($items), 1);
     $linkShare = null;
     foreach ($items as $item) {
         if ($item['share_type'] === \OCP\Share::SHARE_TYPE_LINK) {
             $linkShare = $item;
         }
     }
     // make sure that we found a link share
     $this->assertTrue(is_array($linkShare));
     // update public upload
     $params = array();
     $params['id'] = $linkShare['id'];
     $params['_put'] = array();
     $params['_put']['publicUpload'] = 'true';
     $result = Share\Api::updateShare($params);
     $this->assertTrue($result->succeeded());
     $items = \OCP\Share::getItemShared('file', $linkShare['file_source']);
     $updatedLinkShare = null;
     foreach ($items as $item) {
         if ($item['share_type'] === \OCP\Share::SHARE_TYPE_LINK) {
             $updatedLinkShare = $item;
             break;
         }
     }
     $this->assertTrue(is_array($updatedLinkShare));
     $this->assertEquals(7, $updatedLinkShare['permissions']);
     // cleanup
     \OCP\Share::unshare('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_LINK, null);
 }