]> source.dussan.org Git - nextcloud-server.git/commitdiff
Delete a link share if it is expired on access
authorRoeland Jago Douma <rullzer@owncloud.com>
Fri, 5 Feb 2016 11:59:46 +0000 (12:59 +0100)
committerRoeland Jago Douma <rullzer@owncloud.com>
Sat, 6 Feb 2016 12:31:54 +0000 (13:31 +0100)
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

lib/private/share20/manager.php
tests/lib/share20/managertest.php

index d65fb927f9bd9aafcb1c5abf0efb1758ee228488..a393cdeb89cd80668337ec2f472cff9225dbf132 100644 (file)
@@ -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;
        }
index 131bc7fbfd2e666cc34611d4c48cfd8cd2a86156..d93a881a44801c8886aa33a8a1b22f752ccfa90b 100644 (file)
@@ -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);