2014-12-19 12:28:11 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2016-01-12 14:02:16 +00:00
|
|
|
* @author Lukas Reschke <lukas@owncloud.com>
|
|
|
|
* @author Thomas Müller <thomas.mueller@tmit.eu>
|
|
|
|
* @author Vincent Petry <pvince81@owncloud.com>
|
|
|
|
*
|
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
|
|
|
* @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/>
|
2014-12-19 12:28:11 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2015-10-30 15:05:25 +00:00
|
|
|
namespace OCA\DAV\Tests\Unit\Connector\Sabre;
|
2014-12-19 15:50:32 +00:00
|
|
|
|
2016-01-11 16:29:01 +00:00
|
|
|
use OCP\IGroupManager;
|
2015-02-12 11:29:01 +00:00
|
|
|
use \Sabre\DAV\PropPatch;
|
2014-12-19 12:28:11 +00:00
|
|
|
use OCP\IUserManager;
|
2016-01-11 19:04:33 +00:00
|
|
|
use Test\TestCase;
|
2014-12-19 12:28:11 +00:00
|
|
|
|
2016-01-11 19:04:33 +00:00
|
|
|
class Principal extends TestCase {
|
|
|
|
/** @var IUserManager | \PHPUnit_Framework_MockObject_MockObject */
|
2014-12-19 12:28:11 +00:00
|
|
|
private $userManager;
|
2015-08-30 17:13:01 +00:00
|
|
|
/** @var \OCA\DAV\Connector\Sabre\Principal */
|
2014-12-19 12:28:11 +00:00
|
|
|
private $connector;
|
2016-01-11 19:04:33 +00:00
|
|
|
/** @var IGroupManager | \PHPUnit_Framework_MockObject_MockObject */
|
2016-01-11 16:29:01 +00:00
|
|
|
private $groupManager;
|
2014-12-19 12:28:11 +00:00
|
|
|
|
|
|
|
public function setUp() {
|
|
|
|
$this->userManager = $this->getMockBuilder('\OCP\IUserManager')
|
|
|
|
->disableOriginalConstructor()->getMock();
|
2016-01-11 16:29:01 +00:00
|
|
|
$this->groupManager = $this->getMockBuilder('\OCP\IGroupManager')
|
|
|
|
->disableOriginalConstructor()->getMock();
|
2014-12-19 12:28:11 +00:00
|
|
|
|
2016-01-11 16:29:01 +00:00
|
|
|
$this->connector = new \OCA\DAV\Connector\Sabre\Principal(
|
|
|
|
$this->userManager,
|
|
|
|
$this->groupManager);
|
2014-12-19 12:28:11 +00:00
|
|
|
parent::setUp();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetPrincipalsByPrefixWithoutPrefix() {
|
|
|
|
$response = $this->connector->getPrincipalsByPrefix('');
|
|
|
|
$this->assertSame([], $response);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetPrincipalsByPrefixWithUsers() {
|
|
|
|
$fooUser = $this->getMockBuilder('\OC\User\User')
|
|
|
|
->disableOriginalConstructor()->getMock();
|
|
|
|
$fooUser
|
2015-11-24 22:28:24 +00:00
|
|
|
->expects($this->exactly(1))
|
2015-11-24 10:15:31 +00:00
|
|
|
->method('getUID')
|
|
|
|
->will($this->returnValue('foo'));
|
|
|
|
$fooUser
|
|
|
|
->expects($this->exactly(1))
|
|
|
|
->method('getDisplayName')
|
|
|
|
->will($this->returnValue('Dr. Foo-Bar'));
|
2015-11-24 22:28:24 +00:00
|
|
|
$fooUser
|
|
|
|
->expects($this->exactly(1))
|
|
|
|
->method('getEMailAddress')
|
|
|
|
->will($this->returnValue(''));
|
2014-12-19 12:28:11 +00:00
|
|
|
$barUser = $this->getMockBuilder('\OC\User\User')
|
|
|
|
->disableOriginalConstructor()->getMock();
|
|
|
|
$barUser
|
2015-11-24 22:28:24 +00:00
|
|
|
->expects($this->exactly(1))
|
2014-12-19 12:28:11 +00:00
|
|
|
->method('getUID')
|
|
|
|
->will($this->returnValue('bar'));
|
2015-11-24 22:28:24 +00:00
|
|
|
$barUser
|
|
|
|
->expects($this->exactly(1))
|
|
|
|
->method('getEMailAddress')
|
|
|
|
->will($this->returnValue('bar@owncloud.org'));
|
2014-12-19 12:28:11 +00:00
|
|
|
$this->userManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('search')
|
|
|
|
->with('')
|
|
|
|
->will($this->returnValue([$fooUser, $barUser]));
|
|
|
|
|
|
|
|
$expectedResponse = [
|
|
|
|
0 => [
|
2015-11-24 10:15:31 +00:00
|
|
|
'uri' => 'principals/users/foo',
|
|
|
|
'{DAV:}displayname' => 'Dr. Foo-Bar'
|
2014-12-19 12:28:11 +00:00
|
|
|
],
|
|
|
|
1 => [
|
2015-11-24 10:15:31 +00:00
|
|
|
'uri' => 'principals/users/bar',
|
2014-12-19 12:28:11 +00:00
|
|
|
'{DAV:}displayname' => 'bar',
|
|
|
|
'{http://sabredav.org/ns}email-address' => 'bar@owncloud.org'
|
|
|
|
]
|
|
|
|
];
|
2015-11-24 10:15:31 +00:00
|
|
|
$response = $this->connector->getPrincipalsByPrefix('principals/users');
|
2014-12-19 12:28:11 +00:00
|
|
|
$this->assertSame($expectedResponse, $response);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetPrincipalsByPrefixEmpty() {
|
|
|
|
$this->userManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('search')
|
|
|
|
->with('')
|
|
|
|
->will($this->returnValue([]));
|
|
|
|
|
2015-11-24 10:15:31 +00:00
|
|
|
$response = $this->connector->getPrincipalsByPrefix('principals/users');
|
2014-12-19 12:28:11 +00:00
|
|
|
$this->assertSame([], $response);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetPrincipalsByPathWithoutMail() {
|
|
|
|
$fooUser = $this->getMockBuilder('\OC\User\User')
|
|
|
|
->disableOriginalConstructor()->getMock();
|
|
|
|
$fooUser
|
2015-11-24 22:28:24 +00:00
|
|
|
->expects($this->exactly(1))
|
2014-12-19 12:28:11 +00:00
|
|
|
->method('getUID')
|
|
|
|
->will($this->returnValue('foo'));
|
|
|
|
$this->userManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('get')
|
|
|
|
->with('foo')
|
|
|
|
->will($this->returnValue($fooUser));
|
|
|
|
|
|
|
|
$expectedResponse = [
|
2015-11-24 10:15:31 +00:00
|
|
|
'uri' => 'principals/users/foo',
|
2014-12-19 12:28:11 +00:00
|
|
|
'{DAV:}displayname' => 'foo'
|
|
|
|
];
|
2015-11-24 10:15:31 +00:00
|
|
|
$response = $this->connector->getPrincipalByPath('principals/users/foo');
|
2014-12-19 12:28:11 +00:00
|
|
|
$this->assertSame($expectedResponse, $response);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetPrincipalsByPathWithMail() {
|
|
|
|
$fooUser = $this->getMockBuilder('\OC\User\User')
|
|
|
|
->disableOriginalConstructor()->getMock();
|
|
|
|
$fooUser
|
2015-11-24 22:28:24 +00:00
|
|
|
->expects($this->exactly(1))
|
|
|
|
->method('getEMailAddress')
|
|
|
|
->will($this->returnValue('foo@owncloud.org'));
|
|
|
|
$fooUser
|
|
|
|
->expects($this->exactly(1))
|
|
|
|
->method('getUID')
|
|
|
|
->will($this->returnValue('foo'));
|
2014-12-19 12:28:11 +00:00
|
|
|
$this->userManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('get')
|
|
|
|
->with('foo')
|
|
|
|
->will($this->returnValue($fooUser));
|
|
|
|
|
|
|
|
$expectedResponse = [
|
2015-11-24 10:15:31 +00:00
|
|
|
'uri' => 'principals/users/foo',
|
2014-12-19 12:28:11 +00:00
|
|
|
'{DAV:}displayname' => 'foo',
|
|
|
|
'{http://sabredav.org/ns}email-address' => 'foo@owncloud.org'
|
|
|
|
];
|
2015-11-24 10:15:31 +00:00
|
|
|
$response = $this->connector->getPrincipalByPath('principals/users/foo');
|
2014-12-19 12:28:11 +00:00
|
|
|
$this->assertSame($expectedResponse, $response);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetPrincipalsByPathEmpty() {
|
|
|
|
$this->userManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('get')
|
|
|
|
->with('foo')
|
|
|
|
->will($this->returnValue(null));
|
|
|
|
|
2015-11-24 10:15:31 +00:00
|
|
|
$response = $this->connector->getPrincipalByPath('principals/users/foo');
|
2014-12-19 12:28:11 +00:00
|
|
|
$this->assertSame(null, $response);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetGroupMemberSet() {
|
|
|
|
$fooUser = $this->getMockBuilder('\OC\User\User')
|
|
|
|
->disableOriginalConstructor()->getMock();
|
|
|
|
$fooUser
|
2015-11-24 22:28:24 +00:00
|
|
|
->expects($this->exactly(1))
|
2014-12-19 12:28:11 +00:00
|
|
|
->method('getUID')
|
|
|
|
->will($this->returnValue('foo'));
|
|
|
|
$this->userManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('get')
|
|
|
|
->with('foo')
|
|
|
|
->will($this->returnValue($fooUser));
|
|
|
|
|
2015-11-24 10:15:31 +00:00
|
|
|
$response = $this->connector->getGroupMemberSet('principals/users/foo');
|
|
|
|
$this->assertSame(['principals/users/foo'], $response);
|
2014-12-19 12:28:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @expectedException \Sabre\DAV\Exception
|
|
|
|
* @expectedExceptionMessage Principal not found
|
|
|
|
*/
|
|
|
|
public function testGetGroupMemberSetEmpty() {
|
|
|
|
$this->userManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('get')
|
|
|
|
->with('foo')
|
|
|
|
->will($this->returnValue(null));
|
|
|
|
|
2015-11-24 10:15:31 +00:00
|
|
|
$this->connector->getGroupMemberSet('principals/users/foo');
|
2014-12-19 12:28:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetGroupMembership() {
|
|
|
|
$fooUser = $this->getMockBuilder('\OC\User\User')
|
|
|
|
->disableOriginalConstructor()->getMock();
|
|
|
|
$this->userManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('get')
|
|
|
|
->with('foo')
|
2016-01-11 19:04:33 +00:00
|
|
|
->willReturn($fooUser);
|
|
|
|
$this->groupManager
|
|
|
|
->method('getUserGroups')
|
|
|
|
->willReturn([]);
|
2014-12-19 12:28:11 +00:00
|
|
|
|
|
|
|
$expectedResponse = [
|
2015-11-24 10:15:31 +00:00
|
|
|
'principals/users/foo/calendar-proxy-read',
|
|
|
|
'principals/users/foo/calendar-proxy-write'
|
2014-12-19 12:28:11 +00:00
|
|
|
];
|
2015-11-24 10:15:31 +00:00
|
|
|
$response = $this->connector->getGroupMembership('principals/users/foo');
|
2014-12-19 12:28:11 +00:00
|
|
|
$this->assertSame($expectedResponse, $response);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @expectedException \Sabre\DAV\Exception
|
|
|
|
* @expectedExceptionMessage Principal not found
|
|
|
|
*/
|
|
|
|
public function testGetGroupMembershipEmpty() {
|
|
|
|
$this->userManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('get')
|
|
|
|
->with('foo')
|
|
|
|
->will($this->returnValue(null));
|
|
|
|
|
2015-11-24 10:15:31 +00:00
|
|
|
$this->connector->getGroupMembership('principals/users/foo');
|
2014-12-19 12:28:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @expectedException \Sabre\DAV\Exception
|
|
|
|
* @expectedExceptionMessage Setting members of the group is not supported yet
|
|
|
|
*/
|
|
|
|
public function testSetGroupMembership() {
|
2015-11-24 10:15:31 +00:00
|
|
|
$this->connector->setGroupMemberSet('principals/users/foo', ['foo']);
|
2014-12-19 12:28:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testUpdatePrincipal() {
|
2015-02-12 11:29:01 +00:00
|
|
|
$this->assertSame(0, $this->connector->updatePrincipal('foo', new PropPatch(array())));
|
2014-12-19 12:28:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testSearchPrincipals() {
|
2015-11-24 10:15:31 +00:00
|
|
|
$this->assertSame([], $this->connector->searchPrincipals('principals/users', []));
|
2014-12-19 12:28:11 +00:00
|
|
|
}
|
|
|
|
}
|