summaryrefslogtreecommitdiffstats
path: root/apps/dav/tests/unit/Connector/Sabre/PrincipalTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'apps/dav/tests/unit/Connector/Sabre/PrincipalTest.php')
-rw-r--r--apps/dav/tests/unit/Connector/Sabre/PrincipalTest.php154
1 files changed, 138 insertions, 16 deletions
diff --git a/apps/dav/tests/unit/Connector/Sabre/PrincipalTest.php b/apps/dav/tests/unit/Connector/Sabre/PrincipalTest.php
index 225189e7d01..2a5c122ce9e 100644
--- a/apps/dav/tests/unit/Connector/Sabre/PrincipalTest.php
+++ b/apps/dav/tests/unit/Connector/Sabre/PrincipalTest.php
@@ -29,6 +29,8 @@
namespace OCA\DAV\Tests\unit\Connector\Sabre;
use OC\User\User;
+use OCA\DAV\CalDAV\Proxy\Proxy;
+use OCA\DAV\CalDAV\Proxy\ProxyMapper;
use OCP\App\IAppManager;
use OCP\IConfig;
use OCP\IGroup;
@@ -57,27 +59,27 @@ class PrincipalTest extends TestCase {
/** @var IUserSession | \PHPUnit_Framework_MockObject_MockObject */
private $userSession;
- /** @var IConfig | \PHPUnit_Framework_MockObject_MockObject */
- private $config;
-
/** @var IAppManager | \PHPUnit_Framework_MockObject_MockObject */
private $appManager;
+ /** @var ProxyMapper | \PHPUnit_Framework_MockObject_MockObject */
+ private $proxyMapper;
+
public function setUp() {
$this->userManager = $this->createMock(IUserManager::class);
$this->groupManager = $this->createMock(IGroupManager::class);
$this->shareManager = $this->createMock(IManager::class);
$this->userSession = $this->createMock(IUserSession::class);
- $this->config = $this->createMock(IConfig::class);
$this->appManager = $this->createMock(IAppManager::class);
+ $this->proxyMapper = $this->createMock(ProxyMapper::class);
$this->connector = new \OCA\DAV\Connector\Sabre\Principal(
$this->userManager,
$this->groupManager,
$this->shareManager,
$this->userSession,
- $this->config,
- $this->appManager
+ $this->appManager,
+ $this->proxyMapper
);
parent::setUp();
}
@@ -203,6 +205,25 @@ class PrincipalTest extends TestCase {
}
public function testGetGroupMemberSet() {
+ $response = $this->connector->getGroupMemberSet('principals/users/foo');
+ $this->assertSame([], $response);
+ }
+
+ /**
+ * @expectedException \Sabre\DAV\Exception
+ * @expectedExceptionMessage Principal not found
+ */
+ public function testGetGroupMemberSetEmpty() {
+ $this->userManager
+ ->expects($this->once())
+ ->method('get')
+ ->with('foo')
+ ->will($this->returnValue(null));
+
+ $this->connector->getGroupMemberSet('principals/users/foo/calendar-proxy-read');
+ }
+
+ public function testGetGroupMemberSetProxyRead() {
$fooUser = $this->createMock(User::class);
$fooUser
->expects($this->exactly(1))
@@ -214,22 +235,56 @@ class PrincipalTest extends TestCase {
->with('foo')
->will($this->returnValue($fooUser));
- $response = $this->connector->getGroupMemberSet('principals/users/foo');
- $this->assertSame(['principals/users/foo'], $response);
+ $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('principals/users/foo')
+ ->willReturn([$proxy1, $proxy2, $proxy3]);
+
+ $this->assertEquals(['proxyId1'], $this->connector->getGroupMemberSet('principals/users/foo/calendar-proxy-read'));
}
- /**
- * @expectedException \Sabre\DAV\Exception
- * @expectedExceptionMessage Principal not found
- */
- public function testGetGroupMemberSetEmpty() {
+ public function testGetGroupMemberSetProxyWrite() {
+ $fooUser = $this->createMock(User::class);
+ $fooUser
+ ->expects($this->exactly(1))
+ ->method('getUID')
+ ->will($this->returnValue('foo'));
$this->userManager
->expects($this->once())
->method('get')
->with('foo')
- ->will($this->returnValue(null));
+ ->will($this->returnValue($fooUser));
+
+ $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->connector->getGroupMemberSet('principals/users/foo');
+ $this->proxyMapper->expects($this->once())
+ ->method('getProxiesOf')
+ ->with('principals/users/foo')
+ ->willReturn([$proxy1, $proxy2, $proxy3]);
+
+ $this->assertEquals(['proxyId2', 'proxyId3'], $this->connector->getGroupMemberSet('principals/users/foo/calendar-proxy-write'));
}
public function testGetGroupMembership() {
@@ -243,7 +298,7 @@ class PrincipalTest extends TestCase {
->method('getGID')
->willReturn('foo/bar');
$this->userManager
- ->expects($this->once())
+ ->expects($this->exactly(2))
->method('get')
->with('foo')
->willReturn($fooUser);
@@ -256,9 +311,24 @@ class PrincipalTest extends TestCase {
$group2,
]);
+ $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('principals/users/foo')
+ ->willReturn([$proxy1, $proxy2]);
+
$expectedResponse = [
'principals/groups/group1',
'principals/groups/foo%2Fbar',
+ 'proxyId1/calendar-proxy-read',
+ 'proxyId2/calendar-proxy-write',
];
$response = $this->connector->getGroupMembership('principals/users/foo');
$this->assertSame($expectedResponse, $response);
@@ -286,6 +356,58 @@ class PrincipalTest extends TestCase {
$this->connector->setGroupMemberSet('principals/users/foo', ['foo']);
}
+ public function testSetGroupMembershipProxy() {
+ $fooUser = $this->createMock(User::class);
+ $fooUser
+ ->expects($this->exactly(1))
+ ->method('getUID')
+ ->will($this->returnValue('foo'));
+ $barUser = $this->createMock(User::class);
+ $barUser
+ ->expects($this->exactly(1))
+ ->method('getUID')
+ ->will($this->returnValue('bar'));
+ $this->userManager
+ ->expects($this->at(0))
+ ->method('get')
+ ->with('foo')
+ ->will($this->returnValue($fooUser));
+ $this->userManager
+ ->expects($this->at(1))
+ ->method('get')
+ ->with('bar')
+ ->will($this->returnValue($barUser));
+
+ $this->proxyMapper->expects($this->at(0))
+ ->method('getProxiesOf')
+ ->with('principals/users/foo')
+ ->willReturn([]);
+
+ $this->proxyMapper->expects($this->at(1))
+ ->method('insert')
+ ->with($this->callback(function($proxy) {
+ /** @var Proxy $proxy */
+ if ($proxy->getOwnerId() !== 'principals/users/foo') {
+ return false;
+ }
+ if ($proxy->getProxyId() !== 'principals/users/bar') {
+ return false;
+ }
+ if ($proxy->getPermissions() !== 3) {
+ return false;
+ }
+
+ return true;
+ }));
+
+ $this->connector->setGroupMemberSet('principals/users/foo/calendar-proxy-write', ['principals/users/bar']);
+ }
+
+
+
+
+
+
public function testUpdatePrincipal() {
$this->assertSame(0, $this->connector->updatePrincipal('foo', new PropPatch(array())));
}