Search in sources :

Example 6 with GlobalConfigurationModelToConcreteConversionService

use of com.synopsys.integration.alert.web.api.config.GlobalConfigurationModelToConcreteConversionService in project hub-alert by blackducksoftware.

the class ConfigActionTestIT method deleteSensitiveFieldFromConfig.

@Test
void deleteSensitiveFieldFromConfig() {
    GlobalConfigurationModelToConcreteConversionService conversionService = new GlobalConfigurationModelToConcreteConversionService(List.of(), descriptorMap);
    AuthorizationManager authorizationManager = Mockito.mock(AuthorizationManager.class);
    Mockito.when(authorizationManager.hasDeletePermission(Mockito.anyString(), Mockito.anyString())).thenReturn(Boolean.TRUE);
    Mockito.when(authorizationManager.hasWritePermission(Mockito.anyString(), Mockito.anyString())).thenReturn(Boolean.TRUE);
    ConfigActions configActions = new ConfigActions(authorizationManager, descriptorAccessor, configurationModelConfigurationAccessor, fieldModelProcessor, descriptorProcessor, configurationFieldModelConverter, descriptorMap, pkixErrorResponseFactory, encryptionUtility, settingsDescriptorKey, conversionService);
    ConfigurationFieldModel proxyHost = ConfigurationFieldModel.create(ProxyManager.KEY_PROXY_HOST);
    proxyHost.setFieldValue("proxyHost");
    ConfigurationFieldModel proxyPort = ConfigurationFieldModel.create(ProxyManager.KEY_PROXY_PORT);
    proxyPort.setFieldValue("80");
    ConfigurationFieldModel proxyUsername = ConfigurationFieldModel.create(ProxyManager.KEY_PROXY_USERNAME);
    proxyUsername.setFieldValue("username");
    ConfigurationFieldModel proxyPassword = ConfigurationFieldModel.createSensitive(ProxyManager.KEY_PROXY_PWD);
    proxyPassword.setFieldValue("somestuff");
    ConfigurationFieldModel encryptionPassword = ConfigurationFieldModel.createSensitive(SettingsDescriptor.KEY_ENCRYPTION_PWD);
    encryptionPassword.setFieldValue("pants");
    ConfigurationFieldModel encryptionSalt = ConfigurationFieldModel.createSensitive(SettingsDescriptor.KEY_ENCRYPTION_GLOBAL_SALT);
    encryptionSalt.setFieldValue("salty pants");
    ConfigurationModel configurationModel = configurationModelConfigurationAccessor.createConfiguration(settingsDescriptorKey, ConfigContextEnum.GLOBAL, Set.of(proxyHost, proxyPort, proxyUsername, proxyPassword, encryptionPassword, encryptionSalt));
    FieldValueModel proxyHostFieldValue = new FieldValueModel(Set.of("proxyHost"), true);
    FieldValueModel proxyPortFieldValue = new FieldValueModel(Set.of("80"), true);
    FieldValueModel proxyUsernameFieldValue = new FieldValueModel(Set.of(), false);
    FieldValueModel proxyPasswordFieldValue = new FieldValueModel(Set.of(), false);
    FieldValueModel encryptionPasswordFieldValue = new FieldValueModel(Set.of("encryptionPassword"), true);
    FieldValueModel encryptionSaltFieldValue = new FieldValueModel(Set.of("sodiumChloride"), true);
    Long longConfigId = configurationModel.getConfigurationId();
    String configId = String.valueOf(longConfigId);
    FieldModel fieldModel = new FieldModel(configId, settingsDescriptorKey.getUniversalKey(), ConfigContextEnum.GLOBAL.name(), new HashMap<>(Map.of(ProxyManager.KEY_PROXY_HOST, proxyHostFieldValue, ProxyManager.KEY_PROXY_PORT, proxyPortFieldValue, ProxyManager.KEY_PROXY_USERNAME, proxyUsernameFieldValue, ProxyManager.KEY_PROXY_PWD, proxyPasswordFieldValue, SettingsDescriptor.KEY_ENCRYPTION_PWD, encryptionPasswordFieldValue, SettingsDescriptor.KEY_ENCRYPTION_GLOBAL_SALT, encryptionSaltFieldValue)));
    ActionResponse<FieldModel> response = configActions.update(longConfigId, fieldModel);
    assertTrue(response.hasContent());
    FieldModel updatedConfig = response.getContent().orElseThrow(() -> new AssertionFailedError("content missing from response."));
    assertTrue(updatedConfig.getFieldValue(ProxyManager.KEY_PROXY_USERNAME).isEmpty(), "Need to remove username in order to remove password as well.");
    assertTrue(updatedConfig.getFieldValue(ProxyManager.KEY_PROXY_PWD).isEmpty(), "Saving an empty values should remove it from DB.");
}
Also used : ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) GlobalConfigurationModelToConcreteConversionService(com.synopsys.integration.alert.web.api.config.GlobalConfigurationModelToConcreteConversionService) ConfigActions(com.synopsys.integration.alert.web.api.config.ConfigActions) AuthorizationManager(com.synopsys.integration.alert.common.security.authorization.AuthorizationManager) ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) FieldModel(com.synopsys.integration.alert.common.rest.model.FieldModel) AssertionFailedError(junit.framework.AssertionFailedError) FieldValueModel(com.synopsys.integration.alert.common.rest.model.FieldValueModel) AlertIntegrationTest(com.synopsys.integration.alert.util.AlertIntegrationTest) Test(org.junit.jupiter.api.Test)

Aggregations

GlobalConfigurationModelToConcreteConversionService (com.synopsys.integration.alert.web.api.config.GlobalConfigurationModelToConcreteConversionService)6 FieldModel (com.synopsys.integration.alert.common.rest.model.FieldModel)5 AuthorizationManager (com.synopsys.integration.alert.common.security.authorization.AuthorizationManager)5 AlertIntegrationTest (com.synopsys.integration.alert.util.AlertIntegrationTest)5 ConfigActions (com.synopsys.integration.alert.web.api.config.ConfigActions)5 Test (org.junit.jupiter.api.Test)5 AlertConfigurationException (com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException)4 EmailGlobalCrudActions (com.synopsys.integration.alert.channel.email.action.EmailGlobalCrudActions)4 EmailGlobalConfigurationModelConverter (com.synopsys.integration.alert.channel.email.convert.EmailGlobalConfigurationModelConverter)4 EmailGlobalConfigurationModelSaveActions (com.synopsys.integration.alert.channel.email.convert.EmailGlobalConfigurationModelSaveActions)4 GlobalConfigurationModelToConcreteSaveActions (com.synopsys.integration.alert.common.action.api.GlobalConfigurationModelToConcreteSaveActions)4 FieldValueModel (com.synopsys.integration.alert.common.rest.model.FieldValueModel)4 EmailGlobalConfigModel (com.synopsys.integration.alert.service.email.model.EmailGlobalConfigModel)4 EmailGlobalConfigAccessor (com.synopsys.integration.alert.channel.email.database.accessor.EmailGlobalConfigAccessor)3 EmailGlobalConfigurationValidator (com.synopsys.integration.alert.channel.email.validator.EmailGlobalConfigurationValidator)3 DescriptorMap (com.synopsys.integration.alert.common.descriptor.DescriptorMap)3 DescriptorProcessor (com.synopsys.integration.alert.common.descriptor.DescriptorProcessor)3 ConfigContextEnum (com.synopsys.integration.alert.common.enumeration.ConfigContextEnum)3 ConfigurationModelConfigurationAccessor (com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor)3 DescriptorAccessor (com.synopsys.integration.alert.common.persistence.accessor.DescriptorAccessor)3