Ejemplo n.º 1
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');
 }
Ejemplo n.º 2
0
Archivo: api.php Proyecto: evanjt/core
 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');
 }
Ejemplo n.º 3
0
 /**
  * @medium
  * @depends testCreateShare
  */
 function testGetShareFromSourceWithReshares()
 {
     $fileInfo = $this->view->getFileInfo($this->filename);
     // share the file as user1 to user2
     \OCP\Share::shareItem('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER, \Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER2, 31);
     // login as user2 and reshare the file to user3
     \Test_Files_Sharing_Api::loginHelper(\Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER2);
     \OCP\Share::shareItem('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER, \Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER3, 31);
     // login as user1 again
     \Test_Files_Sharing_Api::loginHelper(\Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER1);
     $_GET['path'] = $this->filename;
     $result = Share\Api::getAllShares(array());
     $this->assertTrue($result->succeeded());
     // test should return one share
     $this->assertTrue(count($result->getData()) === 1);
     // now also ask for the reshares
     $_GET['reshares'] = 'true';
     $result = Share\Api::getAllShares(array());
     $this->assertTrue($result->succeeded());
     // now we should get two shares, the initial share and the reshare
     $this->assertTrue(count($result->getData()) === 2);
     // unshare files again
     \Test_Files_Sharing_Api::loginHelper(\Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER2);
     \OCP\Share::unshare('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER, \Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER3);
     \Test_Files_Sharing_Api::loginHelper(\Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER1);
     \OCP\Share::unshare('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER, \Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER2);
 }