diff options
author | Roeland Jago Douma <rullzer@owncloud.com> | 2016-02-05 12:59:46 +0100 |
---|---|---|
committer | Roeland Jago Douma <rullzer@owncloud.com> | 2016-02-06 13:31:54 +0100 |
commit | 5ed56d9edb54bf3f977ea12f44fca9e4b650c72b (patch) | |
tree | d8bfeba468ff57d882933cca2b93fe9e7097be14 | |
parent | 69a4cd2898d8b65257ccd1e526a4c3baad386a31 (diff) | |
download | nextcloud-server-5ed56d9edb54bf3f977ea12f44fca9e4b650c72b.tar.gz nextcloud-server-5ed56d9edb54bf3f977ea12f44fca9e4b650c72b.zip |
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
-rw-r--r-- | lib/private/share20/manager.php | 6 | ||||
-rw-r--r-- | tests/lib/share20/managertest.php | 43 |
2 files changed, 48 insertions, 1 deletions
diff --git a/lib/private/share20/manager.php b/lib/private/share20/manager.php index d65fb927f9b..a393cdeb89c 100644 --- a/lib/private/share20/manager.php +++ b/lib/private/share20/manager.php @@ -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; } diff --git a/tests/lib/share20/managertest.php b/tests/lib/share20/managertest.php index 131bc7fbfd2..d93a881a448 100644 --- a/tests/lib/share20/managertest.php +++ b/tests/lib/share20/managertest.php @@ -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); |