Delete a link share if it is expired on access
If we access a link share we should check if it has expired already. If so we should remove it and throw a ShareNotFound exception
This commit is contained in:
parent
69a4cd2898
commit
5ed56d9edb
|
@ -831,7 +831,11 @@ class Manager implements IManager {
|
|||
|
||||
$share = $provider->getShareByToken($token);
|
||||
|
||||
//TODO check if share expired
|
||||
if ($share->getExpirationDate() !== null &&
|
||||
$share->getExpirationDate() <= new \DateTime()) {
|
||||
$this->deleteShare($share);
|
||||
throw new ShareNotFound();
|
||||
}
|
||||
|
||||
return $share;
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ namespace Test\Share20;
|
|||
|
||||
use OCP\Files\IRootFolder;
|
||||
use OCP\IUserManager;
|
||||
use OCP\Share\Exceptions\ShareNotFound;
|
||||
use OCP\Share\IProviderFactory;
|
||||
use OCP\Share\IShare;
|
||||
use OC\Share20\Manager;
|
||||
|
@ -1704,6 +1705,48 @@ class ManagerTest extends \Test\TestCase {
|
|||
$this->assertSame($share, $ret);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \OCP\Share\Exceptions\ShareNotFound
|
||||
*/
|
||||
public function testGetShareByTokenExpired() {
|
||||
$manager = $this->createManagerMock()
|
||||
->setMethods(['deleteShare'])
|
||||
->getMock();
|
||||
|
||||
$date = new \DateTime();
|
||||
$date->setTime(0,0,0);
|
||||
$share = $this->manager->newShare();
|
||||
$share->setExpirationDate($date);
|
||||
|
||||
$this->defaultProvider->expects($this->once())
|
||||
->method('getShareByToken')
|
||||
->with('expiredToken')
|
||||
->willReturn($share);
|
||||
|
||||
$manager->expects($this->once())
|
||||
->method('deleteShare')
|
||||
->with($this->equalTo($share));
|
||||
|
||||
$manager->getShareByToken('expiredToken');
|
||||
}
|
||||
|
||||
public function testGetShareByTokenNotExpired() {
|
||||
$date = new \DateTime();
|
||||
$date->setTime(0,0,0);
|
||||
$date->add(new \DateInterval('P2D'));
|
||||
$share = $this->manager->newShare();
|
||||
$share->setExpirationDate($date);
|
||||
|
||||
$this->defaultProvider->expects($this->once())
|
||||
->method('getShareByToken')
|
||||
->with('expiredToken')
|
||||
->willReturn($share);
|
||||
|
||||
$res = $this->manager->getShareByToken('expiredToken');
|
||||
|
||||
$this->assertSame($share, $res);
|
||||
}
|
||||
|
||||
public function testCheckPasswordNoLinkShare() {
|
||||
$share = $this->getMock('\OCP\Share\IShare');
|
||||
$share->method('getShareType')->willReturn(\OCP\Share::SHARE_TYPE_USER);
|
||||
|
|
Loading…
Reference in New Issue