summaryrefslogtreecommitdiffstats
path: root/apps/dav/tests/unit/CalDAV
diff options
context:
space:
mode:
authorRoeland Jago Douma <rullzer@users.noreply.github.com>2019-08-15 19:30:45 +0200
committerGitHub <noreply@github.com>2019-08-15 19:30:45 +0200
commitf452e23a7db1742afa50eaa80b746afe769bdf7b (patch)
treecf23e344e4bf5e094830d6c778be78360bded885 /apps/dav/tests/unit/CalDAV
parent465e919de12a8f6bdcf1133a677101c4cdf1efc2 (diff)
parent63d584afb5727737fe73a0ca2ecf720022b33922 (diff)
downloadnextcloud-server-f452e23a7db1742afa50eaa80b746afe769bdf7b.tar.gz
nextcloud-server-f452e23a7db1742afa50eaa80b746afe769bdf7b.zip
Merge pull request #16666 from nextcloud/feature/calendar/delegation
Feature/calendar/delegation
Diffstat (limited to 'apps/dav/tests/unit/CalDAV')
-rw-r--r--apps/dav/tests/unit/CalDAV/AbstractCalDavBackend.php3
-rw-r--r--apps/dav/tests/unit/CalDAV/CalendarTest.php37
-rw-r--r--apps/dav/tests/unit/CalDAV/ResourceBooking/AbstractPrincipalBackendTest.php114
-rw-r--r--apps/dav/tests/unit/CalDAV/ResourceBooking/ResourcePrincipalBackendTest.php2
-rw-r--r--apps/dav/tests/unit/CalDAV/ResourceBooking/RoomPrincipalBackendTest.php2
5 files changed, 140 insertions, 18 deletions
diff --git a/apps/dav/tests/unit/CalDAV/AbstractCalDavBackend.php b/apps/dav/tests/unit/CalDAV/AbstractCalDavBackend.php
index 795a04e2cbf..9f9a7c01337 100644
--- a/apps/dav/tests/unit/CalDAV/AbstractCalDavBackend.php
+++ b/apps/dav/tests/unit/CalDAV/AbstractCalDavBackend.php
@@ -26,6 +26,7 @@
namespace OCA\DAV\Tests\unit\CalDAV;
use OCA\DAV\CalDAV\CalDavBackend;
+use OCA\DAV\CalDAV\Proxy\ProxyMapper;
use OCA\DAV\Connector\Sabre\Principal;
use OCP\App\IAppManager;
use OCP\IConfig;
@@ -83,8 +84,8 @@ abstract class AbstractCalDavBackend extends TestCase {
$this->groupManager,
$this->createMock(ShareManager::class),
$this->createMock(IUserSession::class),
- $this->createMock(IConfig::class),
$this->createMock(IAppManager::class),
+ $this->createMock(ProxyMapper::class),
])
->setMethods(['getPrincipalByPath', 'getGroupMembership'])
->getMock();
diff --git a/apps/dav/tests/unit/CalDAV/CalendarTest.php b/apps/dav/tests/unit/CalDAV/CalendarTest.php
index f467d46bf60..7ce43f40916 100644
--- a/apps/dav/tests/unit/CalDAV/CalendarTest.php
+++ b/apps/dav/tests/unit/CalDAV/CalendarTest.php
@@ -213,21 +213,44 @@ class CalendarTest extends TestCase {
'principal' => $hasOwnerSet ? 'user1' : 'user2',
'protected' => true
], [
- 'privilege' => '{DAV:}write',
- 'principal' => $hasOwnerSet ? 'user1' : 'user2',
- 'protected' => true
+ 'privilege' => '{DAV:}read',
+ 'principal' => ($hasOwnerSet ? 'user1' : 'user2') . '/calendar-proxy-write',
+ 'protected' => true,
+ ], [
+ 'privilege' => '{DAV:}read',
+ 'principal' => ($hasOwnerSet ? 'user1' : 'user2') . '/calendar-proxy-read',
+ 'protected' => true,
]];
if ($uri === BirthdayService::BIRTHDAY_CALENDAR_URI) {
- $expectedAcl = [[
- 'privilege' => '{DAV:}read',
+ $expectedAcl[] = [
+ 'privilege' => '{DAV:}write-properties',
'principal' => $hasOwnerSet ? 'user1' : 'user2',
'protected' => true
- ], [
+ ];
+ $expectedAcl[] = [
'privilege' => '{DAV:}write-properties',
+ 'principal' => ($hasOwnerSet ? 'user1' : 'user2') . '/calendar-proxy-write',
+ 'protected' => true
+ ];
+ } else {
+ $expectedAcl[] = [
+ 'privilege' => '{DAV:}write',
'principal' => $hasOwnerSet ? 'user1' : 'user2',
'protected' => true
- ]];
+ ];
+ $expectedAcl[] = [
+ 'privilege' => '{DAV:}write',
+ 'principal' => ($hasOwnerSet ? 'user1' : 'user2') . '/calendar-proxy-write',
+ 'protected' => true
+ ];
}
+
+ $expectedAcl[] = [
+ 'privilege' => '{DAV:}write-properties',
+ 'principal' => ($hasOwnerSet ? 'user1' : 'user2') . '/calendar-proxy-read',
+ 'protected' => true
+ ];
+
if ($hasOwnerSet) {
$expectedAcl[] = [
'privilege' => '{DAV:}read',
diff --git a/apps/dav/tests/unit/CalDAV/ResourceBooking/AbstractPrincipalBackendTest.php b/apps/dav/tests/unit/CalDAV/ResourceBooking/AbstractPrincipalBackendTest.php
index f4019d86e2b..c6e16e2c484 100644
--- a/apps/dav/tests/unit/CalDAV/ResourceBooking/AbstractPrincipalBackendTest.php
+++ b/apps/dav/tests/unit/CalDAV/ResourceBooking/AbstractPrincipalBackendTest.php
@@ -21,6 +21,8 @@
*/
namespace OCA\DAV\Tests\unit\CalDAV\ResourceBooking;
+use OCA\DAV\CalDAV\Proxy\Proxy;
+use OCA\DAV\CalDAV\Proxy\ProxyMapper;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IGroupManager;
use OCP\ILogger;
@@ -43,6 +45,9 @@ abstract class AbstractPrincipalBackendTest extends TestCase {
/** @var ILogger|\PHPUnit_Framework_MockObject_MockObject */
protected $logger;
+ /** @var ProxyMapper|\PHPUnit_Framework_MockObject_MockObject */
+ protected $proxyMapper;
+
/** @var string */
protected $mainDbTable;
@@ -64,6 +69,7 @@ abstract class AbstractPrincipalBackendTest extends TestCase {
$this->userSession = $this->createMock(IUserSession::class);
$this->groupManager = $this->createMock(IGroupManager::class);
$this->logger = $this->createMock(ILogger::class);
+ $this->proxyMapper = $this->createMock(ProxyMapper::class);
}
protected function tearDown() {
@@ -152,21 +158,113 @@ abstract class AbstractPrincipalBackendTest extends TestCase {
}
public function testGetGroupMemberSet() {
- $actual = $this->principalBackend->getGroupMemberSet($this->principalPrefix . '/foo-bar');
+ $actual = $this->principalBackend->getGroupMemberSet($this->principalPrefix . '/backend1-res1');
$this->assertEquals([], $actual);
}
+ public function testGetGroupMemberSetProxyRead() {
+ $proxy1 = new Proxy();
+ $proxy1->setProxyId('proxyId1');
+ $proxy1->setPermissions(1);
+
+ $proxy2 = new Proxy();
+ $proxy2->setProxyId('proxyId2');
+ $proxy2->setPermissions(3);
+
+ $proxy3 = new Proxy();
+ $proxy3->setProxyId('proxyId3');
+ $proxy3->setPermissions(3);
+
+ $this->proxyMapper->expects($this->once())
+ ->method('getProxiesOf')
+ ->with($this->principalPrefix . '/backend1-res1')
+ ->willReturn([$proxy1, $proxy2, $proxy3]);
+
+ $actual = $this->principalBackend->getGroupMemberSet($this->principalPrefix . '/backend1-res1/calendar-proxy-read');
+ $this->assertEquals(['proxyId1'], $actual);
+ }
+
+ public function testGetGroupMemberSetProxyWrite() {
+ $proxy1 = new Proxy();
+ $proxy1->setProxyId('proxyId1');
+ $proxy1->setPermissions(1);
+
+ $proxy2 = new Proxy();
+ $proxy2->setProxyId('proxyId2');
+ $proxy2->setPermissions(3);
+
+ $proxy3 = new Proxy();
+ $proxy3->setProxyId('proxyId3');
+ $proxy3->setPermissions(3);
+
+ $this->proxyMapper->expects($this->once())
+ ->method('getProxiesOf')
+ ->with($this->principalPrefix . '/backend1-res1')
+ ->willReturn([$proxy1, $proxy2, $proxy3]);
+
+ $actual = $this->principalBackend->getGroupMemberSet($this->principalPrefix . '/backend1-res1/calendar-proxy-write');
+ $this->assertEquals(['proxyId2', 'proxyId3'], $actual);
+ }
+
public function testGetGroupMembership() {
- $actual = $this->principalBackend->getGroupMembership($this->principalPrefix . '/foo-bar');
- $this->assertEquals([], $actual);
+ $proxy1 = new Proxy();
+ $proxy1->setOwnerId('proxyId1');
+ $proxy1->setPermissions(1);
+
+ $proxy2 = new Proxy();
+ $proxy2->setOwnerId('proxyId2');
+ $proxy2->setPermissions(3);
+
+ $this->proxyMapper->expects($this->once())
+ ->method('getProxiesFor')
+ ->with($this->principalPrefix . '/backend1-res1')
+ ->willReturn([$proxy1, $proxy2]);
+
+ $actual = $this->principalBackend->getGroupMembership($this->principalPrefix . '/backend1-res1');
+
+ $this->assertEquals(['proxyId1/calendar-proxy-read', 'proxyId2/calendar-proxy-write'], $actual);
}
- /**
- * @expectedException \Sabre\DAV\Exception
- * @expectedExceptionMessage Setting members of the group is not supported yet
- */
public function testSetGroupMemberSet() {
- $this->principalBackend->setGroupMemberSet($this->principalPrefix . '/foo-bar', ['foo', 'bar']);
+ $this->proxyMapper->expects($this->at(0))
+ ->method('getProxiesOf')
+ ->with($this->principalPrefix . '/backend1-res1')
+ ->willReturn([]);
+
+ $this->proxyMapper->expects($this->at(1))
+ ->method('insert')
+ ->with($this->callback(function($proxy) {
+ /** @var Proxy $proxy */
+ if ($proxy->getOwnerId() !== $this->principalPrefix . '/backend1-res1') {
+ return false;
+ }
+ if ($proxy->getProxyId() !== $this->principalPrefix . '/backend1-res2') {
+ return false;
+ }
+ if ($proxy->getPermissions() !== 3) {
+ return false;
+ }
+
+ return true;
+ }));
+ $this->proxyMapper->expects($this->at(2))
+ ->method('insert')
+ ->with($this->callback(function($proxy) {
+ /** @var Proxy $proxy */
+ if ($proxy->getOwnerId() !== $this->principalPrefix . '/backend1-res1') {
+ return false;
+ }
+ if ($proxy->getProxyId() !== $this->principalPrefix . '/backend2-res3') {
+ return false;
+ }
+ if ($proxy->getPermissions() !== 3) {
+ return false;
+ }
+
+ return true;
+ }));
+
+ $this->principalBackend->setGroupMemberSet($this->principalPrefix . '/backend1-res1/calendar-proxy-write', [$this->principalPrefix . '/backend1-res2', $this->principalPrefix . '/backend2-res3']);
}
public function testUpdatePrincipal() {
diff --git a/apps/dav/tests/unit/CalDAV/ResourceBooking/ResourcePrincipalBackendTest.php b/apps/dav/tests/unit/CalDAV/ResourceBooking/ResourcePrincipalBackendTest.php
index 3787e4df951..461246dd51d 100644
--- a/apps/dav/tests/unit/CalDAV/ResourceBooking/ResourcePrincipalBackendTest.php
+++ b/apps/dav/tests/unit/CalDAV/ResourceBooking/ResourcePrincipalBackendTest.php
@@ -28,7 +28,7 @@ Class ResourcePrincipalBackendTest extends AbstractPrincipalBackendTest {
parent::setUp();
$this->principalBackend = new ResourcePrincipalBackend(self::$realDatabase,
- $this->userSession, $this->groupManager, $this->logger);
+ $this->userSession, $this->groupManager, $this->logger, $this->proxyMapper);
$this->mainDbTable = 'calendar_resources';
$this->metadataDbTable = 'calendar_resources_md';
diff --git a/apps/dav/tests/unit/CalDAV/ResourceBooking/RoomPrincipalBackendTest.php b/apps/dav/tests/unit/CalDAV/ResourceBooking/RoomPrincipalBackendTest.php
index 9b259c30adf..6b691400cd1 100644
--- a/apps/dav/tests/unit/CalDAV/ResourceBooking/RoomPrincipalBackendTest.php
+++ b/apps/dav/tests/unit/CalDAV/ResourceBooking/RoomPrincipalBackendTest.php
@@ -28,7 +28,7 @@ Class RoomPrincipalBackendTest extends AbstractPrincipalBackendTest {
parent::setUp();
$this->principalBackend = new RoomPrincipalBackend(self::$realDatabase,
- $this->userSession, $this->groupManager, $this->logger);
+ $this->userSession, $this->groupManager, $this->logger, $this->proxyMapper);
$this->mainDbTable = 'calendar_rooms';
$this->metadataDbTable = 'calendar_rooms_md';