Search in sources :

Example 6 with EncryptionUtility

use of com.synopsys.integration.alert.common.security.EncryptionUtility in project hub-alert by blackducksoftware.

the class ConfigurationFieldModelTest method convertDefinedFieldModelEmptyTest.

@Test
public void convertDefinedFieldModelEmptyTest() throws Exception {
    List<DefinedFieldModel> configFields = createConfigFields();
    EncryptionUtility encryptionUtility = Mockito.mock(EncryptionUtility.class);
    DescriptorAccessor descriptorAccessor = new MockDescriptorAccessor(configFields);
    List<DescriptorKey> descriptorKeys = createDescriptorKeyList();
    ConfigurationFieldModelConverter modelConverter = new ConfigurationFieldModelConverter(encryptionUtility, descriptorAccessor, descriptorKeys);
    Optional<ConfigurationFieldModel> optionalModel = modelConverter.convertFromDefinedFieldModel(new DefinedFieldModel(KEY_FIELD_1, ConfigContextEnum.GLOBAL, true), VALUE_FIELD_1, true);
    assertTrue(optionalModel.isEmpty());
}
Also used : ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) DefinedFieldModel(com.synopsys.integration.alert.common.persistence.model.DefinedFieldModel) MockDescriptorAccessor(com.synopsys.integration.alert.mock.MockDescriptorAccessor) DescriptorKey(com.synopsys.integration.alert.descriptor.api.model.DescriptorKey) MockDescriptorAccessor(com.synopsys.integration.alert.mock.MockDescriptorAccessor) DescriptorAccessor(com.synopsys.integration.alert.common.persistence.accessor.DescriptorAccessor) ConfigurationFieldModelConverter(com.synopsys.integration.alert.common.persistence.util.ConfigurationFieldModelConverter) EncryptionUtility(com.synopsys.integration.alert.common.security.EncryptionUtility) Test(org.junit.jupiter.api.Test)

Example 7 with EncryptionUtility

use of com.synopsys.integration.alert.common.security.EncryptionUtility in project hub-alert by blackducksoftware.

the class SettingsEncryptionValidatorTest method validateNotInitializedTest.

@Test
public void validateNotInitializedTest() {
    MockAlertProperties alertPropertiesNoEncryption = new MockAlertProperties();
    alertPropertiesNoEncryption.setEncryptionPassword("");
    alertPropertiesNoEncryption.setEncryptionSalt("");
    FilePersistenceUtil filePersistenceUtilWithoutProperties = new FilePersistenceUtil(alertPropertiesNoEncryption, gson);
    EncryptionUtility encryptionUtilityWithoutProperties = new EncryptionUtility(alertPropertiesNoEncryption, filePersistenceUtilWithoutProperties);
    SettingsEncryptionModel settingsEncryptionModel = new SettingsEncryptionModel();
    settingsEncryptionModel.setEncryptionPassword("password");
    settingsEncryptionModel.setEncryptionGlobalSalt("globalSalt");
    SettingsEncryptionValidator validator = new SettingsEncryptionValidator(encryptionUtilityWithoutProperties, systemMessageAccessor);
    ValidationResponseModel validationResponseModel = validator.validate(settingsEncryptionModel);
    assertFalse(validationResponseModel.hasErrors());
}
Also used : ValidationResponseModel(com.synopsys.integration.alert.common.rest.model.ValidationResponseModel) FilePersistenceUtil(com.synopsys.integration.alert.common.persistence.util.FilePersistenceUtil) SettingsEncryptionModel(com.synopsys.integration.alert.component.settings.encryption.model.SettingsEncryptionModel) MockAlertProperties(com.synopsys.integration.alert.test.common.MockAlertProperties) EncryptionUtility(com.synopsys.integration.alert.common.security.EncryptionUtility) Test(org.junit.jupiter.api.Test)

Example 8 with EncryptionUtility

use of com.synopsys.integration.alert.common.security.EncryptionUtility in project hub-alert by blackducksoftware.

the class AlertStartupInitializerTest method testInitializeConfigsEmptyInitializerList.

@Test
public void testInitializeConfigsEmptyInitializerList() throws Exception {
    Environment environment = Mockito.mock(Environment.class);
    DescriptorAccessor baseDescriptorAccessor = Mockito.mock(DescriptorAccessor.class);
    ConfigurationModelConfigurationAccessor baseConfigurationModelConfigurationAccessor = Mockito.mock(ConfigurationModelConfigurationAccessor.class);
    DescriptorMap descriptorMap = new DescriptorMap(List.of(), List.of());
    EncryptionUtility encryptionUtility = Mockito.mock(EncryptionUtility.class);
    Mockito.when(encryptionUtility.isInitialized()).thenReturn(Boolean.TRUE);
    EnvironmentVariableUtility environmentVariableUtility = new EnvironmentVariableUtility(environment);
    EnvironmentVariableProcessor environmentVariableProcessor = new EnvironmentVariableProcessor(List.of());
    ConfigurationFieldModelConverter modelConverter = new ConfigurationFieldModelConverter(encryptionUtility, baseDescriptorAccessor, List.of());
    FieldModelProcessor fieldModelProcessor = new FieldModelProcessor(modelConverter, new DescriptorProcessor(descriptorMap, baseConfigurationModelConfigurationAccessor, List.of()));
    SettingsUtility settingsUtility = Mockito.mock(SettingsUtility.class);
    Mockito.when(settingsUtility.getKey()).thenReturn(new SettingsDescriptorKey());
    AlertStartupInitializer initializer = new AlertStartupInitializer(descriptorMap, environmentVariableUtility, baseDescriptorAccessor, baseConfigurationModelConfigurationAccessor, modelConverter, fieldModelProcessor, settingsUtility, environmentVariableProcessor);
    initializer.initializeComponent();
    // called to get the settings component configuration and fields.
    Mockito.verify(baseDescriptorAccessor, Mockito.times(1)).getFieldsForDescriptor(Mockito.any(DescriptorKey.class), Mockito.any(ConfigContextEnum.class));
    Mockito.verify(baseConfigurationModelConfigurationAccessor, Mockito.times(1)).getConfigurationsByDescriptorKeyAndContext(Mockito.any(DescriptorKey.class), Mockito.any(ConfigContextEnum.class));
// nothing should be saved
// Mockito.verify(baseConfigurationAccessor, Mockito.times(1)).createConfiguration(Mockito.anyString(), Mockito.any(ConfigContextEnum.class), Mockito.anyCollection());
}
Also used : FieldModelProcessor(com.synopsys.integration.alert.common.rest.FieldModelProcessor) SettingsUtility(com.synopsys.integration.alert.common.descriptor.accessor.SettingsUtility) EnvironmentVariableProcessor(com.synopsys.integration.alert.environment.EnvironmentVariableProcessor) SettingsDescriptorKey(com.synopsys.integration.alert.component.settings.descriptor.SettingsDescriptorKey) DescriptorKey(com.synopsys.integration.alert.descriptor.api.model.DescriptorKey) DescriptorAccessor(com.synopsys.integration.alert.common.persistence.accessor.DescriptorAccessor) ConfigurationModelConfigurationAccessor(com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor) ConfigurationFieldModelConverter(com.synopsys.integration.alert.common.persistence.util.ConfigurationFieldModelConverter) EncryptionUtility(com.synopsys.integration.alert.common.security.EncryptionUtility) DescriptorMap(com.synopsys.integration.alert.common.descriptor.DescriptorMap) EnvironmentVariableUtility(com.synopsys.integration.alert.environment.EnvironmentVariableUtility) DescriptorProcessor(com.synopsys.integration.alert.common.descriptor.DescriptorProcessor) SettingsDescriptorKey(com.synopsys.integration.alert.component.settings.descriptor.SettingsDescriptorKey) Environment(org.springframework.core.env.Environment) ConfigContextEnum(com.synopsys.integration.alert.common.enumeration.ConfigContextEnum) Test(org.junit.jupiter.api.Test)

Example 9 with EncryptionUtility

use of com.synopsys.integration.alert.common.security.EncryptionUtility in project hub-alert by blackducksoftware.

the class AlertStartupInitializerTest method testOverwrite.

@Test
public void testOverwrite() throws Exception {
    Environment environment = Mockito.mock(Environment.class);
    DescriptorAccessor baseDescriptorAccessor = Mockito.mock(DescriptorAccessor.class);
    ConfigurationModelConfigurationAccessor baseConfigurationModelConfigurationAccessor = Mockito.mock(ConfigurationModelConfigurationAccessor.class);
    EncryptionUtility encryptionUtility = Mockito.mock(EncryptionUtility.class);
    Mockito.when(encryptionUtility.isInitialized()).thenReturn(Boolean.TRUE);
    ChannelDescriptor channelDescriptor = new EmailDescriptor(null, null);
    ConfigurationModel settingsModel = Mockito.mock(ConfigurationModel.class);
    ConfigurationFieldModel envOverrideField = Mockito.mock(ConfigurationFieldModel.class);
    ConfigurationModel slackModel = Mockito.mock(ConfigurationModel.class);
    Mockito.when(envOverrideField.getFieldValue()).thenReturn(Optional.of("true"));
    Mockito.when(baseConfigurationModelConfigurationAccessor.getConfigurationsByDescriptorKeyAndContext(SETTINGS_DESCRIPTOR_KEY, ConfigContextEnum.GLOBAL)).thenReturn(List.of(settingsModel));
    Mockito.when(baseConfigurationModelConfigurationAccessor.getConfigurationsByDescriptorKeyAndContext(channelDescriptor.getDescriptorKey(), ConfigContextEnum.GLOBAL)).thenReturn(List.of(slackModel));
    List<DescriptorKey> descriptorKeys = List.of(channelDescriptor.getDescriptorKey(), SETTINGS_DESCRIPTOR_KEY);
    List<Descriptor> descriptors = List.of(channelDescriptor);
    DescriptorMap descriptorMap = new DescriptorMap(descriptorKeys, descriptors);
    ConfigurationFieldModelConverter modelConverter = new ConfigurationFieldModelConverter(encryptionUtility, baseDescriptorAccessor, descriptorKeys);
    Mockito.when(baseDescriptorAccessor.getFieldsForDescriptor(Mockito.any(DescriptorKey.class), Mockito.any(ConfigContextEnum.class))).thenReturn(List.of());
    final String value = "newValue";
    Mockito.when(environment.getProperty(Mockito.startsWith("ALERT_CHANNEL_"))).thenReturn(value);
    EnvironmentVariableUtility environmentVariableUtility = new EnvironmentVariableUtility(environment);
    EnvironmentVariableProcessor environmentVariableProcessor = new EnvironmentVariableProcessor(List.of());
    FieldModelProcessor fieldModelProcessor = new FieldModelProcessor(modelConverter, new DescriptorProcessor(descriptorMap, baseConfigurationModelConfigurationAccessor, List.of()));
    SettingsUtility settingsUtility = Mockito.mock(SettingsUtility.class);
    Mockito.when(settingsUtility.getKey()).thenReturn(new SettingsDescriptorKey());
    AlertStartupInitializer initializer = new AlertStartupInitializer(descriptorMap, environmentVariableUtility, baseDescriptorAccessor, baseConfigurationModelConfigurationAccessor, modelConverter, fieldModelProcessor, settingsUtility, environmentVariableProcessor);
    initializer.initializeComponent();
    Mockito.verify(baseDescriptorAccessor, Mockito.times(2)).getFieldsForDescriptor(Mockito.any(DescriptorKey.class), Mockito.any(ConfigContextEnum.class));
    Mockito.verify(baseConfigurationModelConfigurationAccessor, Mockito.times(0)).createConfiguration(Mockito.any(DescriptorKey.class), Mockito.any(ConfigContextEnum.class), Mockito.anyCollection());
    Mockito.verify(baseConfigurationModelConfigurationAccessor, Mockito.times(2)).getConfigurationsByDescriptorKeyAndContext(Mockito.any(DescriptorKey.class), Mockito.any(ConfigContextEnum.class));
// Mockito.verify(baseConfigurationAccessor, Mockito.times(2)).updateConfiguration(Mockito.anyLong(), Mockito.anyCollection());
}
Also used : ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) FieldModelProcessor(com.synopsys.integration.alert.common.rest.FieldModelProcessor) SettingsUtility(com.synopsys.integration.alert.common.descriptor.accessor.SettingsUtility) EnvironmentVariableProcessor(com.synopsys.integration.alert.environment.EnvironmentVariableProcessor) SettingsDescriptorKey(com.synopsys.integration.alert.component.settings.descriptor.SettingsDescriptorKey) DescriptorKey(com.synopsys.integration.alert.descriptor.api.model.DescriptorKey) DescriptorAccessor(com.synopsys.integration.alert.common.persistence.accessor.DescriptorAccessor) ConfigurationModelConfigurationAccessor(com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor) EmailDescriptor(com.synopsys.integration.alert.channel.email.descriptor.EmailDescriptor) ConfigurationFieldModelConverter(com.synopsys.integration.alert.common.persistence.util.ConfigurationFieldModelConverter) ChannelDescriptor(com.synopsys.integration.alert.common.descriptor.ChannelDescriptor) EncryptionUtility(com.synopsys.integration.alert.common.security.EncryptionUtility) ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) DescriptorMap(com.synopsys.integration.alert.common.descriptor.DescriptorMap) EnvironmentVariableUtility(com.synopsys.integration.alert.environment.EnvironmentVariableUtility) DescriptorProcessor(com.synopsys.integration.alert.common.descriptor.DescriptorProcessor) SettingsDescriptorKey(com.synopsys.integration.alert.component.settings.descriptor.SettingsDescriptorKey) Environment(org.springframework.core.env.Environment) Descriptor(com.synopsys.integration.alert.common.descriptor.Descriptor) ChannelDescriptor(com.synopsys.integration.alert.common.descriptor.ChannelDescriptor) EmailDescriptor(com.synopsys.integration.alert.channel.email.descriptor.EmailDescriptor) ConfigContextEnum(com.synopsys.integration.alert.common.enumeration.ConfigContextEnum) Test(org.junit.jupiter.api.Test)

Example 10 with EncryptionUtility

use of com.synopsys.integration.alert.common.security.EncryptionUtility in project hub-alert by blackducksoftware.

the class AlertStartupInitializerTest method testInitializeConfigs.

// TODO these tests need to be re-written
@Test
public void testInitializeConfigs() {
    Environment environment = Mockito.mock(Environment.class);
    DescriptorAccessor baseDescriptorAccessor = Mockito.mock(DescriptorAccessor.class);
    ConfigurationModelConfigurationAccessor baseConfigurationModelConfigurationAccessor = Mockito.mock(ConfigurationModelConfigurationAccessor.class);
    EncryptionUtility encryptionUtility = Mockito.mock(EncryptionUtility.class);
    Mockito.when(encryptionUtility.isInitialized()).thenReturn(Boolean.TRUE);
    ChannelDescriptor channelDescriptor = new EmailDescriptor(null, null);
    SettingsDescriptorKey settingsDescriptorKey = new SettingsDescriptorKey();
    List<DescriptorKey> descriptorKeys = List.of(channelDescriptor.getDescriptorKey(), settingsDescriptorKey);
    List<Descriptor> descriptors = List.of(channelDescriptor);
    EnvironmentVariableUtility environmentVariableUtility = new EnvironmentVariableUtility(environment);
    EnvironmentVariableProcessor environmentVariableProcessor = new EnvironmentVariableProcessor(List.of());
    DescriptorMap descriptorMap = new DescriptorMap(descriptorKeys, descriptors);
    ConfigurationFieldModelConverter modelConverter = new ConfigurationFieldModelConverter(encryptionUtility, baseDescriptorAccessor, descriptorKeys);
    Mockito.when(baseDescriptorAccessor.getFieldsForDescriptor(Mockito.any(DescriptorKey.class), Mockito.any(ConfigContextEnum.class))).thenReturn(List.of());
    FieldModelProcessor fieldModelProcessor = new FieldModelProcessor(modelConverter, new DescriptorProcessor(descriptorMap, baseConfigurationModelConfigurationAccessor, List.of()));
    SettingsUtility settingsUtility = Mockito.mock(SettingsUtility.class);
    Mockito.when(settingsUtility.getKey()).thenReturn(settingsDescriptorKey);
    AlertStartupInitializer initializer = new AlertStartupInitializer(descriptorMap, environmentVariableUtility, baseDescriptorAccessor, baseConfigurationModelConfigurationAccessor, modelConverter, fieldModelProcessor, settingsUtility, environmentVariableProcessor);
    initializer.initializeComponent();
    Mockito.verify(baseDescriptorAccessor, Mockito.times(4)).getFieldsForDescriptor(Mockito.any(DescriptorKey.class), Mockito.any(ConfigContextEnum.class));
    Mockito.verify(baseConfigurationModelConfigurationAccessor, Mockito.times(2)).getConfigurationsByDescriptorKeyAndContext(Mockito.any(DescriptorKey.class), Mockito.any(ConfigContextEnum.class));
}
Also used : FieldModelProcessor(com.synopsys.integration.alert.common.rest.FieldModelProcessor) SettingsUtility(com.synopsys.integration.alert.common.descriptor.accessor.SettingsUtility) EnvironmentVariableProcessor(com.synopsys.integration.alert.environment.EnvironmentVariableProcessor) SettingsDescriptorKey(com.synopsys.integration.alert.component.settings.descriptor.SettingsDescriptorKey) DescriptorKey(com.synopsys.integration.alert.descriptor.api.model.DescriptorKey) DescriptorAccessor(com.synopsys.integration.alert.common.persistence.accessor.DescriptorAccessor) ConfigurationModelConfigurationAccessor(com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor) EmailDescriptor(com.synopsys.integration.alert.channel.email.descriptor.EmailDescriptor) ConfigurationFieldModelConverter(com.synopsys.integration.alert.common.persistence.util.ConfigurationFieldModelConverter) ChannelDescriptor(com.synopsys.integration.alert.common.descriptor.ChannelDescriptor) EncryptionUtility(com.synopsys.integration.alert.common.security.EncryptionUtility) DescriptorMap(com.synopsys.integration.alert.common.descriptor.DescriptorMap) SettingsDescriptorKey(com.synopsys.integration.alert.component.settings.descriptor.SettingsDescriptorKey) EnvironmentVariableUtility(com.synopsys.integration.alert.environment.EnvironmentVariableUtility) DescriptorProcessor(com.synopsys.integration.alert.common.descriptor.DescriptorProcessor) Environment(org.springframework.core.env.Environment) Descriptor(com.synopsys.integration.alert.common.descriptor.Descriptor) ChannelDescriptor(com.synopsys.integration.alert.common.descriptor.ChannelDescriptor) EmailDescriptor(com.synopsys.integration.alert.channel.email.descriptor.EmailDescriptor) ConfigContextEnum(com.synopsys.integration.alert.common.enumeration.ConfigContextEnum) Test(org.junit.jupiter.api.Test)

Aggregations

EncryptionUtility (com.synopsys.integration.alert.common.security.EncryptionUtility)21 Test (org.junit.jupiter.api.Test)20 DescriptorKey (com.synopsys.integration.alert.descriptor.api.model.DescriptorKey)15 DescriptorAccessor (com.synopsys.integration.alert.common.persistence.accessor.DescriptorAccessor)14 ConfigurationFieldModelConverter (com.synopsys.integration.alert.common.persistence.util.ConfigurationFieldModelConverter)14 ConfigurationFieldModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel)8 DescriptorMap (com.synopsys.integration.alert.common.descriptor.DescriptorMap)7 DescriptorProcessor (com.synopsys.integration.alert.common.descriptor.DescriptorProcessor)7 ConfigContextEnum (com.synopsys.integration.alert.common.enumeration.ConfigContextEnum)7 ConfigurationModelConfigurationAccessor (com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor)7 DefinedFieldModel (com.synopsys.integration.alert.common.persistence.model.DefinedFieldModel)7 FieldModelProcessor (com.synopsys.integration.alert.common.rest.FieldModelProcessor)7 SettingsDescriptorKey (com.synopsys.integration.alert.component.settings.descriptor.SettingsDescriptorKey)7 MockDescriptorAccessor (com.synopsys.integration.alert.mock.MockDescriptorAccessor)7 FieldModel (com.synopsys.integration.alert.common.rest.model.FieldModel)6 FilePersistenceUtil (com.synopsys.integration.alert.common.persistence.util.FilePersistenceUtil)5 SettingsEncryptionModel (com.synopsys.integration.alert.component.settings.encryption.model.SettingsEncryptionModel)4 AlertConfigurationException (com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException)3 EmailGlobalCrudActions (com.synopsys.integration.alert.channel.email.action.EmailGlobalCrudActions)3 EmailGlobalConfigurationModelConverter (com.synopsys.integration.alert.channel.email.convert.EmailGlobalConfigurationModelConverter)3