2018-06-05 22:26:29 +03:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @copyright Copyright (c) 2018, Georg Ehrke
|
|
|
|
*
|
|
|
|
* @author Georg Ehrke <oc.list@georgehrke.com>
|
|
|
|
*
|
|
|
|
* @license AGPL-3.0
|
|
|
|
*
|
|
|
|
* This code is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License, version 3,
|
|
|
|
* as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3,
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
|
|
|
*
|
|
|
|
*/
|
2019-11-22 22:52:10 +03:00
|
|
|
|
2018-06-05 22:26:29 +03:00
|
|
|
namespace OCA\DAV\Tests\unit\CalDAV\ResourceBooking;
|
|
|
|
|
2019-08-14 14:38:11 +03:00
|
|
|
use OCA\DAV\CalDAV\Proxy\Proxy;
|
|
|
|
use OCA\DAV\CalDAV\Proxy\ProxyMapper;
|
2018-06-05 22:26:29 +03:00
|
|
|
use OCP\DB\QueryBuilder\IQueryBuilder;
|
|
|
|
use OCP\IGroupManager;
|
|
|
|
use OCP\ILogger;
|
|
|
|
use OCP\IUser;
|
|
|
|
use OCP\IUserSession;
|
|
|
|
use Sabre\DAV\PropPatch;
|
|
|
|
use Test\TestCase;
|
|
|
|
|
|
|
|
abstract class AbstractPrincipalBackendTest extends TestCase {
|
|
|
|
|
|
|
|
/** @var \OCA\DAV\CalDAV\ResourceBooking\ResourcePrincipalBackend|\OCA\DAV\CalDAV\ResourceBooking\RoomPrincipalBackend */
|
|
|
|
protected $principalBackend;
|
|
|
|
|
|
|
|
/** @var IUserSession|\PHPUnit_Framework_MockObject_MockObject */
|
|
|
|
protected $userSession;
|
|
|
|
|
|
|
|
/** @var IGroupManager|\PHPUnit_Framework_MockObject_MockObject */
|
|
|
|
protected $groupManager;
|
|
|
|
|
|
|
|
/** @var ILogger|\PHPUnit_Framework_MockObject_MockObject */
|
|
|
|
protected $logger;
|
|
|
|
|
2019-08-14 14:38:11 +03:00
|
|
|
/** @var ProxyMapper|\PHPUnit_Framework_MockObject_MockObject */
|
|
|
|
protected $proxyMapper;
|
|
|
|
|
2018-06-05 22:26:29 +03:00
|
|
|
/** @var string */
|
2019-08-01 16:05:53 +03:00
|
|
|
protected $mainDbTable;
|
|
|
|
|
|
|
|
/** @var string */
|
|
|
|
protected $metadataDbTable;
|
|
|
|
|
|
|
|
/** @var string */
|
|
|
|
protected $foreignKey;
|
2018-06-05 22:26:29 +03:00
|
|
|
|
|
|
|
/** @var string */
|
|
|
|
protected $principalPrefix;
|
|
|
|
|
2018-10-16 15:39:04 +03:00
|
|
|
/** @var string */
|
|
|
|
protected $expectedCUType;
|
|
|
|
|
2019-11-27 17:27:18 +03:00
|
|
|
protected function setUp(): void {
|
2018-06-05 22:26:29 +03:00
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
$this->userSession = $this->createMock(IUserSession::class);
|
|
|
|
$this->groupManager = $this->createMock(IGroupManager::class);
|
|
|
|
$this->logger = $this->createMock(ILogger::class);
|
2019-08-14 14:38:11 +03:00
|
|
|
$this->proxyMapper = $this->createMock(ProxyMapper::class);
|
2018-06-05 22:26:29 +03:00
|
|
|
}
|
|
|
|
|
2019-11-21 18:40:38 +03:00
|
|
|
protected function tearDown(): void {
|
2019-08-01 16:05:53 +03:00
|
|
|
$query = self::$realDatabase->getQueryBuilder();
|
2018-06-05 22:26:29 +03:00
|
|
|
|
2019-08-01 16:05:53 +03:00
|
|
|
$query->delete('calendar_resources')->execute();
|
|
|
|
$query->delete('calendar_resources_md')->execute();
|
|
|
|
$query->delete('calendar_rooms')->execute();
|
|
|
|
$query->delete('calendar_rooms_md')->execute();
|
|
|
|
}
|
2018-06-05 22:26:29 +03:00
|
|
|
|
2019-08-01 16:05:53 +03:00
|
|
|
public function testGetPrincipalsByPrefix() {
|
2018-06-05 22:26:29 +03:00
|
|
|
$actual = $this->principalBackend->getPrincipalsByPrefix($this->principalPrefix);
|
2019-08-01 16:05:53 +03:00
|
|
|
|
2018-06-05 22:26:29 +03:00
|
|
|
$this->assertEquals([
|
|
|
|
[
|
2019-08-01 16:05:53 +03:00
|
|
|
'uri' => $this->principalPrefix . '/backend1-res1',
|
|
|
|
'{DAV:}displayname' => 'Beamer1',
|
|
|
|
'{http://sabredav.org/ns}email-address' => 'res1@foo.bar',
|
2018-10-16 15:39:04 +03:00
|
|
|
'{urn:ietf:params:xml:ns:caldav}calendar-user-type' => $this->expectedCUType,
|
2018-06-05 22:26:29 +03:00
|
|
|
],
|
|
|
|
[
|
2019-08-01 16:05:53 +03:00
|
|
|
'uri' => $this->principalPrefix . '/backend1-res2',
|
|
|
|
'{DAV:}displayname' => 'TV1',
|
|
|
|
'{http://sabredav.org/ns}email-address' => 'res2@foo.bar',
|
2018-10-16 15:39:04 +03:00
|
|
|
'{urn:ietf:params:xml:ns:caldav}calendar-user-type' => $this->expectedCUType,
|
2018-06-05 22:26:29 +03:00
|
|
|
],
|
|
|
|
[
|
2019-08-01 16:05:53 +03:00
|
|
|
'uri' => $this->principalPrefix . '/backend2-res3',
|
|
|
|
'{DAV:}displayname' => 'Beamer2',
|
|
|
|
'{http://sabredav.org/ns}email-address' => 'res3@foo.bar',
|
2018-10-16 15:39:04 +03:00
|
|
|
'{urn:ietf:params:xml:ns:caldav}calendar-user-type' => $this->expectedCUType,
|
2019-08-01 16:05:53 +03:00
|
|
|
'{http://nextcloud.com/ns}foo' => 'value1',
|
|
|
|
'{http://nextcloud.com/ns}meta2' => 'value2',
|
2018-06-05 22:26:29 +03:00
|
|
|
],
|
2019-08-01 16:05:53 +03:00
|
|
|
[
|
|
|
|
'uri' => $this->principalPrefix . '/backend2-res4',
|
|
|
|
'{DAV:}displayname' => 'TV2',
|
|
|
|
'{http://sabredav.org/ns}email-address' => 'res4@foo.bar',
|
|
|
|
'{urn:ietf:params:xml:ns:caldav}calendar-user-type' => $this->expectedCUType,
|
|
|
|
'{http://nextcloud.com/ns}meta1' => 'value1',
|
|
|
|
'{http://nextcloud.com/ns}meta3' => 'value3-old',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'uri' => $this->principalPrefix . '/backend3-res5',
|
|
|
|
'{DAV:}displayname' => 'Beamer3',
|
|
|
|
'{http://sabredav.org/ns}email-address' => 'res5@foo.bar',
|
|
|
|
'{urn:ietf:params:xml:ns:caldav}calendar-user-type' => $this->expectedCUType,
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'uri' => $this->principalPrefix . '/backend3-res6',
|
|
|
|
'{DAV:}displayname' => 'Pointer',
|
|
|
|
'{http://sabredav.org/ns}email-address' => 'res6@foo.bar',
|
|
|
|
'{urn:ietf:params:xml:ns:caldav}calendar-user-type' => $this->expectedCUType,
|
|
|
|
'{http://nextcloud.com/ns}meta99' => 'value99'
|
|
|
|
]
|
2018-06-05 22:26:29 +03:00
|
|
|
], $actual);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetNoPrincipalsByPrefixForWrongPrincipalPrefix() {
|
|
|
|
$actual = $this->principalBackend->getPrincipalsByPrefix('principals/users');
|
|
|
|
$this->assertEquals([], $actual);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetPrincipalByPath() {
|
2019-08-01 16:05:53 +03:00
|
|
|
$actual = $this->principalBackend->getPrincipalByPath($this->principalPrefix . '/backend2-res3');
|
2018-06-05 22:26:29 +03:00
|
|
|
$this->assertEquals([
|
2019-08-01 16:05:53 +03:00
|
|
|
'uri' => $this->principalPrefix . '/backend2-res3',
|
|
|
|
'{DAV:}displayname' => 'Beamer2',
|
|
|
|
'{http://sabredav.org/ns}email-address' => 'res3@foo.bar',
|
2018-10-16 15:39:04 +03:00
|
|
|
'{urn:ietf:params:xml:ns:caldav}calendar-user-type' => $this->expectedCUType,
|
2019-08-01 16:05:53 +03:00
|
|
|
'{http://nextcloud.com/ns}foo' => 'value1',
|
|
|
|
'{http://nextcloud.com/ns}meta2' => 'value2',
|
2018-06-05 22:26:29 +03:00
|
|
|
], $actual);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetPrincipalByPathNotFound() {
|
|
|
|
$actual = $this->principalBackend->getPrincipalByPath($this->principalPrefix . '/db-123');
|
|
|
|
$this->assertEquals(null, $actual);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetPrincipalByPathWrongPrefix() {
|
|
|
|
$actual = $this->principalBackend->getPrincipalByPath('principals/users/foo-bar');
|
|
|
|
$this->assertEquals(null, $actual);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetGroupMemberSet() {
|
2019-08-14 14:38:11 +03:00
|
|
|
$actual = $this->principalBackend->getGroupMemberSet($this->principalPrefix . '/backend1-res1');
|
2018-06-05 22:26:29 +03:00
|
|
|
$this->assertEquals([], $actual);
|
|
|
|
}
|
|
|
|
|
2019-08-14 14:38:11 +03:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2018-06-05 22:26:29 +03:00
|
|
|
public function testGetGroupMembership() {
|
2019-08-14 14:38:11 +03:00
|
|
|
$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);
|
2018-06-05 22:26:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testSetGroupMemberSet() {
|
2019-08-14 14:38:11 +03:00
|
|
|
$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']);
|
2018-06-05 22:26:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testUpdatePrincipal() {
|
|
|
|
$propPatch = $this->createMock(PropPatch::class);
|
|
|
|
$actual = $this->principalBackend->updatePrincipal($this->principalPrefix . '/foo-bar', $propPatch);
|
|
|
|
|
|
|
|
$this->assertEquals(0, $actual);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider dataSearchPrincipals
|
|
|
|
*/
|
|
|
|
public function testSearchPrincipals($expected, $test) {
|
|
|
|
$user = $this->createMock(IUser::class);
|
|
|
|
$this->userSession->expects($this->once())
|
|
|
|
->method('getUser')
|
|
|
|
->with()
|
|
|
|
->will($this->returnValue($user));
|
|
|
|
$this->groupManager->expects($this->once())
|
|
|
|
->method('getUserGroupIds')
|
|
|
|
->with($user)
|
|
|
|
->will($this->returnValue(['group1', 'group2']));
|
|
|
|
|
|
|
|
$actual = $this->principalBackend->searchPrincipals($this->principalPrefix, [
|
|
|
|
'{http://sabredav.org/ns}email-address' => 'foo',
|
2019-08-01 16:05:53 +03:00
|
|
|
'{DAV:}displayname' => 'Beamer',
|
2018-06-05 22:26:29 +03:00
|
|
|
], $test);
|
|
|
|
|
|
|
|
$this->assertEquals(
|
|
|
|
str_replace('%prefix%', $this->principalPrefix, $expected),
|
|
|
|
$actual);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function dataSearchPrincipals() {
|
|
|
|
// data providers are called before we subclass
|
|
|
|
// this class, $this->principalPrefix is null
|
|
|
|
// at that point, so we need this hack
|
|
|
|
return [
|
|
|
|
[[
|
2019-08-01 16:05:53 +03:00
|
|
|
'%prefix%/backend1-res1',
|
|
|
|
'%prefix%/backend2-res3',
|
2018-06-05 22:26:29 +03:00
|
|
|
], 'allof'],
|
|
|
|
[[
|
2019-08-01 16:05:53 +03:00
|
|
|
'%prefix%/backend1-res1',
|
|
|
|
'%prefix%/backend1-res2',
|
|
|
|
'%prefix%/backend2-res3',
|
|
|
|
'%prefix%/backend2-res4',
|
|
|
|
'%prefix%/backend3-res6',
|
2018-06-05 22:26:29 +03:00
|
|
|
], 'anyof'],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2019-08-01 19:37:50 +03:00
|
|
|
public function testSearchPrincipalsByMetadataKey() {
|
|
|
|
$user = $this->createMock(IUser::class);
|
|
|
|
$this->userSession->expects($this->once())
|
|
|
|
->method('getUser')
|
|
|
|
->with()
|
|
|
|
->will($this->returnValue($user));
|
|
|
|
$this->groupManager->expects($this->once())
|
|
|
|
->method('getUserGroupIds')
|
|
|
|
->with($user)
|
|
|
|
->will($this->returnValue(['group1', 'group2']));
|
|
|
|
|
|
|
|
$actual = $this->principalBackend->searchPrincipals($this->principalPrefix, [
|
|
|
|
'{http://nextcloud.com/ns}meta3' => 'value',
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals([
|
|
|
|
$this->principalPrefix . '/backend2-res4',
|
|
|
|
], $actual);
|
|
|
|
}
|
|
|
|
|
2019-02-20 22:22:56 +03:00
|
|
|
public function testSearchPrincipalsByCalendarUserAddressSet() {
|
|
|
|
$user = $this->createMock(IUser::class);
|
2019-08-01 16:05:53 +03:00
|
|
|
$this->userSession->method('getUser')
|
2019-02-20 22:22:56 +03:00
|
|
|
->with()
|
|
|
|
->will($this->returnValue($user));
|
2019-08-01 16:05:53 +03:00
|
|
|
$this->groupManager->method('getUserGroupIds')
|
2019-02-20 22:22:56 +03:00
|
|
|
->with($user)
|
|
|
|
->will($this->returnValue(['group1', 'group2']));
|
|
|
|
|
|
|
|
$actual = $this->principalBackend->searchPrincipals($this->principalPrefix, [
|
2019-08-01 16:05:53 +03:00
|
|
|
'{urn:ietf:params:xml:ns:caldav}calendar-user-address-set' => 'res2@foo.bar',
|
2019-02-20 22:22:56 +03:00
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(
|
|
|
|
str_replace('%prefix%', $this->principalPrefix, [
|
2019-08-01 16:05:53 +03:00
|
|
|
'%prefix%/backend1-res2',
|
2019-02-20 22:22:56 +03:00
|
|
|
]),
|
|
|
|
$actual);
|
|
|
|
}
|
|
|
|
|
2018-06-05 22:26:29 +03:00
|
|
|
public function testSearchPrincipalsEmptySearchProperties() {
|
|
|
|
$this->userSession->expects($this->never())
|
|
|
|
->method('getUser');
|
|
|
|
$this->groupManager->expects($this->never())
|
|
|
|
->method('getUserGroupIds');
|
|
|
|
|
|
|
|
$this->principalBackend->searchPrincipals($this->principalPrefix, []);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testSearchPrincipalsWrongPrincipalPrefix() {
|
|
|
|
$this->userSession->expects($this->never())
|
|
|
|
->method('getUser');
|
|
|
|
$this->groupManager->expects($this->never())
|
|
|
|
->method('getUserGroupIds');
|
|
|
|
|
|
|
|
$this->principalBackend->searchPrincipals('principals/users', [
|
|
|
|
'{http://sabredav.org/ns}email-address' => 'foo'
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testFindByUriByEmail() {
|
|
|
|
$user = $this->createMock(IUser::class);
|
|
|
|
$this->userSession->expects($this->once())
|
|
|
|
->method('getUser')
|
|
|
|
->with()
|
|
|
|
->will($this->returnValue($user));
|
|
|
|
$this->groupManager->expects($this->once())
|
|
|
|
->method('getUserGroupIds')
|
|
|
|
->with($user)
|
|
|
|
->will($this->returnValue(['group1', 'group2']));
|
|
|
|
|
2019-08-01 16:05:53 +03:00
|
|
|
$actual = $this->principalBackend->findByUri('mailto:res1@foo.bar', $this->principalPrefix);
|
|
|
|
$this->assertEquals($this->principalPrefix . '/backend1-res1', $actual);
|
2018-06-05 22:26:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testFindByUriByEmailForbiddenResource() {
|
|
|
|
$user = $this->createMock(IUser::class);
|
|
|
|
$this->userSession->expects($this->once())
|
|
|
|
->method('getUser')
|
|
|
|
->with()
|
|
|
|
->will($this->returnValue($user));
|
|
|
|
$this->groupManager->expects($this->once())
|
|
|
|
->method('getUserGroupIds')
|
|
|
|
->with($user)
|
|
|
|
->will($this->returnValue(['group1', 'group2']));
|
|
|
|
|
2019-08-01 16:05:53 +03:00
|
|
|
$actual = $this->principalBackend->findByUri('mailto:res5@foo.bar', $this->principalPrefix);
|
2018-06-05 22:26:29 +03:00
|
|
|
$this->assertEquals(null, $actual);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testFindByUriByEmailNotFound() {
|
|
|
|
$user = $this->createMock(IUser::class);
|
|
|
|
$this->userSession->expects($this->once())
|
|
|
|
->method('getUser')
|
|
|
|
->with()
|
|
|
|
->will($this->returnValue($user));
|
|
|
|
$this->groupManager->expects($this->once())
|
|
|
|
->method('getUserGroupIds')
|
|
|
|
->with($user)
|
|
|
|
->will($this->returnValue(['group1', 'group2']));
|
|
|
|
|
2019-08-01 16:05:53 +03:00
|
|
|
$actual = $this->principalBackend->findByUri('mailto:res99@foo.bar', $this->principalPrefix);
|
2018-06-05 22:26:29 +03:00
|
|
|
$this->assertEquals(null, $actual);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testFindByUriByPrincipal() {
|
|
|
|
$user = $this->createMock(IUser::class);
|
|
|
|
$this->userSession->expects($this->once())
|
|
|
|
->method('getUser')
|
|
|
|
->with()
|
|
|
|
->will($this->returnValue($user));
|
|
|
|
$this->groupManager->expects($this->once())
|
|
|
|
->method('getUserGroupIds')
|
|
|
|
->with($user)
|
|
|
|
->will($this->returnValue(['group1', 'group2']));
|
|
|
|
|
2019-08-01 16:05:53 +03:00
|
|
|
$actual = $this->principalBackend->findByUri('mailto:res6@foo.bar', $this->principalPrefix);
|
|
|
|
$this->assertEquals($this->principalPrefix . '/backend3-res6', $actual);
|
2018-06-05 22:26:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testFindByUriByPrincipalForbiddenResource() {
|
|
|
|
$user = $this->createMock(IUser::class);
|
|
|
|
$this->userSession->expects($this->once())
|
|
|
|
->method('getUser')
|
|
|
|
->with()
|
|
|
|
->will($this->returnValue($user));
|
|
|
|
$this->groupManager->expects($this->once())
|
|
|
|
->method('getUserGroupIds')
|
|
|
|
->with($user)
|
|
|
|
->will($this->returnValue(['group1', 'group2']));
|
|
|
|
|
2019-08-01 16:05:53 +03:00
|
|
|
$actual = $this->principalBackend->findByUri('principal:' . $this->principalPrefix . '/backend3-res5', $this->principalPrefix);
|
2018-06-05 22:26:29 +03:00
|
|
|
$this->assertEquals(null, $actual);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testFindByUriByPrincipalNotFound() {
|
|
|
|
$user = $this->createMock(IUser::class);
|
|
|
|
$this->userSession->expects($this->once())
|
|
|
|
->method('getUser')
|
|
|
|
->with()
|
|
|
|
->will($this->returnValue($user));
|
|
|
|
$this->groupManager->expects($this->once())
|
|
|
|
->method('getUserGroupIds')
|
|
|
|
->with($user)
|
|
|
|
->will($this->returnValue(['group1', 'group2']));
|
|
|
|
|
|
|
|
$actual = $this->principalBackend->findByUri('principal:' . $this->principalPrefix . '/db-123', $this->principalPrefix);
|
|
|
|
$this->assertEquals(null, $actual);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testFindByUriByUnknownUri() {
|
|
|
|
$user = $this->createMock(IUser::class);
|
|
|
|
$this->userSession->expects($this->once())
|
|
|
|
->method('getUser')
|
|
|
|
->with()
|
|
|
|
->will($this->returnValue($user));
|
|
|
|
$this->groupManager->expects($this->once())
|
|
|
|
->method('getUserGroupIds')
|
|
|
|
->with($user)
|
|
|
|
->will($this->returnValue(['group1', 'group2']));
|
|
|
|
|
|
|
|
$actual = $this->principalBackend->findByUri('foobar:blub', $this->principalPrefix);
|
|
|
|
$this->assertEquals(null, $actual);
|
|
|
|
}
|
|
|
|
|
2019-08-01 16:05:53 +03:00
|
|
|
protected function createTestDatasetInDb() {
|
|
|
|
$query = self::$realDatabase->getQueryBuilder();
|
|
|
|
$query->insert($this->mainDbTable)
|
|
|
|
->values([
|
|
|
|
'backend_id' => $query->createNamedParameter('backend1'),
|
|
|
|
'resource_id' => $query->createNamedParameter('res1'),
|
|
|
|
'email' => $query->createNamedParameter('res1@foo.bar'),
|
|
|
|
'displayname' => $query->createNamedParameter('Beamer1'),
|
|
|
|
'group_restrictions' => $query->createNamedParameter('[]'),
|
|
|
|
])
|
|
|
|
->execute();
|
|
|
|
|
|
|
|
$query->insert($this->mainDbTable)
|
|
|
|
->values([
|
|
|
|
'backend_id' => $query->createNamedParameter('backend1'),
|
|
|
|
'resource_id' => $query->createNamedParameter('res2'),
|
|
|
|
'email' => $query->createNamedParameter('res2@foo.bar'),
|
|
|
|
'displayname' => $query->createNamedParameter('TV1'),
|
|
|
|
'group_restrictions' => $query->createNamedParameter('[]'),
|
|
|
|
])
|
|
|
|
->execute();
|
|
|
|
|
|
|
|
$query->insert($this->mainDbTable)
|
|
|
|
->values([
|
|
|
|
'backend_id' => $query->createNamedParameter('backend2'),
|
|
|
|
'resource_id' => $query->createNamedParameter('res3'),
|
|
|
|
'email' => $query->createNamedParameter('res3@foo.bar'),
|
|
|
|
'displayname' => $query->createNamedParameter('Beamer2'),
|
|
|
|
'group_restrictions' => $query->createNamedParameter('[]'),
|
|
|
|
])
|
|
|
|
->execute();
|
|
|
|
$id3 = $query->getLastInsertId();
|
|
|
|
|
|
|
|
$query->insert($this->mainDbTable)
|
|
|
|
->values([
|
|
|
|
'backend_id' => $query->createNamedParameter('backend2'),
|
|
|
|
'resource_id' => $query->createNamedParameter('res4'),
|
|
|
|
'email' => $query->createNamedParameter('res4@foo.bar'),
|
|
|
|
'displayname' => $query->createNamedParameter('TV2'),
|
|
|
|
'group_restrictions' => $query->createNamedParameter('[]'),
|
|
|
|
])
|
|
|
|
->execute();
|
|
|
|
$id4 = $query->getLastInsertId();
|
|
|
|
|
|
|
|
$query->insert($this->mainDbTable)
|
|
|
|
->values([
|
|
|
|
'backend_id' => $query->createNamedParameter('backend3'),
|
|
|
|
'resource_id' => $query->createNamedParameter('res5'),
|
|
|
|
'email' => $query->createNamedParameter('res5@foo.bar'),
|
|
|
|
'displayname' => $query->createNamedParameter('Beamer3'),
|
|
|
|
'group_restrictions' => $query->createNamedParameter('["foo", "bar"]'),
|
|
|
|
])
|
|
|
|
->execute();
|
|
|
|
|
|
|
|
$query->insert($this->mainDbTable)
|
|
|
|
->values([
|
|
|
|
'backend_id' => $query->createNamedParameter('backend3'),
|
|
|
|
'resource_id' => $query->createNamedParameter('res6'),
|
|
|
|
'email' => $query->createNamedParameter('res6@foo.bar'),
|
|
|
|
'displayname' => $query->createNamedParameter('Pointer'),
|
|
|
|
'group_restrictions' => $query->createNamedParameter('["group1", "bar"]'),
|
|
|
|
])
|
|
|
|
->execute();
|
|
|
|
$id6 = $query->getLastInsertId();
|
|
|
|
|
|
|
|
$query->insert($this->metadataDbTable)
|
|
|
|
->values([
|
|
|
|
$this->foreignKey => $query->createNamedParameter($id3),
|
|
|
|
'key' => $query->createNamedParameter('{http://nextcloud.com/ns}foo'),
|
|
|
|
'value' => $query->createNamedParameter('value1')
|
|
|
|
])
|
|
|
|
->execute();
|
|
|
|
$query->insert($this->metadataDbTable)
|
|
|
|
->values([
|
|
|
|
$this->foreignKey => $query->createNamedParameter($id3),
|
|
|
|
'key' => $query->createNamedParameter('{http://nextcloud.com/ns}meta2'),
|
|
|
|
'value' => $query->createNamedParameter('value2')
|
|
|
|
])
|
|
|
|
->execute();
|
|
|
|
$query->insert($this->metadataDbTable)
|
|
|
|
->values([
|
|
|
|
$this->foreignKey => $query->createNamedParameter($id4),
|
|
|
|
'key' => $query->createNamedParameter('{http://nextcloud.com/ns}meta1'),
|
|
|
|
'value' => $query->createNamedParameter('value1')
|
|
|
|
])
|
|
|
|
->execute();
|
|
|
|
$query->insert($this->metadataDbTable)
|
|
|
|
->values([
|
|
|
|
$this->foreignKey => $query->createNamedParameter($id4),
|
|
|
|
'key' => $query->createNamedParameter('{http://nextcloud.com/ns}meta3'),
|
|
|
|
'value' => $query->createNamedParameter('value3-old')
|
|
|
|
])
|
|
|
|
->execute();
|
|
|
|
$query->insert($this->metadataDbTable)
|
|
|
|
->values([
|
|
|
|
$this->foreignKey => $query->createNamedParameter($id6),
|
|
|
|
'key' => $query->createNamedParameter('{http://nextcloud.com/ns}meta99'),
|
|
|
|
'value' => $query->createNamedParameter('value99')
|
|
|
|
])
|
|
|
|
->execute();
|
|
|
|
}
|
|
|
|
|
2018-06-05 22:26:29 +03:00
|
|
|
}
|