use of com.synopsys.integration.alert.common.rest.model.FieldValueModel 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.");
}
use of com.synopsys.integration.alert.common.rest.model.FieldValueModel in project hub-alert by blackducksoftware.
the class EmailGlobalConfigurationFieldModelValidatorTest method verifyMissingAuthPassword.
@Test
public void verifyMissingAuthPassword() {
Map<String, FieldValueModel> defaultKeyToValues = createDefaultKeyToValues();
FieldValueModel authFieldValueModel = new FieldValueModel(List.of("true"), true);
FieldValueModel usernameFieldValueModel = new FieldValueModel(List.of("username"), true);
defaultKeyToValues.put(EmailPropertyKeys.JAVAMAIL_AUTH_KEY.getPropertyKey(), authFieldValueModel);
defaultKeyToValues.put(EmailPropertyKeys.JAVAMAIL_USER_KEY.getPropertyKey(), usernameFieldValueModel);
GlobalConfigurationValidatorAsserter globalConfigurationValidatorAsserter = new GlobalConfigurationValidatorAsserter(new EmailChannelKey().getUniversalKey(), new EmailGlobalConfigurationFieldModelValidator(), defaultKeyToValues);
globalConfigurationValidatorAsserter.assertMissingValue(EmailPropertyKeys.JAVAMAIL_PASSWORD_KEY.getPropertyKey());
}
use of com.synopsys.integration.alert.common.rest.model.FieldValueModel in project hub-alert by blackducksoftware.
the class EmailGlobalConfigurationFieldModelValidatorTest method verifyMissingAuth.
@Test
public void verifyMissingAuth() {
Map<String, FieldValueModel> defaultKeyToValues = createDefaultKeyToValues();
FieldValueModel authFieldValueModel = new FieldValueModel(List.of("true"), true);
defaultKeyToValues.put(EmailPropertyKeys.JAVAMAIL_AUTH_KEY.getPropertyKey(), authFieldValueModel);
FieldModel fieldModel = new FieldModel(new EmailChannelKey().getUniversalKey(), ConfigContextEnum.GLOBAL.name(), defaultKeyToValues);
EmailGlobalConfigurationFieldModelValidator emailGlobalConfigurationValidator = new EmailGlobalConfigurationFieldModelValidator();
Set<AlertFieldStatus> alertFieldStatuses = emailGlobalConfigurationValidator.validate(fieldModel);
assertEquals(2, alertFieldStatuses.size());
}
use of com.synopsys.integration.alert.common.rest.model.FieldValueModel in project hub-alert by blackducksoftware.
the class EmailGlobalConfigurationFieldModelValidator method validate.
@Override
public Set<AlertFieldStatus> validate(FieldModel fieldModel) {
ConfigurationFieldValidator configurationFieldValidator = ConfigurationFieldValidator.fromFieldModel(fieldModel);
configurationFieldValidator.validateRequiredFieldIsNotBlank(EmailPropertyKeys.JAVAMAIL_HOST_KEY.getPropertyKey());
configurationFieldValidator.validateRequiredFieldIsNotBlank(EmailPropertyKeys.JAVAMAIL_FROM_KEY.getPropertyKey());
configurationFieldValidator.validateIsANumber(EmailPropertyKeys.JAVAMAIL_PORT_KEY.getPropertyKey());
configurationFieldValidator.validateIsANumber(EmailPropertyKeys.JAVAMAIL_CONNECTION_TIMEOUT_KEY.getPropertyKey());
configurationFieldValidator.validateIsANumber(EmailPropertyKeys.JAVAMAIL_TIMEOUT_KEY.getPropertyKey());
configurationFieldValidator.validateIsANumber(EmailPropertyKeys.JAVAMAIL_WRITETIMEOUT_KEY.getPropertyKey());
configurationFieldValidator.validateIsANumber(EmailPropertyKeys.JAVAMAIL_LOCALHOST_PORT_KEY.getPropertyKey());
configurationFieldValidator.validateIsANumber(EmailPropertyKeys.JAVAMAIL_AUTH_NTLM_FLAGS_KEY.getPropertyKey());
configurationFieldValidator.validateIsANumber(EmailPropertyKeys.JAVAMAIL_PROXY_PORT_KEY.getPropertyKey());
configurationFieldValidator.validateIsANumber(EmailPropertyKeys.JAVAMAIL_SOCKS_PORT_KEY.getPropertyKey());
boolean useAuth = fieldModel.getFieldValueModel(EmailPropertyKeys.JAVAMAIL_AUTH_KEY.getPropertyKey()).flatMap(FieldValueModel::getValue).map(Boolean::valueOf).orElse(false);
if (useAuth) {
configurationFieldValidator.validateRequiredFieldsAreNotBlank(List.of(EmailPropertyKeys.JAVAMAIL_USER_KEY.getPropertyKey(), EmailPropertyKeys.JAVAMAIL_PASSWORD_KEY.getPropertyKey()));
}
return configurationFieldValidator.getValidationResults();
}
use of com.synopsys.integration.alert.common.rest.model.FieldValueModel in project hub-alert by blackducksoftware.
the class EmailGlobalFieldModelTestActionTest method createFieldModelToTest.
private FieldModel createFieldModelToTest(String destinationValue) {
Map<String, FieldValueModel> keyToValues = new HashMap<>();
Set<String> values = null != destinationValue ? Set.of(destinationValue) : Set.of();
FieldValueModel destinationFieldValueModel = new FieldValueModel(values, false);
keyToValues.put(FieldModelTestAction.KEY_DESTINATION_NAME, destinationFieldValueModel);
return new FieldModel(null, null, keyToValues);
}
Aggregations