use of com.synopsys.integration.alert.database.user.RoleEntity in project hub-alert by blackducksoftware.
the class DefaultRoleAccessorTest method updatePermissionsForRole.
@Test
public void updatePermissionsForRole() throws Exception {
final String roleName = "roleName";
final String contextString = "context-test";
final String descriptorName = "descriptorName";
RoleEntity roleEntity = new RoleEntity(roleName, true);
roleEntity.setId(1L);
ConfigContextEntity configContextEntity = new ConfigContextEntity(contextString);
configContextEntity.setId(1L);
RegisteredDescriptorEntity registeredDescriptorEntity = new RegisteredDescriptorEntity(descriptorName, 1L);
registeredDescriptorEntity.setId(1L);
PermissionKey permissionKey = new PermissionKey(contextString, descriptorName);
PermissionMatrixModel permissionMatrix = new PermissionMatrixModel(Map.of(permissionKey, AccessOperation.READ.getBit() + AccessOperation.WRITE.getBit()));
PermissionMatrixRelation permissionMatrixRelation = new PermissionMatrixRelation(roleEntity.getId(), configContextEntity.getId(), registeredDescriptorEntity.getId(), AccessOperation.READ.getBit() + AccessOperation.WRITE.getBit());
Mockito.when(roleRepository.findByRoleName(Mockito.any())).thenReturn(Optional.of(roleEntity));
mockUpdateRoleOperations(permissionMatrixRelation, configContextEntity, registeredDescriptorEntity);
mockCreateModelFromPermission(configContextEntity, registeredDescriptorEntity);
DefaultRoleAccessor authorizationUtility = new DefaultRoleAccessor(roleRepository, userRoleRepository, permissionMatrixRepository, registeredDescriptorRepository, configContextRepository);
PermissionMatrixModel permissionMatrixModel = authorizationUtility.updatePermissionsForRole(roleName, permissionMatrix);
Mockito.verify(permissionMatrixRepository).saveAll(Mockito.any());
assertFalse(permissionMatrixModel.isEmpty());
assertEquals(permissionMatrix, permissionMatrixModel);
}
use of com.synopsys.integration.alert.database.user.RoleEntity in project hub-alert by blackducksoftware.
the class DefaultRoleAccessorTest method createRoleWithPermissions.
@Test
public void createRoleWithPermissions() {
final String roleName = "roleName";
final String contextString = "context-test";
final String descriptorName = "descriptorName";
RoleEntity roleEntity = new RoleEntity(roleName, true);
roleEntity.setId(1L);
ConfigContextEntity configContextEntity = new ConfigContextEntity(contextString);
configContextEntity.setId(1L);
RegisteredDescriptorEntity registeredDescriptorEntity = new RegisteredDescriptorEntity(descriptorName, 1L);
registeredDescriptorEntity.setId(1L);
PermissionKey permissionKey = new PermissionKey(contextString, descriptorName);
PermissionMatrixModel permissionMatrixModel = new PermissionMatrixModel(Map.of(permissionKey, AccessOperation.READ.getBit() + AccessOperation.WRITE.getBit()));
PermissionMatrixRelation permissionMatrixRelation = new PermissionMatrixRelation(roleEntity.getId(), configContextEntity.getId(), registeredDescriptorEntity.getId(), AccessOperation.READ.getBit() + AccessOperation.WRITE.getBit());
Mockito.when(roleRepository.save(Mockito.any())).thenReturn(new RoleEntity(roleName, true));
mockUpdateRoleOperations(permissionMatrixRelation, configContextEntity, registeredDescriptorEntity);
mockCreateModelFromPermission(configContextEntity, registeredDescriptorEntity);
DefaultRoleAccessor authorizationUtility = new DefaultRoleAccessor(roleRepository, userRoleRepository, permissionMatrixRepository, registeredDescriptorRepository, configContextRepository);
UserRoleModel userRoleModel = authorizationUtility.createRoleWithPermissions(roleName, permissionMatrixModel);
Mockito.verify(permissionMatrixRepository).deleteAll(Mockito.any());
assertEquals(roleName, userRoleModel.getName());
assertTrue(userRoleModel.isCustom());
assertEquals(permissionMatrixModel, userRoleModel.getPermissions());
}
use of com.synopsys.integration.alert.database.user.RoleEntity in project hub-alert by blackducksoftware.
the class DefaultRoleAccessorTest method updateRoleNameTest.
@Test
public void updateRoleNameTest() throws Exception {
final String roleName = "roleName";
final Long roleId = 1L;
RoleEntity roleEntity = new RoleEntity(DefaultUserRole.ALERT_USER.name(), true);
roleEntity.setId(1L);
Mockito.when(roleRepository.findById(Mockito.any())).thenReturn(Optional.of(roleEntity));
DefaultRoleAccessor authorizationUtility = new DefaultRoleAccessor(roleRepository, userRoleRepository, permissionMatrixRepository, registeredDescriptorRepository, configContextRepository);
authorizationUtility.updateRoleName(roleId, roleName);
Mockito.verify(roleRepository).save(Mockito.any());
}
use of com.synopsys.integration.alert.database.user.RoleEntity in project hub-alert by blackducksoftware.
the class DefaultRoleAccessorTest method getRolesTest.
@Test
public void getRolesTest() {
RoleEntity roleEntity = new RoleEntity(DefaultUserRole.ALERT_USER.name(), true);
roleEntity.setId(1L);
Mockito.when(roleRepository.findAll()).thenReturn(List.of(roleEntity));
DefaultRoleAccessor authorizationUtility = new DefaultRoleAccessor(roleRepository, userRoleRepository, permissionMatrixRepository, registeredDescriptorRepository, configContextRepository);
Set<UserRoleModel> userRoleModelsSet = authorizationUtility.getRoles();
UserRoleModel expectedUserRoleModel = createUserRoleModel(1L, DefaultUserRole.ALERT_USER.name(), true);
assertEquals(1, userRoleModelsSet.size());
assertTrue(userRoleModelsSet.contains(expectedUserRoleModel));
}
use of com.synopsys.integration.alert.database.user.RoleEntity in project hub-alert by blackducksoftware.
the class DefaultRoleAccessorTest method getRolesByRoleIdsTest.
@Test
public void getRolesByRoleIdsTest() {
RoleEntity roleEntity = new RoleEntity(DefaultUserRole.ALERT_USER.name(), true);
roleEntity.setId(1L);
Mockito.when(roleRepository.findById(Mockito.any())).thenReturn(Optional.of(roleEntity));
DefaultRoleAccessor authorizationUtility = new DefaultRoleAccessor(roleRepository, userRoleRepository, permissionMatrixRepository, registeredDescriptorRepository, configContextRepository);
Set<UserRoleModel> userRoleModelsSet = authorizationUtility.getRoles(List.of(1L));
UserRoleModel expectedUserRoleModel = createUserRoleModel(1L, DefaultUserRole.ALERT_USER.name(), true);
assertEquals(1, userRoleModelsSet.size());
assertTrue(userRoleModelsSet.contains(expectedUserRoleModel));
}
Aggregations