2014-12-19 15:28:11 +03:00
|
|
|
<?php
|
|
|
|
/**
|
2016-07-21 17:49:16 +03:00
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
2018-10-17 17:06:31 +03:00
|
|
|
* @copyright Copyright (c) 2018, Georg Ehrke
|
2016-07-21 17:49:16 +03:00
|
|
|
*
|
2020-03-31 11:49:10 +03:00
|
|
|
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
|
2019-12-03 21:57:53 +03:00
|
|
|
* @author Georg Ehrke <oc.list@georgehrke.com>
|
2016-07-21 17:49:16 +03:00
|
|
|
* @author Joas Schilling <coding@schilljs.com>
|
2020-03-31 11:49:10 +03:00
|
|
|
* @author Julius Härtl <jus@bitgrid.net>
|
2016-05-26 20:56:05 +03:00
|
|
|
* @author Lukas Reschke <lukas@statuscode.ch>
|
2019-12-03 21:57:53 +03:00
|
|
|
* @author Morris Jobke <hey@morrisjobke.de>
|
2017-11-06 17:56:42 +03:00
|
|
|
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
2016-01-12 17:02:16 +03:00
|
|
|
* @author Thomas Müller <thomas.mueller@tmit.eu>
|
|
|
|
*
|
|
|
|
* @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,
|
2019-12-03 21:57:53 +03:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
2014-12-19 15:28:11 +03:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2016-05-25 17:04:15 +03:00
|
|
|
namespace OCA\DAV\Tests\unit\Connector\Sabre;
|
2014-12-19 18:50:32 +03:00
|
|
|
|
2017-01-09 23:20:55 +03:00
|
|
|
use OC\User\User;
|
2019-08-14 14:38:11 +03:00
|
|
|
use OCA\DAV\CalDAV\Proxy\Proxy;
|
|
|
|
use OCA\DAV\CalDAV\Proxy\ProxyMapper;
|
2019-03-05 18:00:47 +03:00
|
|
|
use OCP\App\IAppManager;
|
2018-05-22 16:09:21 +03:00
|
|
|
use OCP\IConfig;
|
2017-01-09 23:20:55 +03:00
|
|
|
use OCP\IGroup;
|
2016-01-11 19:29:01 +03:00
|
|
|
use OCP\IGroupManager;
|
2017-12-04 17:02:55 +03:00
|
|
|
use OCP\IUser;
|
2019-11-22 22:52:10 +03:00
|
|
|
use OCP\IUserManager;
|
2017-12-04 17:02:55 +03:00
|
|
|
use OCP\IUserSession;
|
|
|
|
use OCP\Share\IManager;
|
2019-11-22 22:52:10 +03:00
|
|
|
use Sabre\DAV\PropPatch;
|
2016-01-11 22:04:33 +03:00
|
|
|
use Test\TestCase;
|
2014-12-19 15:28:11 +03:00
|
|
|
|
2016-05-25 17:04:15 +03:00
|
|
|
class PrincipalTest extends TestCase {
|
2018-10-17 17:06:31 +03:00
|
|
|
|
2016-01-11 22:04:33 +03:00
|
|
|
/** @var IUserManager | \PHPUnit_Framework_MockObject_MockObject */
|
2014-12-19 15:28:11 +03:00
|
|
|
private $userManager;
|
2018-10-17 17:06:31 +03:00
|
|
|
|
2015-08-30 20:13:01 +03:00
|
|
|
/** @var \OCA\DAV\Connector\Sabre\Principal */
|
2014-12-19 15:28:11 +03:00
|
|
|
private $connector;
|
2018-10-17 17:06:31 +03:00
|
|
|
|
2016-01-11 22:04:33 +03:00
|
|
|
/** @var IGroupManager | \PHPUnit_Framework_MockObject_MockObject */
|
2016-01-11 19:29:01 +03:00
|
|
|
private $groupManager;
|
2018-10-17 17:06:31 +03:00
|
|
|
|
2017-12-04 17:02:55 +03:00
|
|
|
/** @var IManager | \PHPUnit_Framework_MockObject_MockObject */
|
|
|
|
private $shareManager;
|
2018-10-17 17:06:31 +03:00
|
|
|
|
2017-12-04 17:02:55 +03:00
|
|
|
/** @var IUserSession | \PHPUnit_Framework_MockObject_MockObject */
|
|
|
|
private $userSession;
|
2018-10-17 17:06:31 +03:00
|
|
|
|
2019-03-05 18:00:47 +03:00
|
|
|
/** @var IAppManager | \PHPUnit_Framework_MockObject_MockObject */
|
|
|
|
private $appManager;
|
|
|
|
|
2019-08-14 14:38:11 +03:00
|
|
|
/** @var ProxyMapper | \PHPUnit_Framework_MockObject_MockObject */
|
|
|
|
private $proxyMapper;
|
|
|
|
|
2019-11-26 18:37:57 +03:00
|
|
|
/** @var IConfig | \PHPUnit_Framework_MockObject_MockObject */
|
|
|
|
private $config;
|
|
|
|
|
2019-11-27 17:27:18 +03:00
|
|
|
protected function setUp(): void {
|
2017-01-09 23:20:55 +03:00
|
|
|
$this->userManager = $this->createMock(IUserManager::class);
|
|
|
|
$this->groupManager = $this->createMock(IGroupManager::class);
|
2017-12-04 17:02:55 +03:00
|
|
|
$this->shareManager = $this->createMock(IManager::class);
|
|
|
|
$this->userSession = $this->createMock(IUserSession::class);
|
2019-03-05 18:00:47 +03:00
|
|
|
$this->appManager = $this->createMock(IAppManager::class);
|
2019-08-14 14:38:11 +03:00
|
|
|
$this->proxyMapper = $this->createMock(ProxyMapper::class);
|
2019-11-26 18:37:57 +03:00
|
|
|
$this->config = $this->createMock(IConfig::class);
|
2014-12-19 15:28:11 +03:00
|
|
|
|
2016-01-11 19:29:01 +03:00
|
|
|
$this->connector = new \OCA\DAV\Connector\Sabre\Principal(
|
|
|
|
$this->userManager,
|
2017-12-04 17:02:55 +03:00
|
|
|
$this->groupManager,
|
|
|
|
$this->shareManager,
|
2018-05-22 16:09:21 +03:00
|
|
|
$this->userSession,
|
2019-08-14 14:38:11 +03:00
|
|
|
$this->appManager,
|
2019-11-26 18:37:57 +03:00
|
|
|
$this->proxyMapper,
|
|
|
|
$this->config
|
2019-03-05 18:00:47 +03:00
|
|
|
);
|
2014-12-19 15:28:11 +03:00
|
|
|
parent::setUp();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetPrincipalsByPrefixWithoutPrefix() {
|
|
|
|
$response = $this->connector->getPrincipalsByPrefix('');
|
|
|
|
$this->assertSame([], $response);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetPrincipalsByPrefixWithUsers() {
|
2017-01-09 23:20:55 +03:00
|
|
|
$fooUser = $this->createMock(User::class);
|
2014-12-19 15:28:11 +03:00
|
|
|
$fooUser
|
2015-11-25 01:28:24 +03:00
|
|
|
->expects($this->exactly(1))
|
2015-11-24 13:15:31 +03:00
|
|
|
->method('getUID')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('foo');
|
2015-11-24 13:15:31 +03:00
|
|
|
$fooUser
|
|
|
|
->expects($this->exactly(1))
|
|
|
|
->method('getDisplayName')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('Dr. Foo-Bar');
|
2015-11-25 01:28:24 +03:00
|
|
|
$fooUser
|
|
|
|
->expects($this->exactly(1))
|
|
|
|
->method('getEMailAddress')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('');
|
2017-01-09 23:20:55 +03:00
|
|
|
$barUser = $this->createMock(User::class);
|
2014-12-19 15:28:11 +03:00
|
|
|
$barUser
|
2015-11-25 01:28:24 +03:00
|
|
|
->expects($this->exactly(1))
|
2014-12-19 15:28:11 +03:00
|
|
|
->method('getUID')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('bar');
|
2015-11-25 01:28:24 +03:00
|
|
|
$barUser
|
|
|
|
->expects($this->exactly(1))
|
|
|
|
->method('getEMailAddress')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('bar@nextcloud.com');
|
2014-12-19 15:28:11 +03:00
|
|
|
$this->userManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('search')
|
|
|
|
->with('')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn([$fooUser, $barUser]);
|
2014-12-19 15:28:11 +03:00
|
|
|
|
|
|
|
$expectedResponse = [
|
|
|
|
0 => [
|
2015-11-24 13:15:31 +03:00
|
|
|
'uri' => 'principals/users/foo',
|
2018-10-17 17:06:31 +03:00
|
|
|
'{DAV:}displayname' => 'Dr. Foo-Bar',
|
|
|
|
'{urn:ietf:params:xml:ns:caldav}calendar-user-type' => 'INDIVIDUAL',
|
2014-12-19 15:28:11 +03:00
|
|
|
],
|
|
|
|
1 => [
|
2015-11-24 13:15:31 +03:00
|
|
|
'uri' => 'principals/users/bar',
|
2014-12-19 15:28:11 +03:00
|
|
|
'{DAV:}displayname' => 'bar',
|
2018-10-17 17:06:31 +03:00
|
|
|
'{urn:ietf:params:xml:ns:caldav}calendar-user-type' => 'INDIVIDUAL',
|
|
|
|
'{http://sabredav.org/ns}email-address' => 'bar@nextcloud.com',
|
2014-12-19 15:28:11 +03:00
|
|
|
]
|
|
|
|
];
|
2015-11-24 13:15:31 +03:00
|
|
|
$response = $this->connector->getPrincipalsByPrefix('principals/users');
|
2014-12-19 15:28:11 +03:00
|
|
|
$this->assertSame($expectedResponse, $response);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetPrincipalsByPrefixEmpty() {
|
|
|
|
$this->userManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('search')
|
|
|
|
->with('')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn([]);
|
2014-12-19 15:28:11 +03:00
|
|
|
|
2015-11-24 13:15:31 +03:00
|
|
|
$response = $this->connector->getPrincipalsByPrefix('principals/users');
|
2014-12-19 15:28:11 +03:00
|
|
|
$this->assertSame([], $response);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetPrincipalsByPathWithoutMail() {
|
2017-01-09 23:20:55 +03:00
|
|
|
$fooUser = $this->createMock(User::class);
|
2014-12-19 15:28:11 +03:00
|
|
|
$fooUser
|
2015-11-25 01:28:24 +03:00
|
|
|
->expects($this->exactly(1))
|
2014-12-19 15:28:11 +03:00
|
|
|
->method('getUID')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('foo');
|
2014-12-19 15:28:11 +03:00
|
|
|
$this->userManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('get')
|
|
|
|
->with('foo')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($fooUser);
|
2014-12-19 15:28:11 +03:00
|
|
|
|
|
|
|
$expectedResponse = [
|
2015-11-24 13:15:31 +03:00
|
|
|
'uri' => 'principals/users/foo',
|
2018-10-17 17:06:31 +03:00
|
|
|
'{DAV:}displayname' => 'foo',
|
|
|
|
'{urn:ietf:params:xml:ns:caldav}calendar-user-type' => 'INDIVIDUAL',
|
2014-12-19 15:28:11 +03:00
|
|
|
];
|
2015-11-24 13:15:31 +03:00
|
|
|
$response = $this->connector->getPrincipalByPath('principals/users/foo');
|
2014-12-19 15:28:11 +03:00
|
|
|
$this->assertSame($expectedResponse, $response);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetPrincipalsByPathWithMail() {
|
2017-01-09 23:20:55 +03:00
|
|
|
$fooUser = $this->createMock(User::class);
|
2014-12-19 15:28:11 +03:00
|
|
|
$fooUser
|
2015-11-25 01:28:24 +03:00
|
|
|
->expects($this->exactly(1))
|
|
|
|
->method('getEMailAddress')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('foo@nextcloud.com');
|
2015-11-25 01:28:24 +03:00
|
|
|
$fooUser
|
|
|
|
->expects($this->exactly(1))
|
|
|
|
->method('getUID')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('foo');
|
2014-12-19 15:28:11 +03:00
|
|
|
$this->userManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('get')
|
|
|
|
->with('foo')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($fooUser);
|
2014-12-19 15:28:11 +03:00
|
|
|
|
|
|
|
$expectedResponse = [
|
2015-11-24 13:15:31 +03:00
|
|
|
'uri' => 'principals/users/foo',
|
2014-12-19 15:28:11 +03:00
|
|
|
'{DAV:}displayname' => 'foo',
|
2018-10-17 17:06:31 +03:00
|
|
|
'{urn:ietf:params:xml:ns:caldav}calendar-user-type' => 'INDIVIDUAL',
|
|
|
|
'{http://sabredav.org/ns}email-address' => 'foo@nextcloud.com',
|
2014-12-19 15:28:11 +03:00
|
|
|
];
|
2015-11-24 13:15:31 +03:00
|
|
|
$response = $this->connector->getPrincipalByPath('principals/users/foo');
|
2014-12-19 15:28:11 +03:00
|
|
|
$this->assertSame($expectedResponse, $response);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetPrincipalsByPathEmpty() {
|
|
|
|
$this->userManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('get')
|
|
|
|
->with('foo')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(null);
|
2014-12-19 15:28:11 +03:00
|
|
|
|
2015-11-24 13:15:31 +03:00
|
|
|
$response = $this->connector->getPrincipalByPath('principals/users/foo');
|
2014-12-19 15:28:11 +03:00
|
|
|
$this->assertSame(null, $response);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetGroupMemberSet() {
|
2019-08-14 14:38:11 +03:00
|
|
|
$response = $this->connector->getGroupMemberSet('principals/users/foo');
|
|
|
|
$this->assertSame([], $response);
|
|
|
|
}
|
|
|
|
|
2019-11-26 18:37:57 +03:00
|
|
|
|
2019-08-14 14:38:11 +03:00
|
|
|
public function testGetGroupMemberSetEmpty() {
|
2019-11-27 17:27:18 +03:00
|
|
|
$this->expectException(\Sabre\DAV\Exception::class);
|
|
|
|
$this->expectExceptionMessage('Principal not found');
|
|
|
|
|
2019-08-14 14:38:11 +03:00
|
|
|
$this->userManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('get')
|
|
|
|
->with('foo')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(null);
|
2019-08-14 14:38:11 +03:00
|
|
|
|
|
|
|
$this->connector->getGroupMemberSet('principals/users/foo/calendar-proxy-read');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetGroupMemberSetProxyRead() {
|
2017-01-09 23:20:55 +03:00
|
|
|
$fooUser = $this->createMock(User::class);
|
2014-12-19 15:28:11 +03:00
|
|
|
$fooUser
|
2015-11-25 01:28:24 +03:00
|
|
|
->expects($this->exactly(1))
|
2014-12-19 15:28:11 +03:00
|
|
|
->method('getUID')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('foo');
|
2014-12-19 15:28:11 +03:00
|
|
|
$this->userManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('get')
|
|
|
|
->with('foo')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($fooUser);
|
2014-12-19 15:28:11 +03:00
|
|
|
|
2019-08-14 14:38:11 +03:00
|
|
|
$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'));
|
2014-12-19 15:28:11 +03:00
|
|
|
}
|
|
|
|
|
2019-08-14 14:38:11 +03:00
|
|
|
public function testGetGroupMemberSetProxyWrite() {
|
|
|
|
$fooUser = $this->createMock(User::class);
|
|
|
|
$fooUser
|
|
|
|
->expects($this->exactly(1))
|
|
|
|
->method('getUID')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('foo');
|
2014-12-19 15:28:11 +03:00
|
|
|
$this->userManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('get')
|
|
|
|
->with('foo')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($fooUser);
|
2019-08-14 14:38:11 +03:00
|
|
|
|
|
|
|
$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);
|
2014-12-19 15:28:11 +03:00
|
|
|
|
2019-08-14 14:38:11 +03:00
|
|
|
$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'));
|
2014-12-19 15:28:11 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetGroupMembership() {
|
2017-01-09 23:20:55 +03:00
|
|
|
$fooUser = $this->createMock(User::class);
|
|
|
|
$group1 = $this->createMock(IGroup::class);
|
|
|
|
$group1->expects($this->once())
|
2016-02-10 12:43:32 +03:00
|
|
|
->method('getGID')
|
|
|
|
->willReturn('group1');
|
2017-01-09 23:20:55 +03:00
|
|
|
$group2 = $this->createMock(IGroup::class);
|
|
|
|
$group2->expects($this->once())
|
|
|
|
->method('getGID')
|
|
|
|
->willReturn('foo/bar');
|
2014-12-19 15:28:11 +03:00
|
|
|
$this->userManager
|
2019-08-14 14:38:11 +03:00
|
|
|
->expects($this->exactly(2))
|
2014-12-19 15:28:11 +03:00
|
|
|
->method('get')
|
|
|
|
->with('foo')
|
2016-01-11 22:04:33 +03:00
|
|
|
->willReturn($fooUser);
|
|
|
|
$this->groupManager
|
2016-02-10 12:43:32 +03:00
|
|
|
->expects($this->once())
|
2016-01-11 22:04:33 +03:00
|
|
|
->method('getUserGroups')
|
2017-01-09 23:20:55 +03:00
|
|
|
->with($fooUser)
|
2016-02-10 12:43:32 +03:00
|
|
|
->willReturn([
|
2017-01-09 23:20:55 +03:00
|
|
|
$group1,
|
|
|
|
$group2,
|
2016-02-10 12:43:32 +03:00
|
|
|
]);
|
2014-12-19 15:28:11 +03:00
|
|
|
|
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('principals/users/foo')
|
|
|
|
->willReturn([$proxy1, $proxy2]);
|
|
|
|
|
2016-02-10 12:43:32 +03:00
|
|
|
$expectedResponse = [
|
2017-01-09 23:20:55 +03:00
|
|
|
'principals/groups/group1',
|
|
|
|
'principals/groups/foo%2Fbar',
|
2019-08-14 14:38:11 +03:00
|
|
|
'proxyId1/calendar-proxy-read',
|
2020-04-09 10:22:29 +03:00
|
|
|
'proxyId2/calendar-proxy-write',
|
2016-02-10 12:43:32 +03:00
|
|
|
];
|
2015-11-24 13:15:31 +03:00
|
|
|
$response = $this->connector->getGroupMembership('principals/users/foo');
|
2014-12-19 15:28:11 +03:00
|
|
|
$this->assertSame($expectedResponse, $response);
|
|
|
|
}
|
|
|
|
|
2019-11-26 18:37:57 +03:00
|
|
|
|
2014-12-19 15:28:11 +03:00
|
|
|
public function testGetGroupMembershipEmpty() {
|
2019-11-27 17:27:18 +03:00
|
|
|
$this->expectException(\Sabre\DAV\Exception::class);
|
|
|
|
$this->expectExceptionMessage('Principal not found');
|
|
|
|
|
2014-12-19 15:28:11 +03:00
|
|
|
$this->userManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('get')
|
|
|
|
->with('foo')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(null);
|
2014-12-19 15:28:11 +03:00
|
|
|
|
2015-11-24 13:15:31 +03:00
|
|
|
$this->connector->getGroupMembership('principals/users/foo');
|
2014-12-19 15:28:11 +03:00
|
|
|
}
|
|
|
|
|
2019-11-26 18:37:57 +03:00
|
|
|
|
2014-12-19 15:28:11 +03:00
|
|
|
public function testSetGroupMembership() {
|
2019-11-27 17:27:18 +03:00
|
|
|
$this->expectException(\Sabre\DAV\Exception::class);
|
|
|
|
$this->expectExceptionMessage('Setting members of the group is not supported yet');
|
|
|
|
|
2015-11-24 13:15:31 +03:00
|
|
|
$this->connector->setGroupMemberSet('principals/users/foo', ['foo']);
|
2014-12-19 15:28:11 +03:00
|
|
|
}
|
|
|
|
|
2019-08-14 14:38:11 +03:00
|
|
|
public function testSetGroupMembershipProxy() {
|
|
|
|
$fooUser = $this->createMock(User::class);
|
|
|
|
$fooUser
|
|
|
|
->expects($this->exactly(1))
|
|
|
|
->method('getUID')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('foo');
|
2019-08-14 14:38:11 +03:00
|
|
|
$barUser = $this->createMock(User::class);
|
|
|
|
$barUser
|
|
|
|
->expects($this->exactly(1))
|
|
|
|
->method('getUID')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('bar');
|
2019-08-14 14:38:11 +03:00
|
|
|
$this->userManager
|
|
|
|
->expects($this->at(0))
|
|
|
|
->method('get')
|
|
|
|
->with('foo')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($fooUser);
|
2019-08-14 14:38:11 +03:00
|
|
|
$this->userManager
|
|
|
|
->expects($this->at(1))
|
|
|
|
->method('get')
|
|
|
|
->with('bar')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($barUser);
|
2019-08-14 14:38:11 +03:00
|
|
|
|
|
|
|
$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']);
|
|
|
|
}
|
|
|
|
|
2014-12-19 15:28:11 +03:00
|
|
|
public function testUpdatePrincipal() {
|
2020-03-26 11:30:18 +03:00
|
|
|
$this->assertSame(0, $this->connector->updatePrincipal('foo', new PropPatch([])));
|
2014-12-19 15:28:11 +03:00
|
|
|
}
|
|
|
|
|
2017-12-04 17:02:55 +03:00
|
|
|
public function testSearchPrincipalsWithEmptySearchProperties() {
|
2015-11-24 13:15:31 +03:00
|
|
|
$this->assertSame([], $this->connector->searchPrincipals('principals/users', []));
|
2014-12-19 15:28:11 +03:00
|
|
|
}
|
2016-05-02 15:19:10 +03:00
|
|
|
|
2017-12-04 17:02:55 +03:00
|
|
|
public function testSearchPrincipalsWithWrongPrefixPath() {
|
|
|
|
$this->assertSame([], $this->connector->searchPrincipals('principals/groups',
|
|
|
|
['{http://sabredav.org/ns}email-address' => 'foo']));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider searchPrincipalsDataProvider
|
|
|
|
*/
|
2018-10-17 17:06:31 +03:00
|
|
|
public function testSearchPrincipals($sharingEnabled, $groupsOnly, $test, $result) {
|
2017-12-04 17:02:55 +03:00
|
|
|
$this->shareManager->expects($this->once())
|
|
|
|
->method('shareAPIEnabled')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($sharingEnabled);
|
2018-10-14 13:48:42 +03:00
|
|
|
|
|
|
|
if ($sharingEnabled) {
|
2020-03-10 18:19:49 +03:00
|
|
|
$this->shareManager->expects($this->once())
|
|
|
|
->method('allowEnumeration')
|
|
|
|
->willReturn(true);
|
2019-11-26 18:37:57 +03:00
|
|
|
|
2018-10-14 13:48:42 +03:00
|
|
|
$this->shareManager->expects($this->once())
|
|
|
|
->method('shareWithGroupMembersOnly')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($groupsOnly);
|
2018-10-14 13:48:42 +03:00
|
|
|
|
|
|
|
if ($groupsOnly) {
|
|
|
|
$user = $this->createMock(IUser::class);
|
|
|
|
$this->userSession->expects($this->once())
|
|
|
|
->method('getUser')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($user);
|
2018-10-14 13:48:42 +03:00
|
|
|
|
|
|
|
$this->groupManager->expects($this->at(0))
|
|
|
|
->method('getUserGroupIds')
|
|
|
|
->with($user)
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(['group1', 'group2', 'group5']);
|
2017-12-04 17:02:55 +03:00
|
|
|
}
|
|
|
|
} else {
|
2019-11-26 18:37:57 +03:00
|
|
|
$this->config->expects($this->never())
|
|
|
|
->method('getAppValue');
|
2017-12-04 17:02:55 +03:00
|
|
|
$this->shareManager->expects($this->never())
|
|
|
|
->method('shareWithGroupMembersOnly');
|
|
|
|
$this->groupManager->expects($this->never())
|
|
|
|
->method($this->anything());
|
|
|
|
}
|
|
|
|
|
|
|
|
$user2 = $this->createMock(IUser::class);
|
2020-03-26 00:21:27 +03:00
|
|
|
$user2->method('getUID')->willReturn('user2');
|
2017-12-04 17:02:55 +03:00
|
|
|
$user3 = $this->createMock(IUser::class);
|
2020-03-26 00:21:27 +03:00
|
|
|
$user3->method('getUID')->willReturn('user3');
|
2018-10-17 17:06:31 +03:00
|
|
|
$user4 = $this->createMock(IUser::class);
|
2020-03-26 00:21:27 +03:00
|
|
|
$user4->method('getUID')->willReturn('user4');
|
2017-12-04 17:02:55 +03:00
|
|
|
|
2018-10-14 13:48:42 +03:00
|
|
|
if ($sharingEnabled) {
|
|
|
|
$this->userManager->expects($this->at(0))
|
|
|
|
->method('getByEmail')
|
2018-10-17 17:06:31 +03:00
|
|
|
->with('user@example.com')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn([$user2, $user3]);
|
2018-10-17 17:06:31 +03:00
|
|
|
|
|
|
|
$this->userManager->expects($this->at(1))
|
|
|
|
->method('searchDisplayName')
|
|
|
|
->with('User 12')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn([$user3, $user4]);
|
2018-05-22 16:09:21 +03:00
|
|
|
} else {
|
|
|
|
$this->userManager->expects($this->never())
|
|
|
|
->method('getByEmail');
|
2018-10-17 17:06:31 +03:00
|
|
|
|
|
|
|
$this->userManager->expects($this->never())
|
|
|
|
->method('searchDisplayName');
|
2017-12-04 17:02:55 +03:00
|
|
|
}
|
|
|
|
|
2018-10-14 13:48:42 +03:00
|
|
|
if ($sharingEnabled && $groupsOnly) {
|
|
|
|
$this->groupManager->expects($this->at(1))
|
|
|
|
->method('getUserGroupIds')
|
|
|
|
->with($user2)
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(['group1', 'group3']);
|
2018-10-14 13:48:42 +03:00
|
|
|
$this->groupManager->expects($this->at(2))
|
|
|
|
->method('getUserGroupIds')
|
|
|
|
->with($user3)
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(['group3', 'group4']);
|
2018-10-17 17:06:31 +03:00
|
|
|
$this->groupManager->expects($this->at(3))
|
|
|
|
->method('getUserGroupIds')
|
|
|
|
->with($user3)
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(['group3', 'group4']);
|
2018-10-17 17:06:31 +03:00
|
|
|
$this->groupManager->expects($this->at(4))
|
|
|
|
->method('getUserGroupIds')
|
|
|
|
->with($user4)
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(['group4', 'group5']);
|
2017-12-04 17:02:55 +03:00
|
|
|
}
|
|
|
|
|
2018-10-14 13:48:42 +03:00
|
|
|
|
2017-12-04 17:02:55 +03:00
|
|
|
$this->assertEquals($result, $this->connector->searchPrincipals('principals/users',
|
2018-10-17 17:06:31 +03:00
|
|
|
['{http://sabredav.org/ns}email-address' => 'user@example.com',
|
|
|
|
'{DAV:}displayname' => 'User 12'], $test));
|
2017-12-04 17:02:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function searchPrincipalsDataProvider() {
|
|
|
|
return [
|
2018-10-17 17:06:31 +03:00
|
|
|
[true, false, 'allof', ['principals/users/user3']],
|
|
|
|
[true, false, 'anyof', ['principals/users/user2', 'principals/users/user3', 'principals/users/user4']],
|
|
|
|
[true, true, 'allof', []],
|
|
|
|
[true, true, 'anyof', ['principals/users/user2', 'principals/users/user4']],
|
|
|
|
[false, false, 'allof', []],
|
|
|
|
[false, false, 'anyof', []],
|
2017-12-04 17:02:55 +03:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2019-02-20 22:22:56 +03:00
|
|
|
public function testSearchPrincipalByCalendarUserAddressSet() {
|
|
|
|
$this->shareManager->expects($this->exactly(2))
|
|
|
|
->method('shareAPIEnabled')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(true);
|
2019-02-20 22:22:56 +03:00
|
|
|
|
2020-03-10 18:19:49 +03:00
|
|
|
$this->shareManager->expects($this->exactly(2))
|
|
|
|
->method('allowEnumeration')
|
|
|
|
->willReturn(true);
|
2019-11-26 18:37:57 +03:00
|
|
|
|
2019-02-20 22:22:56 +03:00
|
|
|
$this->shareManager->expects($this->exactly(2))
|
|
|
|
->method('shareWithGroupMembersOnly')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(false);
|
2019-02-20 22:22:56 +03:00
|
|
|
|
|
|
|
$user2 = $this->createMock(IUser::class);
|
2020-03-26 00:21:27 +03:00
|
|
|
$user2->method('getUID')->willReturn('user2');
|
2019-02-20 22:22:56 +03:00
|
|
|
$user3 = $this->createMock(IUser::class);
|
2020-03-26 00:21:27 +03:00
|
|
|
$user3->method('getUID')->willReturn('user3');
|
2019-02-20 22:22:56 +03:00
|
|
|
|
|
|
|
$this->userManager->expects($this->at(0))
|
|
|
|
->method('getByEmail')
|
|
|
|
->with('user@example.com')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn([$user2, $user3]);
|
2019-02-20 22:22:56 +03:00
|
|
|
|
|
|
|
$this->assertEquals([
|
2020-04-09 10:22:29 +03:00
|
|
|
'principals/users/user2',
|
|
|
|
'principals/users/user3',
|
|
|
|
], $this->connector->searchPrincipals('principals/users',
|
2019-02-20 22:22:56 +03:00
|
|
|
['{urn:ietf:params:xml:ns:caldav}calendar-user-address-set' => 'user@example.com']));
|
|
|
|
}
|
|
|
|
|
2019-11-26 18:37:57 +03:00
|
|
|
public function testSearchPrincipalWithEnumerationDisabledDisplayname() {
|
|
|
|
$this->shareManager->expects($this->once())
|
|
|
|
->method('shareAPIEnabled')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(true);
|
2019-11-26 18:37:57 +03:00
|
|
|
|
2020-03-10 18:19:49 +03:00
|
|
|
$this->shareManager->expects($this->once())
|
|
|
|
->method('allowEnumeration')
|
|
|
|
->willReturn(false);
|
2019-11-26 18:37:57 +03:00
|
|
|
|
|
|
|
$this->shareManager->expects($this->once())
|
|
|
|
->method('shareWithGroupMembersOnly')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(false);
|
2019-11-26 18:37:57 +03:00
|
|
|
|
|
|
|
$user2 = $this->createMock(IUser::class);
|
2020-03-26 00:21:27 +03:00
|
|
|
$user2->method('getUID')->willReturn('user2');
|
|
|
|
$user2->method('getDisplayName')->willReturn('User 2');
|
|
|
|
$user2->method('getEMailAddress')->willReturn('user2@foo.bar');
|
2019-11-26 18:37:57 +03:00
|
|
|
$user3 = $this->createMock(IUser::class);
|
2020-03-26 00:21:27 +03:00
|
|
|
$user3->method('getUID')->willReturn('user3');
|
|
|
|
$user2->method('getDisplayName')->willReturn('User 22');
|
|
|
|
$user2->method('getEMailAddress')->willReturn('user2@foo.bar123');
|
2019-11-26 18:37:57 +03:00
|
|
|
$user4 = $this->createMock(IUser::class);
|
2020-03-26 00:21:27 +03:00
|
|
|
$user4->method('getUID')->willReturn('user4');
|
|
|
|
$user2->method('getDisplayName')->willReturn('User 222');
|
|
|
|
$user2->method('getEMailAddress')->willReturn('user2@foo.bar456');
|
2019-11-26 18:37:57 +03:00
|
|
|
|
|
|
|
$this->userManager->expects($this->at(0))
|
|
|
|
->method('searchDisplayName')
|
|
|
|
->with('User 2')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn([$user2, $user3, $user4]);
|
2019-11-26 18:37:57 +03:00
|
|
|
|
|
|
|
$this->assertEquals(['principals/users/user2'], $this->connector->searchPrincipals('principals/users',
|
|
|
|
['{DAV:}displayname' => 'User 2']));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testSearchPrincipalWithEnumerationDisabledEmail() {
|
|
|
|
$this->shareManager->expects($this->once())
|
|
|
|
->method('shareAPIEnabled')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(true);
|
2019-11-26 18:37:57 +03:00
|
|
|
|
2020-03-10 18:19:49 +03:00
|
|
|
$this->shareManager->expects($this->once())
|
|
|
|
->method('allowEnumeration')
|
|
|
|
->willReturn(false);
|
2019-11-26 18:37:57 +03:00
|
|
|
|
|
|
|
$this->shareManager->expects($this->once())
|
|
|
|
->method('shareWithGroupMembersOnly')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(false);
|
2019-11-26 18:37:57 +03:00
|
|
|
|
|
|
|
$user2 = $this->createMock(IUser::class);
|
2020-03-26 00:21:27 +03:00
|
|
|
$user2->method('getUID')->willReturn('user2');
|
|
|
|
$user2->method('getDisplayName')->willReturn('User 2');
|
|
|
|
$user2->method('getEMailAddress')->willReturn('user2@foo.bar');
|
2019-11-26 18:37:57 +03:00
|
|
|
$user3 = $this->createMock(IUser::class);
|
2020-03-26 00:21:27 +03:00
|
|
|
$user3->method('getUID')->willReturn('user3');
|
|
|
|
$user2->method('getDisplayName')->willReturn('User 22');
|
|
|
|
$user2->method('getEMailAddress')->willReturn('user2@foo.bar123');
|
2019-11-26 18:37:57 +03:00
|
|
|
$user4 = $this->createMock(IUser::class);
|
2020-03-26 00:21:27 +03:00
|
|
|
$user4->method('getUID')->willReturn('user4');
|
|
|
|
$user2->method('getDisplayName')->willReturn('User 222');
|
|
|
|
$user2->method('getEMailAddress')->willReturn('user2@foo.bar456');
|
2019-11-26 18:37:57 +03:00
|
|
|
|
|
|
|
$this->userManager->expects($this->at(0))
|
|
|
|
->method('getByEmail')
|
|
|
|
->with('user2@foo.bar')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn([$user2, $user3, $user4]);
|
2019-11-26 18:37:57 +03:00
|
|
|
|
|
|
|
$this->assertEquals(['principals/users/user2'], $this->connector->searchPrincipals('principals/users',
|
|
|
|
['{http://sabredav.org/ns}email-address' => 'user2@foo.bar']));
|
|
|
|
}
|
|
|
|
|
2020-02-20 20:52:23 +03:00
|
|
|
public function testSearchPrincipalWithEnumerationLimitedDisplayname() {
|
|
|
|
$this->shareManager->expects($this->at(0))
|
|
|
|
->method('shareAPIEnabled')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(true);
|
2020-02-20 20:52:23 +03:00
|
|
|
|
|
|
|
$this->shareManager->expects($this->at(1))
|
|
|
|
->method('allowEnumeration')
|
|
|
|
->willReturn(true);
|
|
|
|
|
|
|
|
$this->shareManager->expects($this->at(2))
|
|
|
|
->method('limitEnumerationToGroups')
|
|
|
|
->willReturn(true);
|
|
|
|
|
|
|
|
$this->shareManager->expects($this->once())
|
|
|
|
->method('shareWithGroupMembersOnly')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(false);
|
2020-02-20 20:52:23 +03:00
|
|
|
|
|
|
|
$user2 = $this->createMock(IUser::class);
|
2020-03-26 00:21:27 +03:00
|
|
|
$user2->method('getUID')->willReturn('user2');
|
|
|
|
$user2->method('getDisplayName')->willReturn('User 2');
|
|
|
|
$user2->method('getEMailAddress')->willReturn('user2@foo.bar');
|
2020-02-20 20:52:23 +03:00
|
|
|
$user3 = $this->createMock(IUser::class);
|
2020-03-26 00:21:27 +03:00
|
|
|
$user3->method('getUID')->willReturn('user3');
|
|
|
|
$user3->method('getDisplayName')->willReturn('User 22');
|
|
|
|
$user3->method('getEMailAddress')->willReturn('user2@foo.bar123');
|
2020-02-20 20:52:23 +03:00
|
|
|
$user4 = $this->createMock(IUser::class);
|
2020-03-26 00:21:27 +03:00
|
|
|
$user4->method('getUID')->willReturn('user4');
|
|
|
|
$user4->method('getDisplayName')->willReturn('User 222');
|
|
|
|
$user4->method('getEMailAddress')->willReturn('user2@foo.bar456');
|
2020-02-20 20:52:23 +03:00
|
|
|
|
|
|
|
|
|
|
|
$this->userSession->expects($this->at(0))
|
|
|
|
->method('getUser')
|
|
|
|
->willReturn($user2);
|
|
|
|
|
|
|
|
$this->groupManager->expects($this->at(0))
|
|
|
|
->method('getUserGroupIds')
|
|
|
|
->willReturn(['group1']);
|
|
|
|
$this->groupManager->expects($this->at(1))
|
|
|
|
->method('getUserGroupIds')
|
|
|
|
->willReturn(['group1']);
|
|
|
|
$this->groupManager->expects($this->at(2))
|
|
|
|
->method('getUserGroupIds')
|
|
|
|
->willReturn(['group1']);
|
|
|
|
$this->groupManager->expects($this->at(3))
|
|
|
|
->method('getUserGroupIds')
|
|
|
|
->willReturn(['group2']);
|
|
|
|
|
|
|
|
$this->userManager->expects($this->at(0))
|
|
|
|
->method('searchDisplayName')
|
|
|
|
->with('User')
|
|
|
|
->willReturn([$user2, $user3, $user4]);
|
|
|
|
|
|
|
|
|
|
|
|
$this->assertEquals([
|
|
|
|
'principals/users/user2',
|
|
|
|
'principals/users/user3',
|
|
|
|
], $this->connector->searchPrincipals('principals/users',
|
|
|
|
['{DAV:}displayname' => 'User']));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testSearchPrincipalWithEnumerationLimitedMail() {
|
|
|
|
$this->shareManager->expects($this->at(0))
|
|
|
|
->method('shareAPIEnabled')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(true);
|
2020-02-20 20:52:23 +03:00
|
|
|
|
|
|
|
$this->shareManager->expects($this->at(1))
|
|
|
|
->method('allowEnumeration')
|
|
|
|
->willReturn(true);
|
|
|
|
|
|
|
|
$this->shareManager->expects($this->at(2))
|
|
|
|
->method('limitEnumerationToGroups')
|
|
|
|
->willReturn(true);
|
|
|
|
|
|
|
|
$this->shareManager->expects($this->once())
|
|
|
|
->method('shareWithGroupMembersOnly')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(false);
|
2020-02-20 20:52:23 +03:00
|
|
|
|
|
|
|
$user2 = $this->createMock(IUser::class);
|
2020-03-26 00:21:27 +03:00
|
|
|
$user2->method('getUID')->willReturn('user2');
|
|
|
|
$user2->method('getDisplayName')->willReturn('User 2');
|
|
|
|
$user2->method('getEMailAddress')->willReturn('user2@foo.bar');
|
2020-02-20 20:52:23 +03:00
|
|
|
$user3 = $this->createMock(IUser::class);
|
2020-03-26 00:21:27 +03:00
|
|
|
$user3->method('getUID')->willReturn('user3');
|
|
|
|
$user3->method('getDisplayName')->willReturn('User 22');
|
|
|
|
$user3->method('getEMailAddress')->willReturn('user2@foo.bar123');
|
2020-02-20 20:52:23 +03:00
|
|
|
$user4 = $this->createMock(IUser::class);
|
2020-03-26 00:21:27 +03:00
|
|
|
$user4->method('getUID')->willReturn('user4');
|
|
|
|
$user4->method('getDisplayName')->willReturn('User 222');
|
|
|
|
$user4->method('getEMailAddress')->willReturn('user2@foo.bar456');
|
2020-02-20 20:52:23 +03:00
|
|
|
|
|
|
|
|
|
|
|
$this->userSession->expects($this->at(0))
|
|
|
|
->method('getUser')
|
|
|
|
->willReturn($user2);
|
|
|
|
|
|
|
|
$this->groupManager->expects($this->at(0))
|
|
|
|
->method('getUserGroupIds')
|
|
|
|
->willReturn(['group1']);
|
|
|
|
$this->groupManager->expects($this->at(1))
|
|
|
|
->method('getUserGroupIds')
|
|
|
|
->willReturn(['group1']);
|
|
|
|
$this->groupManager->expects($this->at(2))
|
|
|
|
->method('getUserGroupIds')
|
|
|
|
->willReturn(['group1']);
|
|
|
|
$this->groupManager->expects($this->at(3))
|
|
|
|
->method('getUserGroupIds')
|
|
|
|
->willReturn(['group2']);
|
|
|
|
|
|
|
|
$this->userManager->expects($this->at(0))
|
|
|
|
->method('getByEmail')
|
|
|
|
->with('user')
|
|
|
|
->willReturn([$user2, $user3, $user4]);
|
|
|
|
|
|
|
|
|
|
|
|
$this->assertEquals([
|
|
|
|
'principals/users/user2',
|
|
|
|
'principals/users/user3'
|
|
|
|
], $this->connector->searchPrincipals('principals/users',
|
|
|
|
['{http://sabredav.org/ns}email-address' => 'user']));
|
|
|
|
}
|
|
|
|
|
2017-12-04 17:02:55 +03:00
|
|
|
public function testFindByUriSharingApiDisabled() {
|
|
|
|
$this->shareManager->expects($this->once())
|
|
|
|
->method('shareApiEnabled')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(false);
|
2017-12-04 17:02:55 +03:00
|
|
|
|
|
|
|
$this->assertEquals(null, $this->connector->findByUri('mailto:user@foo.com', 'principals/users'));
|
|
|
|
}
|
2016-05-02 15:19:10 +03:00
|
|
|
|
2017-12-04 17:02:55 +03:00
|
|
|
/**
|
|
|
|
* @dataProvider findByUriWithGroupRestrictionDataProvider
|
|
|
|
*/
|
2018-10-14 13:48:42 +03:00
|
|
|
public function testFindByUriWithGroupRestriction($uri, $email, $expects) {
|
2017-12-04 17:02:55 +03:00
|
|
|
$this->shareManager->expects($this->once())
|
|
|
|
->method('shareApiEnabled')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(true);
|
2017-12-04 17:02:55 +03:00
|
|
|
|
2018-05-22 16:09:21 +03:00
|
|
|
$this->shareManager->expects($this->once())
|
|
|
|
->method('shareWithGroupMembersOnly')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(true);
|
2017-12-04 17:02:55 +03:00
|
|
|
|
2018-05-22 16:09:21 +03:00
|
|
|
$user = $this->createMock(IUser::class);
|
|
|
|
$this->userSession->expects($this->once())
|
|
|
|
->method('getUser')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($user);
|
2017-12-04 17:02:55 +03:00
|
|
|
|
2018-05-22 16:09:21 +03:00
|
|
|
$this->groupManager->expects($this->at(0))
|
|
|
|
->method('getUserGroupIds')
|
|
|
|
->with($user)
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(['group1', 'group2']);
|
2017-12-04 17:02:55 +03:00
|
|
|
|
2018-05-22 16:09:21 +03:00
|
|
|
$user2 = $this->createMock(IUser::class);
|
2020-03-26 00:21:27 +03:00
|
|
|
$user2->method('getUID')->willReturn('user2');
|
2018-05-22 16:09:21 +03:00
|
|
|
$user3 = $this->createMock(IUser::class);
|
2020-03-26 00:21:27 +03:00
|
|
|
$user3->method('getUID')->willReturn('user3');
|
2017-12-04 17:02:55 +03:00
|
|
|
|
2018-05-22 16:09:21 +03:00
|
|
|
$this->userManager->expects($this->once())
|
|
|
|
->method('getByEmail')
|
|
|
|
->with($email)
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn([$email === 'user2@foo.bar' ? $user2 : $user3]);
|
2017-12-04 17:02:55 +03:00
|
|
|
|
2018-05-22 16:09:21 +03:00
|
|
|
if ($email === 'user2@foo.bar') {
|
|
|
|
$this->groupManager->expects($this->at(1))
|
|
|
|
->method('getUserGroupIds')
|
|
|
|
->with($user2)
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(['group1', 'group3']);
|
2018-05-22 16:09:21 +03:00
|
|
|
} else {
|
|
|
|
$this->groupManager->expects($this->at(1))
|
|
|
|
->method('getUserGroupIds')
|
|
|
|
->with($user3)
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(['group3', 'group3']);
|
2018-05-22 16:09:21 +03:00
|
|
|
}
|
2017-12-04 17:02:55 +03:00
|
|
|
|
|
|
|
$this->assertEquals($expects, $this->connector->findByUri($uri, 'principals/users'));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function findByUriWithGroupRestrictionDataProvider() {
|
|
|
|
return [
|
2018-10-14 13:48:42 +03:00
|
|
|
['mailto:user2@foo.bar', 'user2@foo.bar', 'principals/users/user2'],
|
|
|
|
['mailto:user3@foo.bar', 'user3@foo.bar', null],
|
2017-12-04 17:02:55 +03:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider findByUriWithoutGroupRestrictionDataProvider
|
|
|
|
*/
|
2018-10-14 13:48:42 +03:00
|
|
|
public function testFindByUriWithoutGroupRestriction($uri, $email, $expects) {
|
2017-12-04 17:02:55 +03:00
|
|
|
$this->shareManager->expects($this->once())
|
|
|
|
->method('shareApiEnabled')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(true);
|
2017-12-04 17:02:55 +03:00
|
|
|
|
2018-05-22 16:09:21 +03:00
|
|
|
$this->shareManager->expects($this->once())
|
|
|
|
->method('shareWithGroupMembersOnly')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(false);
|
2017-12-04 17:02:55 +03:00
|
|
|
|
2018-05-22 16:09:21 +03:00
|
|
|
$user2 = $this->createMock(IUser::class);
|
2020-03-26 00:21:27 +03:00
|
|
|
$user2->method('getUID')->willReturn('user2');
|
2018-05-22 16:09:21 +03:00
|
|
|
$user3 = $this->createMock(IUser::class);
|
2020-03-26 00:21:27 +03:00
|
|
|
$user3->method('getUID')->willReturn('user3');
|
2018-05-22 16:09:21 +03:00
|
|
|
|
|
|
|
$this->userManager->expects($this->once())
|
|
|
|
->method('getByEmail')
|
|
|
|
->with($email)
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn([$email === 'user2@foo.bar' ? $user2 : $user3]);
|
2017-12-04 17:02:55 +03:00
|
|
|
|
|
|
|
$this->assertEquals($expects, $this->connector->findByUri($uri, 'principals/users'));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function findByUriWithoutGroupRestrictionDataProvider() {
|
|
|
|
return [
|
2018-10-14 13:48:42 +03:00
|
|
|
['mailto:user2@foo.bar', 'user2@foo.bar', 'principals/users/user2'],
|
|
|
|
['mailto:user3@foo.bar', 'user3@foo.bar', 'principals/users/user3'],
|
2017-12-04 17:02:55 +03:00
|
|
|
];
|
2016-05-02 15:19:10 +03:00
|
|
|
}
|
2014-12-19 15:28:11 +03:00
|
|
|
}
|