use of com.enonic.xp.security.Group in project xp by enonic.
the class GetMembershipsHandlerTest method testGetUserMembershipsWithRoleAndGroup.
@Test
public void testGetUserMembershipsWithRoleAndGroup() {
final Role role = TestDataFixtures.getTestRole();
final Group group = TestDataFixtures.getTestGroup();
final PrincipalKeys principalKeys = PrincipalKeys.from(role.getKey(), group.getKey());
Mockito.when(securityService.getMemberships(PrincipalKey.from("user:myIdProvider:userId"))).thenReturn(principalKeys);
Mockito.when(securityService.getPrincipals(principalKeys)).thenReturn(Principals.from(role, group));
runFunction("/test/getMemberships-test.js", "getUserMembershipsWithRoleAndGroup");
}
use of com.enonic.xp.security.Group in project xp by enonic.
the class GetMembershipsHandlerTest method testGetUserMemberships.
@Test
public void testGetUserMemberships() {
final Group group = TestDataFixtures.getTestGroup();
final PrincipalKeys principalKeys = PrincipalKeys.from(group.getKey());
final PrincipalKey pKey = PrincipalKey.from("user:myIdProvider:userId");
Mockito.when(securityService.getMemberships(pKey)).thenReturn(principalKeys);
Mockito.verify(securityService, Mockito.never()).getAllMemberships(pKey);
Mockito.when(securityService.getPrincipals(principalKeys)).thenReturn(Principals.from(group));
runFunction("/test/getMemberships-test.js", "getUserMemberships");
}
use of com.enonic.xp.security.Group in project xp by enonic.
the class SecurityServiceImplTest method testCreateGroup.
@Test
public void testCreateGroup() throws Exception {
runAsAdmin(() -> {
final PrincipalKey groupKey1 = PrincipalKey.ofGroup(SYSTEM, "Group-a");
final CreateGroupParams createGroup = CreateGroupParams.create().groupKey(groupKey1).displayName("Group A").description("Group A Description").build();
final PrincipalKey groupKey2 = PrincipalKey.ofGroup(SYSTEM, "group-b");
final CreateGroupParams createGroup2 = CreateGroupParams.create().groupKey(groupKey2).displayName("Group B").build();
final Group group1 = securityService.createGroup(createGroup);
final Group group2 = securityService.createGroup(createGroup2);
refresh();
final Group createdGroup1 = securityService.getGroup(groupKey1).get();
final Group createdGroup2 = securityService.getGroup(groupKey2).get();
assertEquals("Group A", group1.getDisplayName());
assertEquals("Group A", createdGroup1.getDisplayName());
assertEquals("Group A Description", group1.getDescription());
assertEquals("Group A Description", createdGroup1.getDescription());
assertEquals("Group B", group2.getDisplayName());
assertEquals("Group B", createdGroup2.getDisplayName());
assertNull(group2.getDescription());
assertNull(createdGroup2.getDescription());
});
}
use of com.enonic.xp.security.Group in project xp by enonic.
the class GroupNodeTranslatorTest method toCreateNode.
@Test
public void toCreateNode() throws Exception {
final Group group = Group.create().displayName("My Group").key(PrincipalKey.ofGroup(IdProviderKey.system(), "group-a")).modifiedTime(Instant.now(clock)).description("my group a").build();
final CreateNodeParams createNodeParams = PrincipalNodeTranslator.toCreateNodeParams(group);
assertEquals("group-a", createNodeParams.getName());
final PropertyTree rootDataSet = createNodeParams.getData();
assertNotNull(rootDataSet);
assertEquals(4, rootDataSet.getTotalSize());
assertEquals(IdProviderKey.system().toString(), rootDataSet.getString(PrincipalPropertyNames.ID_PROVIDER_KEY));
assertEquals(PrincipalType.GROUP.toString(), rootDataSet.getString(PrincipalPropertyNames.PRINCIPAL_TYPE_KEY));
assertEquals("My Group", rootDataSet.getString(PrincipalPropertyNames.DISPLAY_NAME_KEY));
assertEquals("my group a", rootDataSet.getString(PrincipalPropertyNames.DESCRIPTION_KEY));
}
Aggregations