$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;
}
use OCP\Files\IRootFolder;
use OCP\IUserManager;
+use OCP\Share\Exceptions\ShareNotFound;
use OCP\Share\IProviderFactory;
use OCP\Share\IShare;
use OC\Share20\Manager;
$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);