/** * Returns the property values (including information about their descriptors and overwritten values) for * the given resource in the specified context. * * @param resourceId * @param contextId * @return */ public List<ResourceEditProperty> getPropertiesForResource(Integer resourceId, Integer contextId) { ResourceEntity resource = entityManager.find(ResourceEntity.class, resourceId); ContextEntity context = entityManager.find(ContextEntity.class, contextId); List<ResourceEditProperty> properties = propertyEditingService.loadPropertiesForEditResource( resource.getId(), resource.getResourceType(), context); if (permissionBoundary.hasPermission(Permission.RESOURCE_PROPERTY_DECRYPT, context, Action.ALL, resource, null)) { return propertyValueService.decryptProperties(properties); } return properties; }
@Test public void resetPropertyValueOnResourceForContextShouldBeSuccessfullWhenResourceUpdatePermissionIsPresentButResourcePropertyDecryptIsMissing() throws Exception { // given String resourceGroupName = "resourceGroupName"; String releaseName = "releaseName"; String contextName = "contextName"; String propertyName = "propertyName"; String propertyValue = "propertyValue"; String typeName = "resourceGroupTypeName"; List<ResourceEditProperty> properties = new ArrayList<>(); properties.add(new ResourceEditPropertyBuilder().withDisplayAndTechKeyName(propertyName).withValue(propertyValue).withDescriptorId(12).build()); ContextEntity contextMock = mock(ContextEntity.class); ResourceEntity resource = createWithIdNameAndTypeName(1, resourceGroupName, typeName); when(resourceLocatorMock.getResourceByGroupNameAndRelease(resourceGroupName, releaseName)).thenReturn(resource); when(contextLocatorMock.getContextByName(contextName)).thenReturn(contextMock); when(propertyEditingServiceMock.loadPropertiesForEditResource(anyInt(), any(ResourceTypeEntity.class), any(ContextEntity.class))).thenReturn(properties); when(permissionBoundaryMock.hasPermission(Permission.RESOURCE, contextMock, Action.UPDATE, resource, null)).thenReturn(true); when(permissionBoundaryMock.hasPermission(Permission.RESOURCE_PROPERTY_DECRYPT, contextMock, Action.ALL, resource, null)).thenReturn(false); when(entityManagerMock.merge(resource)).thenReturn(resource); when(entityManagerMock.merge(contextMock)).thenReturn(contextMock); // when Assert.assertFalse(properties.isEmpty()); editor.resetPropertyValueOnResourceForContext(resourceGroupName, releaseName, contextName, propertyName); }
@Test(expected = NotAuthorizedException.class) public void setPropertyValueOnResourceForContextShouldThrowExceptionWhenResourceUpdatePermissionIsMissing() throws Exception { // given String resourceGroupName = "resourceGroupName"; String releaseName = "releaseName"; String contextName = "contextName"; String propertyName = "propertyName"; String propertyValue = "propertyValue"; String typeName = "resourceGroupTypeName"; List<ResourceEditProperty> properties = new ArrayList<>(); properties.add(new ResourceEditPropertyBuilder().withDisplayAndTechKeyName(propertyName).withValue(propertyValue).build()); ResourceEntity resource = createWithIdNameAndTypeName(1, resourceGroupName, typeName); ContextEntity contextMock = mock(ContextEntity.class); when(resourceLocatorMock.getResourceByGroupNameAndRelease(resourceGroupName, releaseName)).thenReturn(resource); when(contextLocatorMock.getContextByName(contextName)).thenReturn(contextMock); when(propertyEditingServiceMock.loadPropertiesForEditResource(anyInt(), any(ResourceTypeEntity.class), any(ContextEntity.class))).thenReturn(properties); when(permissionBoundaryMock.hasPermission(Permission.RESOURCE, contextMock, Action.UPDATE, null, null)).thenReturn(false); when(permissionBoundaryMock.hasPermission(Permission.RESOURCE_PROPERTY_DECRYPT, contextMock, Action.ALL, resource, null)).thenReturn(false); // when Assert.assertFalse(properties.isEmpty()); editor.setPropertyValueOnResourceForContext(resourceGroupName, releaseName, contextName, propertyName, propertyValue); }
@Test public void setPropertyValueOnResourceForContextShouldSetPropertyValue() throws Exception { // given String resourceGroupName = "resourceGroupName"; String releaseName = "releaseName"; String contextName = "contextName"; String propertyName = "propertyName"; String propertyValue = "propertyValue"; String typeName = "resourceGroupTypeName"; List<ResourceEditProperty> properties = new ArrayList<>(); properties.add(new ResourceEditPropertyBuilder().withDisplayAndTechKeyName(propertyName).withValue(propertyValue).build()); ContextEntity contextMock = mock(ContextEntity.class); ResourceEntity resource = createWithIdNameAndTypeName(1, resourceGroupName, typeName); when(resourceLocatorMock.getResourceByGroupNameAndRelease(resourceGroupName, releaseName)).thenReturn(resource); when(contextLocatorMock.getContextByName(contextName)).thenReturn(contextMock); when(propertyEditingServiceMock.loadPropertiesForEditResource(any(Integer.class), any(ResourceTypeEntity.class), any(ContextEntity.class))).thenReturn(properties); when(permissionBoundaryMock.hasPermission(Permission.RESOURCE, contextMock, Action.UPDATE, resource, null)).thenReturn(true); when(permissionBoundaryMock.hasPermission(Permission.RESOURCE_PROPERTY_DECRYPT, contextMock, Action.ALL, resource, null)).thenReturn(true); setupMocksForSinglePropertiesModificationsFor(resource); // when Assert.assertFalse(properties.isEmpty()); editor.setPropertyValueOnResourceForContext(resourceGroupName, releaseName, contextName, propertyName, propertyValue); //then verify(propertyValueServiceMock).setPropertyValue(Matchers.any(ContextDependency.class), Matchers.anyInt(), Matchers.eq(propertyValue)); }
.loadPropertiesForEditResource(resourceByNameAndRelease.getId(), resourceByNameAndRelease.getResourceType(), context);
.loadPropertiesForEditResource(resource.getId(), resource.getResourceType(), context);