Delete expired share when fetched by id

remotes/origin/users-ajaxloadgroups
Roeland Jago Douma 2016-02-05 15:34:30 +07:00
parent 5ed56d9edb
commit 3028ec5440
2 changed files with 35 additions and 0 deletions

@ -803,6 +803,14 @@ class Manager implements IManager {
$share = $provider->getShareById($id, $recipient);
// Validate link shares expiration date
if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK &&
$share->getExpirationDate() !== null &&
$share->getExpirationDate() <= new \DateTime()) {
$this->deleteShare($share);
throw new ShareNotFound();
}
return $share;
}

@ -500,6 +500,33 @@ class ManagerTest extends \Test\TestCase {
$this->assertEquals($share, $this->manager->getShareById('default:42'));
}
/**
* @expectedException \OCP\Share\Exceptions\ShareNotFound
*/
public function testGetExpiredShareById() {
$manager = $this->createManagerMock()
->setMethods(['deleteShare'])
->getMock();
$date = new \DateTime();
$date->setTime(0,0,0);
$share = $this->manager->newShare();
$share->setExpirationDate($date)
->setShareType(\OCP\Share::SHARE_TYPE_LINK);
$this->defaultProvider->expects($this->once())
->method('getShareById')
->with('42')
->willReturn($share);
$manager->expects($this->once())
->method('deleteShare')
->with($share);
$manager->getShareById('default:42');
}
/**
* @expectedException InvalidArgumentException
* @expectedExceptionMessage Passwords are enforced for link shares