2017-09-12 18:42:57 +03:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @copyright Copyright (c) 2017 Arthur Schiwon <blizzz@arthur-schiwon.de>
|
|
|
|
*
|
|
|
|
* @author Arthur Schiwon <blizzz@arthur-schiwon.de>
|
|
|
|
*
|
|
|
|
* @license GNU AGPL version 3 or any later version
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Test\Collaboration\Collaborators;
|
|
|
|
|
|
|
|
use OC\Collaboration\Collaborators\SearchResult;
|
|
|
|
use OC\Collaboration\Collaborators\UserPlugin;
|
2021-03-09 23:48:48 +03:00
|
|
|
use OC\KnownUser\KnownUserService;
|
2017-09-12 18:42:57 +03:00
|
|
|
use OCP\Collaboration\Collaborators\ISearchResult;
|
|
|
|
use OCP\IConfig;
|
2019-06-21 16:38:19 +03:00
|
|
|
use OCP\IGroup;
|
2017-09-12 18:42:57 +03:00
|
|
|
use OCP\IGroupManager;
|
|
|
|
use OCP\IUser;
|
|
|
|
use OCP\IUserManager;
|
|
|
|
use OCP\IUserSession;
|
2020-06-24 17:49:16 +03:00
|
|
|
use OCP\Share\IShare;
|
2020-08-05 11:37:20 +03:00
|
|
|
use OCP\UserStatus\IManager as IUserStatusManager;
|
2017-09-12 18:42:57 +03:00
|
|
|
use Test\TestCase;
|
|
|
|
|
|
|
|
class UserPluginTest extends TestCase {
|
2020-08-11 22:32:18 +03:00
|
|
|
/** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */
|
2017-09-12 18:42:57 +03:00
|
|
|
protected $config;
|
|
|
|
|
2020-08-11 22:32:18 +03:00
|
|
|
/** @var IUserManager|\PHPUnit\Framework\MockObject\MockObject */
|
2017-09-12 18:42:57 +03:00
|
|
|
protected $userManager;
|
|
|
|
|
2020-08-11 22:32:18 +03:00
|
|
|
/** @var IGroupManager|\PHPUnit\Framework\MockObject\MockObject */
|
2017-09-12 18:42:57 +03:00
|
|
|
protected $groupManager;
|
|
|
|
|
2020-08-11 22:32:18 +03:00
|
|
|
/** @var IUserSession|\PHPUnit\Framework\MockObject\MockObject */
|
2017-09-12 18:42:57 +03:00
|
|
|
protected $session;
|
|
|
|
|
2021-03-09 23:48:48 +03:00
|
|
|
/** @var KnownUserService|\PHPUnit\Framework\MockObject\MockObject */
|
|
|
|
protected $knownUserService;
|
|
|
|
|
2020-08-05 11:37:20 +03:00
|
|
|
/** @var IUserStatusManager|\PHPUnit\Framework\MockObject\MockObject */
|
|
|
|
protected $userStatusManager;
|
|
|
|
|
2017-09-12 18:42:57 +03:00
|
|
|
/** @var UserPlugin */
|
|
|
|
protected $plugin;
|
|
|
|
|
|
|
|
/** @var ISearchResult */
|
|
|
|
protected $searchResult;
|
|
|
|
|
|
|
|
/** @var int */
|
|
|
|
protected $limit = 2;
|
|
|
|
|
|
|
|
/** @var int */
|
|
|
|
protected $offset = 0;
|
|
|
|
|
2020-08-11 22:32:18 +03:00
|
|
|
/** @var IUser|\PHPUnit\Framework\MockObject\MockObject */
|
2017-09-12 18:42:57 +03:00
|
|
|
protected $user;
|
|
|
|
|
2019-11-27 17:27:18 +03:00
|
|
|
protected function setUp(): void {
|
2017-09-12 18:42:57 +03:00
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
$this->config = $this->createMock(IConfig::class);
|
|
|
|
|
|
|
|
$this->userManager = $this->createMock(IUserManager::class);
|
|
|
|
|
|
|
|
$this->groupManager = $this->createMock(IGroupManager::class);
|
|
|
|
|
|
|
|
$this->session = $this->createMock(IUserSession::class);
|
|
|
|
|
2021-03-09 23:48:48 +03:00
|
|
|
$this->knownUserService = $this->createMock(KnownUserService::class);
|
|
|
|
|
2020-08-05 11:37:20 +03:00
|
|
|
$this->userStatusManager = $this->createMock(IUserStatusManager::class);
|
|
|
|
|
2017-09-12 18:42:57 +03:00
|
|
|
$this->searchResult = new SearchResult();
|
|
|
|
|
|
|
|
$this->user = $this->getUserMock('admin', 'Administrator');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function instantiatePlugin() {
|
|
|
|
// cannot be done within setUp, because dependent mocks needs to be set
|
|
|
|
// up with configuration etc. first
|
|
|
|
$this->plugin = new UserPlugin(
|
|
|
|
$this->config,
|
|
|
|
$this->userManager,
|
|
|
|
$this->groupManager,
|
2020-08-05 11:37:20 +03:00
|
|
|
$this->session,
|
2021-03-09 23:48:48 +03:00
|
|
|
$this->knownUserService,
|
2020-08-05 11:37:20 +03:00
|
|
|
$this->userStatusManager
|
2017-09-12 18:42:57 +03:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-03-17 11:02:37 +03:00
|
|
|
public function mockConfig($shareWithGroupOnly, $shareeEnumeration, $shareeEnumerationLimitToGroup, $shareeEnumerationPhone = false) {
|
2020-02-20 22:00:38 +03:00
|
|
|
$this->config->expects($this->any())
|
|
|
|
->method('getAppValue')
|
|
|
|
->willReturnCallback(
|
2021-03-17 11:02:37 +03:00
|
|
|
function ($appName, $key, $default) use ($shareWithGroupOnly, $shareeEnumeration, $shareeEnumerationLimitToGroup, $shareeEnumerationPhone) {
|
2020-02-20 22:00:38 +03:00
|
|
|
if ($appName === 'core' && $key === 'shareapi_only_share_with_group_members') {
|
|
|
|
return $shareWithGroupOnly ? 'yes' : 'no';
|
2020-04-10 11:35:09 +03:00
|
|
|
} elseif ($appName === 'core' && $key === 'shareapi_allow_share_dialog_user_enumeration') {
|
2020-02-20 22:00:38 +03:00
|
|
|
return $shareeEnumeration ? 'yes' : 'no';
|
2020-04-10 11:35:09 +03:00
|
|
|
} elseif ($appName === 'core' && $key === 'shareapi_restrict_user_enumeration_to_group') {
|
2020-02-20 22:00:38 +03:00
|
|
|
return $shareeEnumerationLimitToGroup ? 'yes' : 'no';
|
2021-03-17 11:02:37 +03:00
|
|
|
} elseif ($appName === 'core' && $key === 'shareapi_restrict_user_enumeration_to_phone') {
|
|
|
|
return $shareeEnumerationPhone ? 'yes' : 'no';
|
2020-02-20 22:00:38 +03:00
|
|
|
}
|
|
|
|
return $default;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getUserMock($uid, $displayName, $enabled = true, $groups = []) {
|
2017-09-12 18:42:57 +03:00
|
|
|
$user = $this->createMock(IUser::class);
|
|
|
|
|
|
|
|
$user->expects($this->any())
|
|
|
|
->method('getUID')
|
|
|
|
->willReturn($uid);
|
|
|
|
|
|
|
|
$user->expects($this->any())
|
|
|
|
->method('getDisplayName')
|
|
|
|
->willReturn($displayName);
|
|
|
|
|
2018-08-06 10:55:24 +03:00
|
|
|
$user->expects($this->any())
|
|
|
|
->method('isEnabled')
|
|
|
|
->willReturn($enabled);
|
|
|
|
|
2017-09-12 18:42:57 +03:00
|
|
|
return $user;
|
|
|
|
}
|
|
|
|
|
2019-06-21 16:38:19 +03:00
|
|
|
public function getGroupMock($gid) {
|
|
|
|
$group = $this->createMock(IGroup::class);
|
|
|
|
|
|
|
|
$group->expects($this->any())
|
|
|
|
->method('getGID')
|
|
|
|
->willReturn($gid);
|
|
|
|
|
|
|
|
return $group;
|
|
|
|
}
|
|
|
|
|
2017-09-12 18:42:57 +03:00
|
|
|
public function dataGetUsers() {
|
|
|
|
return [
|
|
|
|
['test', false, true, [], [], [], [], true, false],
|
|
|
|
['test', false, false, [], [], [], [], true, false],
|
|
|
|
['test', true, true, [], [], [], [], true, false],
|
|
|
|
['test', true, false, [], [], [], [], true, false],
|
|
|
|
[
|
|
|
|
'test', false, true, [], [],
|
|
|
|
[
|
2020-10-07 13:31:30 +03:00
|
|
|
['label' => 'Test', 'value' => ['shareType' => IShare::TYPE_USER, 'shareWith' => 'test'], 'icon' => 'icon-user', 'subline' => null, 'status' => [], 'shareWithDisplayNameUnique' => 'test'],
|
2019-06-21 16:38:19 +03:00
|
|
|
], [], true, $this->getUserMock('test', 'Test'),
|
2017-09-12 18:42:57 +03:00
|
|
|
],
|
|
|
|
[
|
|
|
|
'test', false, false, [], [],
|
|
|
|
[
|
2020-10-07 13:31:30 +03:00
|
|
|
['label' => 'Test', 'value' => ['shareType' => IShare::TYPE_USER, 'shareWith' => 'test'], 'icon' => 'icon-user', 'subline' => null, 'status' => [], 'shareWithDisplayNameUnique' => 'test'],
|
2019-06-21 16:38:19 +03:00
|
|
|
], [], true, $this->getUserMock('test', 'Test'),
|
2017-09-12 18:42:57 +03:00
|
|
|
],
|
|
|
|
[
|
|
|
|
'test', true, true, [], [],
|
2019-06-21 16:38:19 +03:00
|
|
|
[], [], true, $this->getUserMock('test', 'Test'),
|
2017-09-12 18:42:57 +03:00
|
|
|
],
|
|
|
|
[
|
|
|
|
'test', true, false, [], [],
|
2019-06-21 16:38:19 +03:00
|
|
|
[], [], true, $this->getUserMock('test', 'Test'),
|
2017-09-12 18:42:57 +03:00
|
|
|
],
|
|
|
|
[
|
|
|
|
'test', true, true, ['test-group'], [['test-group', 'test', 2, 0, []]],
|
|
|
|
[
|
2020-10-07 13:31:30 +03:00
|
|
|
['label' => 'Test', 'value' => ['shareType' => IShare::TYPE_USER, 'shareWith' => 'test'], 'icon' => 'icon-user', 'subline' => null, 'status' => [], 'shareWithDisplayNameUnique' => 'test'],
|
2019-06-21 16:38:19 +03:00
|
|
|
], [], true, $this->getUserMock('test', 'Test'),
|
2017-09-12 18:42:57 +03:00
|
|
|
],
|
|
|
|
[
|
|
|
|
'test', true, false, ['test-group'], [['test-group', 'test', 2, 0, []]],
|
|
|
|
[
|
2020-10-07 13:31:30 +03:00
|
|
|
['label' => 'Test', 'value' => ['shareType' => IShare::TYPE_USER, 'shareWith' => 'test'], 'icon' => 'icon-user', 'subline' => null, 'status' => [], 'shareWithDisplayNameUnique' => 'test'],
|
2019-06-21 16:38:19 +03:00
|
|
|
], [], true, $this->getUserMock('test', 'Test'),
|
2017-09-12 18:42:57 +03:00
|
|
|
],
|
|
|
|
[
|
|
|
|
'test',
|
|
|
|
false,
|
|
|
|
true,
|
|
|
|
[],
|
|
|
|
[
|
|
|
|
$this->getUserMock('test1', 'Test One'),
|
|
|
|
],
|
|
|
|
[],
|
|
|
|
[
|
2020-10-07 13:31:30 +03:00
|
|
|
['label' => 'Test One', 'value' => ['shareType' => IShare::TYPE_USER, 'shareWith' => 'test1'], 'icon' => 'icon-user', 'subline' => null, 'status' => [], 'shareWithDisplayNameUnique' => 'test1'],
|
2017-09-12 18:42:57 +03:00
|
|
|
],
|
|
|
|
true,
|
|
|
|
false,
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'test',
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
[],
|
|
|
|
[
|
|
|
|
$this->getUserMock('test1', 'Test One'),
|
|
|
|
],
|
|
|
|
[],
|
|
|
|
[],
|
|
|
|
true,
|
|
|
|
false,
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'test',
|
|
|
|
false,
|
|
|
|
true,
|
|
|
|
[],
|
|
|
|
[
|
|
|
|
$this->getUserMock('test1', 'Test One'),
|
|
|
|
$this->getUserMock('test2', 'Test Two'),
|
|
|
|
],
|
|
|
|
[],
|
|
|
|
[
|
2020-10-07 13:31:30 +03:00
|
|
|
['label' => 'Test One', 'value' => ['shareType' => IShare::TYPE_USER, 'shareWith' => 'test1'], 'icon' => 'icon-user', 'subline' => null, 'status' => [], 'shareWithDisplayNameUnique' => 'test1'],
|
|
|
|
['label' => 'Test Two', 'value' => ['shareType' => IShare::TYPE_USER, 'shareWith' => 'test2'], 'icon' => 'icon-user', 'subline' => null, 'status' => [], 'shareWithDisplayNameUnique' => 'test2'],
|
2017-09-12 18:42:57 +03:00
|
|
|
],
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'test',
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
[],
|
|
|
|
[
|
|
|
|
$this->getUserMock('test1', 'Test One'),
|
|
|
|
$this->getUserMock('test2', 'Test Two'),
|
|
|
|
],
|
|
|
|
[],
|
|
|
|
[],
|
|
|
|
true,
|
|
|
|
false,
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'test',
|
|
|
|
false,
|
|
|
|
true,
|
|
|
|
[],
|
|
|
|
[
|
|
|
|
$this->getUserMock('test0', 'Test'),
|
|
|
|
$this->getUserMock('test1', 'Test One'),
|
|
|
|
$this->getUserMock('test2', 'Test Two'),
|
|
|
|
],
|
|
|
|
[
|
2020-10-07 13:31:30 +03:00
|
|
|
['label' => 'Test', 'value' => ['shareType' => IShare::TYPE_USER, 'shareWith' => 'test0'], 'icon' => 'icon-user', 'subline' => null, 'status' => [], 'shareWithDisplayNameUnique' => 'test0'],
|
2017-09-12 18:42:57 +03:00
|
|
|
],
|
|
|
|
[
|
2020-10-07 13:31:30 +03:00
|
|
|
['label' => 'Test One', 'value' => ['shareType' => IShare::TYPE_USER, 'shareWith' => 'test1'], 'icon' => 'icon-user', 'subline' => null, 'status' => [], 'shareWithDisplayNameUnique' => 'test1'],
|
|
|
|
['label' => 'Test Two', 'value' => ['shareType' => IShare::TYPE_USER, 'shareWith' => 'test2'], 'icon' => 'icon-user', 'subline' => null, 'status' => [], 'shareWithDisplayNameUnique' => 'test2'],
|
2017-09-12 18:42:57 +03:00
|
|
|
],
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
],
|
2021-03-17 11:02:37 +03:00
|
|
|
[
|
|
|
|
'test',
|
|
|
|
false,
|
|
|
|
true,
|
|
|
|
[],
|
|
|
|
[
|
|
|
|
$this->getUserMock('test0', 'Test'),
|
|
|
|
$this->getUserMock('test1', 'Test One'),
|
|
|
|
$this->getUserMock('test2', 'Test Two'),
|
|
|
|
],
|
|
|
|
[
|
|
|
|
['label' => 'Test', 'value' => ['shareType' => IShare::TYPE_USER, 'shareWith' => 'test0'], 'icon' => 'icon-user', 'subline' => null, 'status' => [], 'shareWithDisplayNameUnique' => 'test0'],
|
|
|
|
],
|
|
|
|
[
|
|
|
|
['label' => 'Test One', 'value' => ['shareType' => IShare::TYPE_USER, 'shareWith' => 'test1'], 'icon' => 'icon-user', 'subline' => null, 'status' => [], 'shareWithDisplayNameUnique' => 'test1'],
|
|
|
|
['label' => 'Test Two', 'value' => ['shareType' => IShare::TYPE_USER, 'shareWith' => 'test2'], 'icon' => 'icon-user', 'subline' => null, 'status' => [], 'shareWithDisplayNameUnique' => 'test2'],
|
|
|
|
],
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
[],
|
|
|
|
true,
|
|
|
|
],
|
2017-09-12 18:42:57 +03:00
|
|
|
[
|
|
|
|
'test',
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
[],
|
|
|
|
[
|
|
|
|
$this->getUserMock('test0', 'Test'),
|
|
|
|
$this->getUserMock('test1', 'Test One'),
|
|
|
|
$this->getUserMock('test2', 'Test Two'),
|
|
|
|
],
|
|
|
|
[
|
2020-10-07 13:31:30 +03:00
|
|
|
['label' => 'Test', 'value' => ['shareType' => IShare::TYPE_USER, 'shareWith' => 'test0'], 'icon' => 'icon-user', 'subline' => null, 'status' => [], 'shareWithDisplayNameUnique' => 'test0'],
|
2017-09-12 18:42:57 +03:00
|
|
|
],
|
|
|
|
[],
|
|
|
|
true,
|
|
|
|
false,
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'test',
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
['abc', 'xyz'],
|
|
|
|
[
|
2020-06-18 12:33:43 +03:00
|
|
|
['abc', 'test', 2, 0, ['test1' => 'Test One']],
|
2017-09-12 18:42:57 +03:00
|
|
|
['xyz', 'test', 2, 0, []],
|
|
|
|
],
|
|
|
|
[],
|
|
|
|
[
|
2020-10-07 13:31:30 +03:00
|
|
|
['label' => 'Test One', 'value' => ['shareType' => IShare::TYPE_USER, 'shareWith' => 'test1'], 'icon' => 'icon-user', 'subline' => null, 'status' => [], 'shareWithDisplayNameUnique' => 'test1'],
|
2017-09-12 18:42:57 +03:00
|
|
|
],
|
|
|
|
true,
|
|
|
|
false,
|
2020-06-18 12:33:43 +03:00
|
|
|
[['test1', $this->getUserMock('test1', 'Test One')]],
|
2017-09-12 18:42:57 +03:00
|
|
|
],
|
|
|
|
[
|
|
|
|
'test',
|
|
|
|
true,
|
|
|
|
false,
|
|
|
|
['abc', 'xyz'],
|
|
|
|
[
|
2020-06-18 12:33:43 +03:00
|
|
|
['abc', 'test', 2, 0, ['test1' => 'Test One']],
|
2017-09-12 18:42:57 +03:00
|
|
|
['xyz', 'test', 2, 0, []],
|
|
|
|
],
|
|
|
|
[],
|
|
|
|
[],
|
|
|
|
true,
|
|
|
|
false,
|
2020-06-18 12:33:43 +03:00
|
|
|
[['test1', $this->getUserMock('test1', 'Test One')]],
|
2017-09-12 18:42:57 +03:00
|
|
|
],
|
|
|
|
[
|
|
|
|
'test',
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
['abc', 'xyz'],
|
|
|
|
[
|
|
|
|
['abc', 'test', 2, 0, [
|
2020-06-18 12:33:43 +03:00
|
|
|
'test1' => 'Test One',
|
|
|
|
'test2' => 'Test Two',
|
2017-09-12 18:42:57 +03:00
|
|
|
]],
|
|
|
|
['xyz', 'test', 2, 0, [
|
2020-06-18 12:33:43 +03:00
|
|
|
'test1' => 'Test One',
|
|
|
|
'test2' => 'Test Two',
|
2017-09-12 18:42:57 +03:00
|
|
|
]],
|
|
|
|
],
|
|
|
|
[],
|
|
|
|
[
|
2020-10-07 13:31:30 +03:00
|
|
|
['label' => 'Test One', 'value' => ['shareType' => IShare::TYPE_USER, 'shareWith' => 'test1'], 'icon' => 'icon-user', 'subline' => null, 'status' => [], 'shareWithDisplayNameUnique' => 'test1'],
|
|
|
|
['label' => 'Test Two', 'value' => ['shareType' => IShare::TYPE_USER, 'shareWith' => 'test2'], 'icon' => 'icon-user', 'subline' => null, 'status' => [], 'shareWithDisplayNameUnique' => 'test2'],
|
2017-09-12 18:42:57 +03:00
|
|
|
],
|
2020-08-20 19:24:09 +03:00
|
|
|
true,
|
2017-09-12 18:42:57 +03:00
|
|
|
false,
|
2020-06-18 12:33:43 +03:00
|
|
|
[
|
|
|
|
['test1', $this->getUserMock('test1', 'Test One')],
|
|
|
|
['test2', $this->getUserMock('test2', 'Test Two')],
|
|
|
|
],
|
2017-09-12 18:42:57 +03:00
|
|
|
],
|
|
|
|
[
|
|
|
|
'test',
|
|
|
|
true,
|
|
|
|
false,
|
|
|
|
['abc', 'xyz'],
|
|
|
|
[
|
|
|
|
['abc', 'test', 2, 0, [
|
2020-06-18 12:33:43 +03:00
|
|
|
'test1' => 'Test One',
|
|
|
|
'test2' => 'Test Two',
|
2017-09-12 18:42:57 +03:00
|
|
|
]],
|
|
|
|
['xyz', 'test', 2, 0, [
|
2020-06-18 12:33:43 +03:00
|
|
|
'test1' => 'Test One',
|
|
|
|
'test2' => 'Test Two',
|
2017-09-12 18:42:57 +03:00
|
|
|
]],
|
|
|
|
],
|
|
|
|
[],
|
|
|
|
[],
|
|
|
|
true,
|
|
|
|
false,
|
2020-06-18 12:33:43 +03:00
|
|
|
[
|
|
|
|
['test1', $this->getUserMock('test1', 'Test One')],
|
|
|
|
['test2', $this->getUserMock('test2', 'Test Two')],
|
|
|
|
],
|
2017-09-12 18:42:57 +03:00
|
|
|
],
|
|
|
|
[
|
|
|
|
'test',
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
['abc', 'xyz'],
|
|
|
|
[
|
|
|
|
['abc', 'test', 2, 0, [
|
2020-06-18 12:33:43 +03:00
|
|
|
'test' => 'Test One',
|
2017-09-12 18:42:57 +03:00
|
|
|
]],
|
|
|
|
['xyz', 'test', 2, 0, [
|
2020-06-18 12:33:43 +03:00
|
|
|
'test2' => 'Test Two',
|
2017-09-12 18:42:57 +03:00
|
|
|
]],
|
|
|
|
],
|
|
|
|
[
|
2020-10-07 13:31:30 +03:00
|
|
|
['label' => 'Test One', 'value' => ['shareType' => IShare::TYPE_USER, 'shareWith' => 'test'], 'icon' => 'icon-user', 'subline' => null, 'status' => [], 'shareWithDisplayNameUnique' => 'test'],
|
2017-09-12 18:42:57 +03:00
|
|
|
],
|
|
|
|
[
|
2020-10-07 13:31:30 +03:00
|
|
|
['label' => 'Test Two', 'value' => ['shareType' => IShare::TYPE_USER, 'shareWith' => 'test2'], 'icon' => 'icon-user', 'subline' => null, 'status' => [], 'shareWithDisplayNameUnique' => 'test2'],
|
2017-09-12 18:42:57 +03:00
|
|
|
],
|
|
|
|
false,
|
|
|
|
false,
|
2020-06-18 12:33:43 +03:00
|
|
|
[
|
|
|
|
['test', $this->getUserMock('test', 'Test One')],
|
|
|
|
['test2', $this->getUserMock('test2', 'Test Two')],
|
|
|
|
],
|
2017-09-12 18:42:57 +03:00
|
|
|
],
|
|
|
|
[
|
|
|
|
'test',
|
|
|
|
true,
|
|
|
|
false,
|
|
|
|
['abc', 'xyz'],
|
|
|
|
[
|
|
|
|
['abc', 'test', 2, 0, [
|
2020-06-18 12:33:43 +03:00
|
|
|
'test' => 'Test One',
|
2017-09-12 18:42:57 +03:00
|
|
|
]],
|
|
|
|
['xyz', 'test', 2, 0, [
|
2020-06-18 12:33:43 +03:00
|
|
|
'test2' => 'Test Two',
|
2017-09-12 18:42:57 +03:00
|
|
|
]],
|
|
|
|
],
|
|
|
|
[
|
2020-10-07 13:31:30 +03:00
|
|
|
['label' => 'Test One', 'value' => ['shareType' => IShare::TYPE_USER, 'shareWith' => 'test'], 'icon' => 'icon-user', 'subline' => null, 'status' => [], 'shareWithDisplayNameUnique' => 'test'],
|
2017-09-12 18:42:57 +03:00
|
|
|
],
|
|
|
|
[],
|
|
|
|
true,
|
|
|
|
false,
|
2020-06-18 12:33:43 +03:00
|
|
|
[
|
|
|
|
['test', $this->getUserMock('test', 'Test One')],
|
|
|
|
['test2', $this->getUserMock('test2', 'Test Two')],
|
|
|
|
],
|
2017-09-12 18:42:57 +03:00
|
|
|
],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider dataGetUsers
|
|
|
|
*
|
|
|
|
* @param string $searchTerm
|
|
|
|
* @param bool $shareWithGroupOnly
|
|
|
|
* @param bool $shareeEnumeration
|
|
|
|
* @param array $groupResponse
|
|
|
|
* @param array $userResponse
|
|
|
|
* @param array $exactExpected
|
|
|
|
* @param array $expected
|
|
|
|
* @param bool $reachedEnd
|
|
|
|
* @param bool|IUser $singleUser
|
2020-06-18 12:33:43 +03:00
|
|
|
* @param array $users
|
2017-09-12 18:42:57 +03:00
|
|
|
*/
|
|
|
|
public function testSearch(
|
|
|
|
$searchTerm,
|
|
|
|
$shareWithGroupOnly,
|
|
|
|
$shareeEnumeration,
|
|
|
|
array $groupResponse,
|
|
|
|
array $userResponse,
|
|
|
|
array $exactExpected,
|
|
|
|
array $expected,
|
|
|
|
$reachedEnd,
|
2020-06-18 12:33:43 +03:00
|
|
|
$singleUser,
|
2021-03-17 11:02:37 +03:00
|
|
|
array $users = [],
|
|
|
|
$shareeEnumerationPhone = false
|
2017-09-12 18:42:57 +03:00
|
|
|
) {
|
2021-03-17 11:02:37 +03:00
|
|
|
$this->mockConfig($shareWithGroupOnly, $shareeEnumeration, false, $shareeEnumerationPhone);
|
2017-09-12 18:42:57 +03:00
|
|
|
$this->instantiatePlugin();
|
|
|
|
|
|
|
|
$this->session->expects($this->any())
|
|
|
|
->method('getUser')
|
|
|
|
->willReturn($this->user);
|
|
|
|
|
2019-06-21 16:38:19 +03:00
|
|
|
if (!$shareWithGroupOnly) {
|
2021-03-17 11:02:37 +03:00
|
|
|
if ($shareeEnumerationPhone) {
|
|
|
|
$this->userManager->expects($this->once())
|
|
|
|
->method('searchKnownUsersByDisplayName')
|
|
|
|
->with($this->user->getUID(), $searchTerm, $this->limit, $this->offset)
|
|
|
|
->willReturn($userResponse);
|
|
|
|
|
|
|
|
$this->knownUserService->method('isKnownToUser')
|
|
|
|
->willReturnMap([
|
|
|
|
[$this->user->getUID(), 'test0', true],
|
|
|
|
[$this->user->getUID(), 'test1', true],
|
|
|
|
[$this->user->getUID(), 'test2', true],
|
|
|
|
]);
|
|
|
|
} else {
|
|
|
|
$this->userManager->expects($this->once())
|
|
|
|
->method('searchDisplayName')
|
|
|
|
->with($searchTerm, $this->limit, $this->offset)
|
|
|
|
->willReturn($userResponse);
|
|
|
|
}
|
2017-09-12 18:42:57 +03:00
|
|
|
} else {
|
2020-06-18 12:33:43 +03:00
|
|
|
$this->groupManager->method('getUserGroupIds')
|
|
|
|
->with($this->user)
|
|
|
|
->willReturn($groupResponse);
|
2019-06-21 16:38:19 +03:00
|
|
|
|
2020-06-18 12:33:43 +03:00
|
|
|
if ($singleUser !== false) {
|
2019-06-21 16:38:19 +03:00
|
|
|
$this->groupManager->method('getUserGroupIds')
|
|
|
|
->with($singleUser)
|
2017-09-12 18:42:57 +03:00
|
|
|
->willReturn($groupResponse);
|
|
|
|
}
|
|
|
|
|
2020-06-18 12:33:43 +03:00
|
|
|
$this->groupManager->method('displayNamesInGroup')
|
|
|
|
->willReturnMap($userResponse);
|
2017-09-12 18:42:57 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($singleUser !== false) {
|
2020-06-18 12:33:43 +03:00
|
|
|
$users[] = [$searchTerm, $singleUser];
|
2017-09-12 18:42:57 +03:00
|
|
|
}
|
|
|
|
|
2020-06-18 12:33:43 +03:00
|
|
|
if (!empty($users)) {
|
|
|
|
$this->userManager->expects($this->atLeastOnce())
|
|
|
|
->method('get')
|
|
|
|
->willReturnMap($users);
|
|
|
|
}
|
2017-09-12 18:42:57 +03:00
|
|
|
|
|
|
|
$moreResults = $this->plugin->search($searchTerm, $this->limit, $this->offset, $this->searchResult);
|
|
|
|
$result = $this->searchResult->asArray();
|
|
|
|
|
|
|
|
$this->assertEquals($exactExpected, $result['exact']['users']);
|
|
|
|
$this->assertEquals($expected, $result['users']);
|
|
|
|
$this->assertSame($reachedEnd, $moreResults);
|
|
|
|
}
|
2018-01-17 15:49:18 +03:00
|
|
|
|
|
|
|
public function takeOutCurrentUserProvider() {
|
|
|
|
$inputUsers = [
|
|
|
|
'alice' => 'Alice',
|
|
|
|
'bob' => 'Bob',
|
2019-06-21 16:38:19 +03:00
|
|
|
'carol' => 'Carol',
|
2018-01-17 15:49:18 +03:00
|
|
|
];
|
|
|
|
return [
|
|
|
|
[
|
|
|
|
$inputUsers,
|
|
|
|
['alice', 'carol'],
|
2019-06-21 16:38:19 +03:00
|
|
|
'bob',
|
2018-01-17 15:49:18 +03:00
|
|
|
],
|
|
|
|
[
|
|
|
|
$inputUsers,
|
|
|
|
['alice', 'bob', 'carol'],
|
2019-06-21 16:38:19 +03:00
|
|
|
'dave',
|
2018-01-17 15:49:18 +03:00
|
|
|
],
|
|
|
|
[
|
|
|
|
$inputUsers,
|
|
|
|
['alice', 'bob', 'carol'],
|
2019-06-21 16:38:19 +03:00
|
|
|
null,
|
|
|
|
],
|
2018-01-17 15:49:18 +03:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider takeOutCurrentUserProvider
|
|
|
|
* @param array $users
|
|
|
|
* @param array $expectedUIDs
|
|
|
|
* @param $currentUserId
|
|
|
|
*/
|
|
|
|
public function testTakeOutCurrentUser(array $users, array $expectedUIDs, $currentUserId) {
|
|
|
|
$this->instantiatePlugin();
|
|
|
|
|
|
|
|
$this->session->expects($this->once())
|
|
|
|
->method('getUser')
|
2019-06-21 16:38:19 +03:00
|
|
|
->willReturnCallback(function () use ($currentUserId) {
|
|
|
|
if ($currentUserId !== null) {
|
2018-01-17 15:49:18 +03:00
|
|
|
return $this->getUserMock($currentUserId, $currentUserId);
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
});
|
|
|
|
|
|
|
|
$this->plugin->takeOutCurrentUser($users);
|
|
|
|
$this->assertSame($expectedUIDs, array_keys($users));
|
|
|
|
}
|
2020-02-20 22:00:38 +03:00
|
|
|
|
|
|
|
public function dataSearchEnumeration() {
|
|
|
|
return [
|
|
|
|
[
|
|
|
|
'test',
|
|
|
|
['groupA'],
|
|
|
|
[
|
2019-06-21 16:38:19 +03:00
|
|
|
['uid' => 'test1', 'groups' => ['groupA']],
|
|
|
|
['uid' => 'test2', 'groups' => ['groupB']],
|
2020-02-20 22:00:38 +03:00
|
|
|
],
|
2020-06-15 10:29:30 +03:00
|
|
|
['exact' => [], 'wide' => ['test1']],
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'test1',
|
|
|
|
['groupA'],
|
|
|
|
[
|
|
|
|
['uid' => 'test1', 'groups' => ['groupA']],
|
|
|
|
['uid' => 'test2', 'groups' => ['groupB']],
|
|
|
|
],
|
|
|
|
['exact' => ['test1'], 'wide' => []],
|
2020-02-20 22:00:38 +03:00
|
|
|
],
|
|
|
|
[
|
|
|
|
'test',
|
|
|
|
['groupA'],
|
|
|
|
[
|
2019-06-21 16:38:19 +03:00
|
|
|
['uid' => 'test1', 'groups' => ['groupA']],
|
|
|
|
['uid' => 'test2', 'groups' => ['groupB', 'groupA']],
|
2020-02-20 22:00:38 +03:00
|
|
|
],
|
2020-06-15 10:29:30 +03:00
|
|
|
['exact' => [], 'wide' => ['test1', 'test2']],
|
2020-02-20 22:00:38 +03:00
|
|
|
],
|
|
|
|
[
|
|
|
|
'test',
|
|
|
|
['groupA'],
|
|
|
|
[
|
2019-06-21 16:38:19 +03:00
|
|
|
['uid' => 'test1', 'groups' => ['groupA', 'groupC']],
|
|
|
|
['uid' => 'test2', 'groups' => ['groupB', 'groupA']],
|
2020-02-20 22:00:38 +03:00
|
|
|
],
|
2020-06-15 10:29:30 +03:00
|
|
|
['exact' => [], 'wide' => ['test1', 'test2']],
|
2020-02-20 22:00:38 +03:00
|
|
|
],
|
|
|
|
[
|
|
|
|
'test',
|
|
|
|
['groupC', 'groupB'],
|
|
|
|
[
|
2019-06-21 16:38:19 +03:00
|
|
|
['uid' => 'test1', 'groups' => ['groupA', 'groupC']],
|
|
|
|
['uid' => 'test2', 'groups' => ['groupB', 'groupA']],
|
2020-02-20 22:00:38 +03:00
|
|
|
],
|
2020-06-15 10:29:30 +03:00
|
|
|
['exact' => [], 'wide' => ['test1', 'test2']],
|
2020-02-20 22:00:38 +03:00
|
|
|
],
|
|
|
|
[
|
|
|
|
'test',
|
|
|
|
[],
|
|
|
|
[
|
2019-06-21 16:38:19 +03:00
|
|
|
['uid' => 'test1', 'groups' => ['groupA']],
|
|
|
|
['uid' => 'test2', 'groups' => ['groupB', 'groupA']],
|
2020-02-20 22:00:38 +03:00
|
|
|
],
|
2020-06-15 10:29:30 +03:00
|
|
|
['exact' => [], 'wide' => []],
|
2020-02-20 22:00:38 +03:00
|
|
|
],
|
|
|
|
[
|
|
|
|
'test',
|
|
|
|
['groupC', 'groupB'],
|
|
|
|
[
|
2019-06-21 16:38:19 +03:00
|
|
|
['uid' => 'test1', 'groups' => []],
|
|
|
|
['uid' => 'test2', 'groups' => []],
|
2020-02-20 22:00:38 +03:00
|
|
|
],
|
2020-06-15 10:29:30 +03:00
|
|
|
['exact' => [], 'wide' => []],
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'test',
|
|
|
|
['groupC', 'groupB'],
|
|
|
|
[
|
|
|
|
['uid' => 'test1', 'groups' => []],
|
|
|
|
['uid' => 'test2', 'groups' => []],
|
|
|
|
],
|
|
|
|
['exact' => [], 'wide' => []],
|
2020-02-20 22:00:38 +03:00
|
|
|
],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider dataSearchEnumeration
|
|
|
|
*/
|
|
|
|
public function testSearchEnumerationLimit($search, $userGroups, $matchingUsers, $result) {
|
|
|
|
$this->mockConfig(false, true, true);
|
|
|
|
|
2021-03-17 12:26:21 +03:00
|
|
|
$userResults = [];
|
|
|
|
foreach ($matchingUsers as $user) {
|
|
|
|
$userResults[$user['uid']] = $user['uid'];
|
|
|
|
}
|
2020-02-20 22:00:38 +03:00
|
|
|
|
2020-06-15 10:29:30 +03:00
|
|
|
$mappedResultExact = array_map(function ($user) {
|
2020-10-07 13:31:30 +03:00
|
|
|
return ['label' => $user, 'value' => ['shareType' => 0, 'shareWith' => $user], 'icon' => 'icon-user', 'subline' => null, 'status' => [], 'shareWithDisplayNameUnique' => $user];
|
2020-06-15 10:29:30 +03:00
|
|
|
}, $result['exact']);
|
|
|
|
$mappedResultWide = array_map(function ($user) {
|
2020-10-07 13:31:30 +03:00
|
|
|
return ['label' => $user, 'value' => ['shareType' => 0, 'shareWith' => $user], 'icon' => 'icon-user', 'subline' => null, 'status' => [], 'shareWithDisplayNameUnique' => $user];
|
2020-06-15 10:29:30 +03:00
|
|
|
}, $result['wide']);
|
2020-02-20 22:00:38 +03:00
|
|
|
|
2021-03-17 12:26:21 +03:00
|
|
|
$this->userManager
|
|
|
|
->method('get')
|
|
|
|
->willReturnCallback(function ($userId) use ($userResults) {
|
|
|
|
if (isset($userResults[$userId])) {
|
|
|
|
return $this->getUserMock($userId, $userId);
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
});
|
|
|
|
|
|
|
|
$this->groupManager->method('displayNamesInGroup')
|
2020-02-20 22:00:38 +03:00
|
|
|
->willReturn($userResults);
|
2021-03-17 12:26:21 +03:00
|
|
|
|
|
|
|
|
2020-02-20 22:00:38 +03:00
|
|
|
$this->session->expects($this->any())
|
|
|
|
->method('getUser')
|
|
|
|
->willReturn($this->getUserMock('test', 'foo'));
|
|
|
|
// current user
|
|
|
|
$this->groupManager->expects($this->at(0))
|
|
|
|
->method('getUserGroupIds')
|
|
|
|
->willReturn($userGroups);
|
|
|
|
$this->groupManager->expects($this->any())
|
|
|
|
->method('getUserGroupIds')
|
|
|
|
->willReturnCallback(function ($user) use ($matchingUsers) {
|
|
|
|
$neededObject = array_filter(
|
|
|
|
$matchingUsers,
|
|
|
|
function ($e) use ($user) {
|
|
|
|
return $user->getUID() === $e['uid'];
|
|
|
|
}
|
|
|
|
);
|
|
|
|
if (count($neededObject) > 0) {
|
|
|
|
return array_shift($neededObject)['groups'];
|
|
|
|
}
|
|
|
|
return [];
|
|
|
|
});
|
|
|
|
|
|
|
|
$this->instantiatePlugin();
|
|
|
|
$this->plugin->search($search, $this->limit, $this->offset, $this->searchResult);
|
|
|
|
$result = $this->searchResult->asArray();
|
|
|
|
|
2020-06-15 10:29:30 +03:00
|
|
|
$this->assertEquals($mappedResultExact, $result['exact']['users']);
|
|
|
|
$this->assertEquals($mappedResultWide, $result['users']);
|
2020-02-20 22:00:38 +03:00
|
|
|
}
|
2017-09-12 18:42:57 +03:00
|
|
|
}
|