@@ -188,7 +188,96 @@ public function testGetContactsWithoutAvatarURI(): void {
188188 $ this ->assertEquals ('https://photo ' , $ entries [1 ]->getAvatar ());
189189 }
190190
191- public function testGetContactsWhenUserIsInExcludeGroups (): void {
191+ public static function dataGetContactsWhenUserIsInExcludeGroups (): array {
192+ return [
193+ ['yes ' , '[] ' , [], ['user123 ' , 'user12345 ' ]],
194+ ['yes ' , '["excludedGroup1"] ' , [], ['user123 ' , 'user12345 ' ]],
195+ ['yes ' , '["excludedGroup1"] ' , ['anotherGroup1 ' ], ['user123 ' , 'user12345 ' ]],
196+ ['yes ' , '["excludedGroup1"] ' , ['anotherGroup1 ' , 'anotherGroup2 ' , 'anotherGroup3 ' ], ['user123 ' , 'user12345 ' ]],
197+ ['yes ' , '["excludedGroup1"] ' , ['excludedGroup1 ' ], []],
198+ ['yes ' , '["excludedGroup1"] ' , ['anotherGroup1 ' , 'excludedGroup1 ' ], ['user123 ' , 'user12345 ' ]],
199+ ['yes ' , '["excludedGroup1"] ' , ['excludedGroup1 ' , 'anotherGroup1 ' , 'anotherGroup2 ' , 'anotherGroup3 ' ], ['user123 ' , 'user12345 ' ]],
200+ ['yes ' , '["excludedGroup1", "excludedGroup2", "excludedGroup3"] ' , [], ['user123 ' , 'user12345 ' ]],
201+ ['yes ' , '["excludedGroup1", "excludedGroup2", "excludedGroup3"] ' , ['anotherGroup1 ' ], ['user123 ' , 'user12345 ' ]],
202+ ['yes ' , '["excludedGroup1", "excludedGroup2", "excludedGroup3"] ' , ['anotherGroup1 ' , 'anotherGroup2 ' , 'anotherGroup3 ' ], ['user123 ' , 'user12345 ' ]],
203+ ['yes ' , '["excludedGroup1", "excludedGroup2", "excludedGroup3"] ' , ['excludedGroup1 ' ], []],
204+ ['yes ' , '["excludedGroup1", "excludedGroup2", "excludedGroup3"] ' , ['excludedGroup2 ' ], []],
205+ ['yes ' , '["excludedGroup1", "excludedGroup2", "excludedGroup3"] ' , ['excludedGroup3 ' ], []],
206+ ['yes ' , '["excludedGroup1", "excludedGroup2", "excludedGroup3"] ' , ['excludedGroup1 ' , 'excludedGroup2 ' , 'excludedGroup3 ' ], []],
207+ ['yes ' , '["excludedGroup1", "excludedGroup2", "excludedGroup3"] ' , ['anotherGroup1 ' , 'excludedGroup1 ' ], ['user123 ' , 'user12345 ' ]],
208+ ['yes ' , '["excludedGroup1", "excludedGroup2", "excludedGroup3"] ' , ['anotherGroup1 ' , 'excludedGroup2 ' , 'anotherGroup2 ' , 'anotherGroup3 ' ], ['user123 ' , 'user12345 ' ]],
209+ ['yes ' , '["excludedGroup1", "excludedGroup2", "excludedGroup3"] ' , ['excludedGroup3 ' , 'anotherGroup1 ' , 'anotherGroup2 ' , 'anotherGroup3 ' ], ['user123 ' , 'user12345 ' ]],
210+ ['allow ' , '[] ' , [], []],
211+ ['allow ' , '["allowedGroup1"] ' , [], []],
212+ ['allow ' , '["allowedGroup1"] ' , ['anotherGroup1 ' ], []],
213+ ['allow ' , '["allowedGroup1"] ' , ['anotherGroup1 ' , 'anotherGroup2 ' , 'anotherGroup3 ' ], []],
214+ ['allow ' , '["allowedGroup1"] ' , ['allowedGroup1 ' ], ['user123 ' , 'user12345 ' ]],
215+ ['allow ' , '["allowedGroup1"] ' , ['anotherGroup1 ' , 'allowedGroup1 ' ], ['user123 ' , 'user12345 ' ]],
216+ ['allow ' , '["allowedGroup1"] ' , ['allowedGroup1 ' , 'anotherGroup1 ' , 'anotherGroup2 ' , 'anotherGroup3 ' ], ['user123 ' , 'user12345 ' ]],
217+ ['allow ' , '["allowedGroup1", "allowedGroup2", "allowedGroup3"] ' , [], []],
218+ ['allow ' , '["allowedGroup1", "allowedGroup2", "allowedGroup3"] ' , ['anotherGroup1 ' ], []],
219+ ['allow ' , '["allowedGroup1", "allowedGroup2", "allowedGroup3"] ' , ['anotherGroup1 ' , 'anotherGroup2 ' , 'anotherGroup3 ' ], []],
220+ ['allow ' , '["allowedGroup1", "allowedGroup2", "allowedGroup3"] ' , ['allowedGroup1 ' ], ['user123 ' , 'user12345 ' ]],
221+ ['allow ' , '["allowedGroup1", "allowedGroup2", "allowedGroup3"] ' , ['allowedGroup2 ' ], ['user123 ' , 'user12345 ' ]],
222+ ['allow ' , '["allowedGroup1", "allowedGroup2", "allowedGroup3"] ' , ['allowedGroup3 ' ], ['user123 ' , 'user12345 ' ]],
223+ ['allow ' , '["allowedGroup1", "allowedGroup2", "allowedGroup3"] ' , ['allowedGroup1 ' , 'allowedGroup2 ' , 'allowedGroup3 ' ], ['user123 ' , 'user12345 ' ]],
224+ ['allow ' , '["allowedGroup1", "allowedGroup2", "allowedGroup3"] ' , ['anotherGroup1 ' , 'allowedGroup1 ' ], ['user123 ' , 'user12345 ' ]],
225+ ['allow ' , '["allowedGroup1", "allowedGroup2", "allowedGroup3"] ' , ['anotherGroup1 ' , 'allowedGroup2 ' , 'anotherGroup2 ' , 'anotherGroup3 ' ], ['user123 ' , 'user12345 ' ]],
226+ ['allow ' , '["allowedGroup1", "allowedGroup2", "allowedGroup3"] ' , ['allowedGroup3 ' , 'anotherGroup1 ' , 'anotherGroup2 ' , 'anotherGroup3 ' ], ['user123 ' , 'user12345 ' ]],
227+ ];
228+ }
229+
230+ /**
231+ * @dataProvider dataGetContactsWhenUserIsInExcludeGroups
232+ */
233+ public function testGetContactsWhenUserIsInExcludeGroups (string $ excludeGroups , string $ excludeGroupsList , array $ currentUserGroupIds , array $ expectedUids ): void {
234+ $ this ->config
235+ ->method ('getAppValue ' )
236+ ->willReturnMap ([
237+ ['core ' , 'shareapi_allow_share_dialog_user_enumeration ' , 'yes ' , 'yes ' ],
238+ ['core ' , 'shareapi_restrict_user_enumeration_to_group ' , 'no ' , 'no ' ],
239+ ['core ' , 'shareapi_restrict_user_enumeration_to_phone ' , 'no ' , 'no ' ],
240+ ['core ' , 'shareapi_exclude_groups ' , 'no ' , $ excludeGroups ],
241+ ['core ' , 'shareapi_only_share_with_group_members ' , 'no ' , 'no ' ],
242+ ['core ' , 'shareapi_exclude_groups_list ' , '' , $ excludeGroupsList ],
243+ ['core ' , 'shareapi_only_share_with_group_members_exclude_group_list ' , '' , '[] ' ],
244+ ]);
245+
246+ /** @var IUser|MockObject $currentUser */
247+ $ currentUser = $ this ->createMock (IUser::class);
248+ $ currentUser ->expects ($ this ->exactly (2 ))
249+ ->method ('getUID ' )
250+ ->willReturn ('user001 ' );
251+
252+ $ this ->groupManager ->expects ($ this ->once ())
253+ ->method ('getUserGroupIds ' )
254+ ->with ($ this ->equalTo ($ currentUser ))
255+ ->willReturn ($ currentUserGroupIds );
256+
257+ $ this ->contactsManager ->expects ($ this ->once ())
258+ ->method ('search ' )
259+ ->with ($ this ->equalTo ('' ), $ this ->equalTo (['FN ' , 'EMAIL ' ]))
260+ ->willReturn ([
261+ [
262+ 'UID ' => 'user123 ' ,
263+ 'isLocalSystemBook ' => true
264+ ],
265+ [
266+ 'UID ' => 'user12345 ' ,
267+ 'isLocalSystemBook ' => true
268+ ],
269+ ]);
270+
271+
272+ $ entries = $ this ->contactsStore ->getContacts ($ currentUser , '' );
273+
274+ $ this ->assertCount (count ($ expectedUids ), $ entries );
275+ for ($ i = 0 ; $ i < count ($ expectedUids ); $ i ++) {
276+ $ this ->assertEquals ($ expectedUids [$ i ], $ entries [$ i ]->getProperty ('UID ' ));
277+ }
278+ }
279+
280+ public function testGetContactsOnlyShareIfInTheSameGroupWhenUserIsInExcludeGroups (): void {
192281 $ this ->config
193282 ->method ('getAppValue ' )
194283 ->willReturnMap ([
0 commit comments