|
|
@@ -213,19 +213,20 @@ class ShareAPIControllerTest extends TestCase { |
|
|
|
|
|
|
|
/** |
|
|
|
* @expectedException \OCP\AppFramework\OCS\OCSNotFoundException |
|
|
|
* @expectedExceptionMessage could not delete share |
|
|
|
* @expectedExceptionMessage Could not delete share |
|
|
|
*/ |
|
|
|
public function testDeleteShareLocked() { |
|
|
|
$node = $this->getMockBuilder(File::class)->getMock(); |
|
|
|
|
|
|
|
$share = $this->newShare(); |
|
|
|
$share->setSharedBy($this->currentUser) |
|
|
|
->setNode($node); |
|
|
|
$share->setNode($node); |
|
|
|
|
|
|
|
$this->shareManager |
|
|
|
->expects($this->once()) |
|
|
|
->method('getShareById') |
|
|
|
->with('ocinternal:42') |
|
|
|
->willReturn($share); |
|
|
|
|
|
|
|
$this->shareManager |
|
|
|
->expects($this->never()) |
|
|
|
->method('deleteShare') |
|
|
@@ -235,6 +236,205 @@ class ShareAPIControllerTest extends TestCase { |
|
|
|
->method('lock') |
|
|
|
->with(\OCP\Lock\ILockingProvider::LOCK_SHARED) |
|
|
|
->will($this->throwException(new LockedException('mypath'))); |
|
|
|
|
|
|
|
$this->assertFalse($this->invokePrivate($this->ocs, 'canDeleteFromSelf', [$share])); |
|
|
|
$this->assertFalse($this->invokePrivate($this->ocs, 'canDeleteShare', [$share])); |
|
|
|
|
|
|
|
$this->ocs->deleteShare(42); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* You can always remove a share that was shared with you |
|
|
|
*/ |
|
|
|
public function testDeleteShareWithMe() { |
|
|
|
$node = $this->getMockBuilder(File::class)->getMock(); |
|
|
|
|
|
|
|
$share = $this->newShare(); |
|
|
|
$share->setSharedWith($this->currentUser) |
|
|
|
->setShareType(\OCP\Share::SHARE_TYPE_USER) |
|
|
|
->setNode($node); |
|
|
|
|
|
|
|
$this->shareManager |
|
|
|
->expects($this->once()) |
|
|
|
->method('getShareById') |
|
|
|
->with('ocinternal:42') |
|
|
|
->willReturn($share); |
|
|
|
|
|
|
|
$this->shareManager |
|
|
|
->expects($this->once()) |
|
|
|
->method('deleteShare') |
|
|
|
->with($share); |
|
|
|
|
|
|
|
$node->expects($this->once()) |
|
|
|
->method('lock') |
|
|
|
->with(\OCP\Lock\ILockingProvider::LOCK_SHARED); |
|
|
|
|
|
|
|
$this->assertFalse($this->invokePrivate($this->ocs, 'canDeleteFromSelf', [$share])); |
|
|
|
$this->assertTrue($this->invokePrivate($this->ocs, 'canDeleteShare', [$share])); |
|
|
|
|
|
|
|
$this->ocs->deleteShare(42); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* You can always delete a share you own |
|
|
|
*/ |
|
|
|
public function testDeleteShareOwner() { |
|
|
|
$node = $this->getMockBuilder(File::class)->getMock(); |
|
|
|
|
|
|
|
$share = $this->newShare(); |
|
|
|
$share->setSharedBy($this->currentUser) |
|
|
|
->setNode($node); |
|
|
|
|
|
|
|
$this->shareManager |
|
|
|
->expects($this->once()) |
|
|
|
->method('getShareById') |
|
|
|
->with('ocinternal:42') |
|
|
|
->willReturn($share); |
|
|
|
|
|
|
|
$this->shareManager |
|
|
|
->expects($this->once()) |
|
|
|
->method('deleteShare') |
|
|
|
->with($share); |
|
|
|
|
|
|
|
$node->expects($this->once()) |
|
|
|
->method('lock') |
|
|
|
->with(\OCP\Lock\ILockingProvider::LOCK_SHARED); |
|
|
|
|
|
|
|
$this->assertFalse($this->invokePrivate($this->ocs, 'canDeleteFromSelf', [$share])); |
|
|
|
$this->assertTrue($this->invokePrivate($this->ocs, 'canDeleteShare', [$share])); |
|
|
|
|
|
|
|
$this->ocs->deleteShare(42); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* You can always delete a share when you own |
|
|
|
* the file path it belong to |
|
|
|
*/ |
|
|
|
public function testDeleteShareFileOwner() { |
|
|
|
$node = $this->getMockBuilder(File::class)->getMock(); |
|
|
|
|
|
|
|
$share = $this->newShare(); |
|
|
|
$share->setShareOwner($this->currentUser) |
|
|
|
->setNode($node); |
|
|
|
|
|
|
|
$this->shareManager |
|
|
|
->expects($this->once()) |
|
|
|
->method('getShareById') |
|
|
|
->with('ocinternal:42') |
|
|
|
->willReturn($share); |
|
|
|
|
|
|
|
$this->shareManager |
|
|
|
->expects($this->once()) |
|
|
|
->method('deleteShare') |
|
|
|
->with($share); |
|
|
|
|
|
|
|
$node->expects($this->once()) |
|
|
|
->method('lock') |
|
|
|
->with(\OCP\Lock\ILockingProvider::LOCK_SHARED); |
|
|
|
|
|
|
|
$this->assertFalse($this->invokePrivate($this->ocs, 'canDeleteFromSelf', [$share])); |
|
|
|
$this->assertTrue($this->invokePrivate($this->ocs, 'canDeleteShare', [$share])); |
|
|
|
|
|
|
|
$this->ocs->deleteShare(42); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* You can remove (the mountpoint, not the share) |
|
|
|
* a share if you're in the group the share is shared with |
|
|
|
*/ |
|
|
|
public function testDeleteSharedWithMyGroup() { |
|
|
|
$node = $this->getMockBuilder(File::class)->getMock(); |
|
|
|
|
|
|
|
$share = $this->newShare(); |
|
|
|
$share->setShareType(\OCP\Share::SHARE_TYPE_GROUP) |
|
|
|
->setSharedWith('group') |
|
|
|
->setNode($node); |
|
|
|
|
|
|
|
$this->shareManager |
|
|
|
->expects($this->once()) |
|
|
|
->method('getShareById') |
|
|
|
->with('ocinternal:42') |
|
|
|
->willReturn($share); |
|
|
|
|
|
|
|
// canDeleteShareFromSelf |
|
|
|
$user = $this->createMock(IUser::class); |
|
|
|
$group = $this->getMockBuilder('OCP\IGroup')->getMock(); |
|
|
|
$this->groupManager |
|
|
|
->method('get') |
|
|
|
->with('group') |
|
|
|
->willReturn($group); |
|
|
|
$this->userManager |
|
|
|
->method('get') |
|
|
|
->with($this->currentUser) |
|
|
|
->willReturn($user); |
|
|
|
$group->method('inGroup') |
|
|
|
->with($user) |
|
|
|
->willReturn(true); |
|
|
|
|
|
|
|
$node->expects($this->once()) |
|
|
|
->method('lock') |
|
|
|
->with(\OCP\Lock\ILockingProvider::LOCK_SHARED); |
|
|
|
|
|
|
|
$this->shareManager->expects($this->once()) |
|
|
|
->method('deleteFromSelf') |
|
|
|
->with($share, $this->currentUser); |
|
|
|
|
|
|
|
$this->shareManager->expects($this->never()) |
|
|
|
->method('deleteShare'); |
|
|
|
|
|
|
|
$this->assertTrue($this->invokePrivate($this->ocs, 'canDeleteShareFromSelf', [$share])); |
|
|
|
$this->assertFalse($this->invokePrivate($this->ocs, 'canDeleteShare', [$share])); |
|
|
|
|
|
|
|
$this->ocs->deleteShare(42); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* You cannot remove a share if you're not |
|
|
|
* in the group the share is shared with |
|
|
|
* @expectedException \OCP\AppFramework\OCS\OCSNotFoundException |
|
|
|
* @expectedExceptionMessage Wrong share ID, share doesn't exist |
|
|
|
*/ |
|
|
|
public function testDeleteSharedWithGroupIDontBelongTo() { |
|
|
|
$node = $this->getMockBuilder(File::class)->getMock(); |
|
|
|
|
|
|
|
$share = $this->newShare(); |
|
|
|
$share->setShareType(\OCP\Share::SHARE_TYPE_GROUP) |
|
|
|
->setSharedWith('group') |
|
|
|
->setNode($node); |
|
|
|
|
|
|
|
$this->shareManager |
|
|
|
->expects($this->once()) |
|
|
|
->method('getShareById') |
|
|
|
->with('ocinternal:42') |
|
|
|
->willReturn($share); |
|
|
|
|
|
|
|
// canDeleteShareFromSelf |
|
|
|
$user = $this->createMock(IUser::class); |
|
|
|
$group = $this->getMockBuilder('OCP\IGroup')->getMock(); |
|
|
|
$this->groupManager |
|
|
|
->method('get') |
|
|
|
->with('group') |
|
|
|
->willReturn($group); |
|
|
|
$this->userManager |
|
|
|
->method('get') |
|
|
|
->with($this->currentUser) |
|
|
|
->willReturn($user); |
|
|
|
$group->method('inGroup') |
|
|
|
->with($user) |
|
|
|
->willReturn(false); |
|
|
|
|
|
|
|
$node->expects($this->once()) |
|
|
|
->method('lock') |
|
|
|
->with(\OCP\Lock\ILockingProvider::LOCK_SHARED); |
|
|
|
|
|
|
|
$this->shareManager->expects($this->never()) |
|
|
|
->method('deleteFromSelf'); |
|
|
|
|
|
|
|
$this->shareManager->expects($this->never()) |
|
|
|
->method('deleteShare'); |
|
|
|
|
|
|
|
$this->assertFalse($this->invokePrivate($this->ocs, 'canDeleteShareFromSelf', [$share])); |
|
|
|
$this->assertFalse($this->invokePrivate($this->ocs, 'canDeleteShare', [$share])); |
|
|
|
|
|
|
|
$this->ocs->deleteShare(42); |
|
|
|
} |