['core', 'shareapi_restrict_user_enumeration_to_phone', 'no', 'no'],
['core', 'shareapi_restrict_user_enumeration_full_match', 'yes', 'yes'],
['core', 'shareapi_restrict_user_enumeration_full_match_userid', 'yes', 'yes'],
+ ['core', 'shareapi_restrict_user_enumeration_full_match_ignore_second_display_name', 'no', 'no'],
['core', 'shareapi_enabled', 'yes', 'yes'],
['core', 'shareapi_default_expire_date', 'no', 'no'],
['core', 'shareapi_expire_after_n_days', '7', '7'],
'restrictUserEnumerationToPhone' => 'no',
'restrictUserEnumerationFullMatch' => 'yes',
'restrictUserEnumerationFullMatchUserId' => 'yes',
+ 'restrictUserEnumerationFullMatchIgnoreSecondDisplayName' => 'no',
'enforceLinkPassword' => false,
'onlyShareWithGroupMembers' => false,
'shareAPIEnabled' => 'yes',
['core', 'shareapi_restrict_user_enumeration_to_phone', 'no', 'no'],
['core', 'shareapi_restrict_user_enumeration_full_match', 'yes', 'yes'],
['core', 'shareapi_restrict_user_enumeration_full_match_userid', 'yes', 'yes'],
+ ['core', 'shareapi_restrict_user_enumeration_full_match_ignore_second_display_name', 'no', 'no'],
['core', 'shareapi_enabled', 'yes', 'yes'],
['core', 'shareapi_default_expire_date', 'no', 'no'],
['core', 'shareapi_expire_after_n_days', '7', '7'],
'restrictUserEnumerationToPhone' => 'no',
'restrictUserEnumerationFullMatch' => 'yes',
'restrictUserEnumerationFullMatchUserId' => 'yes',
+ 'restrictUserEnumerationFullMatchIgnoreSecondDisplayName' => 'no',
'enforceLinkPassword' => false,
'onlyShareWithGroupMembers' => false,
'shareAPIEnabled' => 'yes',
);
}
- public function mockConfig($shareWithGroupOnly, $shareeEnumeration, $shareeEnumerationLimitToGroup, $shareeEnumerationPhone = false) {
+ public function mockConfig($mockedSettings) {
$this->config->expects($this->any())
->method('getAppValue')
->willReturnCallback(
- function ($appName, $key, $default) use ($shareWithGroupOnly, $shareeEnumeration, $shareeEnumerationLimitToGroup, $shareeEnumerationPhone) {
- if ($appName === 'core' && $key === 'shareapi_only_share_with_group_members') {
- return $shareWithGroupOnly ? 'yes' : 'no';
- } elseif ($appName === 'core' && $key === 'shareapi_allow_share_dialog_user_enumeration') {
- return $shareeEnumeration ? 'yes' : 'no';
- } elseif ($appName === 'core' && $key === 'shareapi_restrict_user_enumeration_to_group') {
- return $shareeEnumerationLimitToGroup ? 'yes' : 'no';
- } elseif ($appName === 'core' && $key === 'shareapi_restrict_user_enumeration_to_phone') {
- return $shareeEnumerationPhone ? 'yes' : 'no';
- }
- return $default;
+ function ($appName, $key, $default) use ($mockedSettings) {
+ return $mockedSettings[$appName][$key] ?? $default;
}
);
}
array $users = [],
$shareeEnumerationPhone = false
) {
- $this->mockConfig($shareWithGroupOnly, $shareeEnumeration, false, $shareeEnumerationPhone);
+ $this->mockConfig(["core" => [
+ 'shareapi_only_share_with_group_members' => $shareWithGroupOnly ? 'yes' : 'no',
+ 'shareapi_allow_share_dialog_user_enumeration' => $shareeEnumeration? 'yes' : 'no',
+ 'shareapi_restrict_user_enumeration_to_group' => false ? 'yes' : 'no',
+ 'shareapi_restrict_user_enumeration_to_phone' => $shareeEnumerationPhone ? 'yes' : 'no',
+ ]]);
+
$this->instantiatePlugin();
$this->session->expects($this->any())
['uid' => 'test2', 'groups' => ['groupB']],
],
['exact' => [], 'wide' => ['test1']],
+ ['core' => ['shareapi_restrict_user_enumeration_to_group' => 'yes']],
+ ],
+ [
+ 'test',
+ ['groupA'],
+ [
+ ['uid' => 'test1', 'displayName' => 'Test user 1', 'groups' => ['groupA']],
+ ['uid' => 'test2', 'displayName' => 'Test user 2', 'groups' => ['groupA']],
+ ],
+ ['exact' => [], 'wide' => []],
+ ['core' => ['shareapi_allow_share_dialog_user_enumeration' => 'no']],
+ ],
+ [
+ 'test1',
+ ['groupA'],
+ [
+ ['uid' => 'test1', 'displayName' => 'Test user 1', 'groups' => ['groupA']],
+ ['uid' => 'test2', 'displayName' => 'Test user 2', 'groups' => ['groupA']],
+ ],
+ ['exact' => ['test1'], 'wide' => []],
+ ['core' => ['shareapi_allow_share_dialog_user_enumeration' => 'no']],
+ ],
+ [
+ 'test1',
+ ['groupA'],
+ [
+ ['uid' => 'test1', 'displayName' => 'Test user 1', 'groups' => ['groupA']],
+ ['uid' => 'test2', 'displayName' => 'Test user 2', 'groups' => ['groupA']],
+ ],
+ ['exact' => [], 'wide' => []],
+ [
+ 'core' => [
+ 'shareapi_allow_share_dialog_user_enumeration' => 'no',
+ 'shareapi_restrict_user_enumeration_full_match_userid' => 'no',
+ ],
+ ]
+ ],
+ [
+ 'Test user 1',
+ ['groupA'],
+ [
+ ['uid' => 'test1', 'displayName' => 'Test user 1', 'groups' => ['groupA']],
+ ['uid' => 'test2', 'displayName' => 'Test user 2', 'groups' => ['groupA']],
+ ],
+ ['exact' => ['test1'], 'wide' => []],
+ [
+ 'core' => [
+ 'shareapi_allow_share_dialog_user_enumeration' => 'no',
+ 'shareapi_restrict_user_enumeration_full_match_userid' => 'no',
+ ],
+ ]
+ ],
+ [
+ 'Test user 1',
+ ['groupA'],
+ [
+ ['uid' => 'test1', 'displayName' => 'Test user 1 (Second displayName for user 1)', 'groups' => ['groupA']],
+ ['uid' => 'test2', 'displayName' => 'Test user 2 (Second displayName for user 2)', 'groups' => ['groupA']],
+ ],
+ ['exact' => [], 'wide' => []],
+ ['core' => ['shareapi_allow_share_dialog_user_enumeration' => 'no'],
+ ]
+ ],
+ [
+ 'Test user 1',
+ ['groupA'],
+ [
+ ['uid' => 'test1', 'displayName' => 'Test user 1 (Second displayName for user 1)', 'groups' => ['groupA']],
+ ['uid' => 'test2', 'displayName' => 'Test user 2 (Second displayName for user 2)', 'groups' => ['groupA']],
+ ],
+ ['exact' => ['test1'], 'wide' => []],
+ [
+ 'core' => [
+ 'shareapi_allow_share_dialog_user_enumeration' => 'no',
+ 'shareapi_restrict_user_enumeration_full_match_ignore_second_display_name' => 'yes',
+ ],
+ ]
],
[
'test1',
['uid' => 'test2', 'groups' => ['groupB']],
],
['exact' => ['test1'], 'wide' => []],
+ ['core' => ['shareapi_restrict_user_enumeration_to_group' => 'yes']],
],
[
'test',
['uid' => 'test2', 'groups' => ['groupB', 'groupA']],
],
['exact' => [], 'wide' => ['test1', 'test2']],
+ ['core' => ['shareapi_restrict_user_enumeration_to_group' => 'yes']],
],
[
'test',
['uid' => 'test2', 'groups' => ['groupB', 'groupA']],
],
['exact' => [], 'wide' => ['test1', 'test2']],
+ ['core' => ['shareapi_restrict_user_enumeration_to_group' => 'yes']],
],
[
'test',
['uid' => 'test2', 'groups' => ['groupB', 'groupA']],
],
['exact' => [], 'wide' => ['test1', 'test2']],
+ ['core' => ['shareapi_restrict_user_enumeration_to_group' => 'yes']],
],
[
'test',
['uid' => 'test2', 'groups' => ['groupB', 'groupA']],
],
['exact' => [], 'wide' => []],
+ ['core' => ['shareapi_restrict_user_enumeration_to_group' => 'yes']],
],
[
'test',
['uid' => 'test2', 'groups' => []],
],
['exact' => [], 'wide' => []],
+ ['core' => ['shareapi_restrict_user_enumeration_to_group' => 'yes']],
],
[
'test',
['uid' => 'test2', 'groups' => []],
],
['exact' => [], 'wide' => []],
+ ['core' => ['shareapi_restrict_user_enumeration_to_group' => 'yes']],
],
];
}
/**
* @dataProvider dataSearchEnumeration
*/
- public function testSearchEnumerationLimit($search, $userGroups, $matchingUsers, $result) {
- $this->mockConfig(false, true, true);
+ public function testSearchEnumerationLimit($search, $userGroups, $matchingUsers, $result, $mockedSettings) {
+ $this->mockConfig($mockedSettings);
$userResults = [];
foreach ($matchingUsers as $user) {
$userResults[$user['uid']] = $user['uid'];
}
- $mappedResultExact = array_map(function ($user) {
- return ['label' => $user, 'value' => ['shareType' => 0, 'shareWith' => $user], 'icon' => 'icon-user', 'subline' => null, 'status' => [], 'shareWithDisplayNameUnique' => $user];
+ $usersById = [];
+ foreach ($matchingUsers as $user) {
+ $usersById[$user['uid']] = $user;
+ }
+
+ $mappedResultExact = array_map(function ($user) use ($usersById, $search) {
+ return [
+ 'label' => $search === $user ? $user : $usersById[$user]['displayName'],
+ 'value' => ['shareType' => 0, 'shareWith' => $user],
+ 'icon' => 'icon-user',
+ 'subline' => null,
+ 'status' => [],
+ 'shareWithDisplayNameUnique' => $user,
+ ];
}, $result['exact']);
$mappedResultWide = array_map(function ($user) {
- return ['label' => $user, 'value' => ['shareType' => 0, 'shareWith' => $user], 'icon' => 'icon-user', 'subline' => null, 'status' => [], 'shareWithDisplayNameUnique' => $user];
+ return [
+ 'label' => $user,
+ 'value' => ['shareType' => 0, 'shareWith' => $user],
+ 'icon' => 'icon-user',
+ 'subline' => null,
+ 'status' => [],
+ 'shareWithDisplayNameUnique' => $user,
+ ];
}, $result['wide']);
$this->userManager
}
return null;
});
+ $this->userManager
+ ->method('searchDisplayName')
+ ->willReturnCallback(function ($search) use ($matchingUsers) {
+ $users = array_filter(
+ $matchingUsers,
+ function ($user) use ($search) {
+ return str_contains(strtolower($user['displayName']), strtolower($search));
+ });
+ return array_map(
+ function ($user) {
+ return $this->getUserMock($user['uid'], $user['displayName']);
+ },
+ $users
+ );
+ });
$this->groupManager->method('displayNamesInGroup')
->willReturn($userResults);