|
|
|
|
@ -1518,7 +1518,7 @@ class Test_Files_Sharing_Api extends TestCase { |
|
|
|
|
if ($valid === false) { |
|
|
|
|
$this->assertFalse($result->succeeded()); |
|
|
|
|
$this->assertEquals(404, $result->getStatusCode()); |
|
|
|
|
$this->assertEquals('Invalid Date', $result->getMeta()['message']); |
|
|
|
|
$this->assertEquals('Invalid Date. Format must be YYYY-MM-DD.', $result->getMeta()['message']); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -1543,4 +1543,90 @@ class Test_Files_Sharing_Api extends TestCase { |
|
|
|
|
$fileinfo = $this->view->getFileInfo($this->folder); |
|
|
|
|
\OCP\Share::unshare('folder', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_LINK, null); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
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'])); |
|
|
|
|
|
|
|
|
|
// 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'); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function testCreatePublicLinkExpireDateInvalidFuture() { |
|
|
|
|
$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('P8D')); |
|
|
|
|
|
|
|
|
|
$_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->assertFalse($result->succeeded()); |
|
|
|
|
$this->assertEquals(404, $result->getStatusCode()); |
|
|
|
|
$this->assertEquals('Cannot set expiration date. Shares cannot expire later than 7 after they have been shared', $result->getMeta()['message']); |
|
|
|
|
|
|
|
|
|
$config->setAppValue('core', 'shareapi_default_expire_date', 'no'); |
|
|
|
|
$config->setAppValue('core', 'shareapi_enforce_expire_date', 'no'); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function testCreatePublicLinkExpireDateInvalidPast() { |
|
|
|
|
$config = \OC::$server->getConfig(); |
|
|
|
|
|
|
|
|
|
$date = new \DateTime(); |
|
|
|
|
$date->sub(new \DateInterval('P8D')); |
|
|
|
|
|
|
|
|
|
$_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->assertFalse($result->succeeded()); |
|
|
|
|
$this->assertEquals(404, $result->getStatusCode()); |
|
|
|
|
$this->assertEquals('Cannot set expiration date. Expiration date is in the past', $result->getMeta()['message']); |
|
|
|
|
|
|
|
|
|
$config->setAppValue('core', 'shareapi_default_expire_date', 'no'); |
|
|
|
|
$config->setAppValue('core', 'shareapi_enforce_expire_date', 'no'); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|