Skip to content

Commit

Permalink
test: group provisioning with whitelist regex
Browse files Browse the repository at this point in the history
Signed-off-by: Armin Berger <[email protected]>
  • Loading branch information
bergerar committed Oct 29, 2024
1 parent 9e0b2ae commit 06eee6e
Showing 1 changed file with 48 additions and 5 deletions.
53 changes: 48 additions & 5 deletions tests/unit/Service/ProvisioningServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,9 @@ public function dataProvisionUserGroups() {
'displayName' => 'groupName1'
]
],
]
],
'',
true,
],
[
'1',
Expand All @@ -177,30 +179,71 @@ public function dataProvisionUserGroups() {
'groups' => [
'group2'
],
]
],
'',
true,
],
[
'1_Group_Import',
'Imported from OIDC',
(object)[
'groups' => [
(object)[
'gid' => '1_Group_Import',
'displayName' => 'Imported from OIDC',
],
(object)[
'gid' => '10_Group_NoImport',
'displayName' => 'Not Imported',
]
],
],
'/^1_/',
false
],
[
'1',
'users_nextcloud',
(object)[
'groups' => [
'users_nextcloud',
'users',
],
],
'/nextcloud/',
false,
],
];
}

/** @dataProvider dataProvisionUserGroups */
public function testProvisionUserGroups(string $gid, string $displayName, object $payload): void {
public function testProvisionUserGroups(string $gid, string $displayName, object $payload, string $group_whitelist, bool $expect_delete_local_group): void {
$user = $this->createMock(IUser::class);
$group = $this->createMock(IGroup::class);
$local_group = $this->createMock(IGroup::class);
$providerId = 421;

$this->providerService
->method('getSetting')
->will($this->returnValueMap(
[
[$providerId, ProviderService::SETTING_GROUP_WHITELIST_REGEX, '', ''],
[$providerId, ProviderService::SETTING_GROUP_WHITELIST_REGEX, '', $group_whitelist],
[$providerId, ProviderService::SETTING_MAPPING_GROUPS, 'groups', 'groups'],
]
));

$this->groupManager
->method('getUserGroups')
->with($user)
->willReturn([]);
->willReturn([$local_group]);

$local_group
->method('getGID')
->willReturn('local_group');

$local_group->expects($expect_delete_local_group ? self::once() : self::never())
->method('removeUser')
->with($user);

$this->idService->method('getId')
->willReturn($gid);
Expand Down

0 comments on commit 06eee6e

Please sign in to comment.