Search in sources :

Example 41 with SettingsProxyModel

use of com.synopsys.integration.alert.common.rest.model.SettingsProxyModel in project hub-alert by blackducksoftware.

the class SettingsProxyValidatorTest method validateNonProxyHostsTest.

@Test
void validateNonProxyHostsTest() {
    SettingsProxyModel settingsProxyModel = new SettingsProxyModel();
    settingsProxyModel.setName(AlertRestConstants.DEFAULT_CONFIGURATION_NAME);
    settingsProxyModel.setProxyPort(PORT);
    settingsProxyModel.setNonProxyHosts(List.of("nonProxyHost"));
    ValidationResponseModel validationResponseModel = settingsProxyValidator.validate(settingsProxyModel);
    assertTrue(validationResponseModel.hasErrors());
    assertEquals(1, validationResponseModel.getErrors().size());
    assertTrue(validationResponseModel.getErrors().containsKey(SettingsProxyValidator.PROXY_HOST_FIELD_NAME));
}
Also used : ValidationResponseModel(com.synopsys.integration.alert.common.rest.model.ValidationResponseModel) SettingsProxyModel(com.synopsys.integration.alert.common.rest.model.SettingsProxyModel) Test(org.junit.jupiter.api.Test)

Example 42 with SettingsProxyModel

use of com.synopsys.integration.alert.common.rest.model.SettingsProxyModel in project hub-alert by blackducksoftware.

the class StartupLogTest method testLogConfiguration.

@Test
void testLogConfiguration() throws Exception {
    SettingsProxyModel settingsProxyModel = new SettingsProxyModel();
    settingsProxyModel.setProxyHost("google.com");
    settingsProxyModel.setProxyPort(3218);
    settingsProxyModel.setProxyUsername("AUser");
    settingsProxyModel.setIsProxyPasswordSet(true);
    settingsProxyModel.setProxyPassword("aPassword");
    SettingsUtility mockSettingsUtility = Mockito.mock(SettingsUtility.class);
    Mockito.when(mockSettingsUtility.getConfiguration()).thenReturn(Optional.of(settingsProxyModel));
    ProxyManager proxyManager = new ProxyManager(mockSettingsUtility);
    MockAlertProperties testAlertProperties = new MockAlertProperties();
    ConfigurationLogger configurationLogger = new ConfigurationLogger(proxyManager, testAlertProperties);
    configurationLogger.initializeComponent();
    assertTrue(outputLogger.isLineContainingText("Alert Proxy Authenticated: true"));
}
Also used : SettingsUtility(com.synopsys.integration.alert.common.descriptor.accessor.SettingsUtility) SettingsProxyModel(com.synopsys.integration.alert.common.rest.model.SettingsProxyModel) ProxyManager(com.synopsys.integration.alert.common.rest.proxy.ProxyManager) MockAlertProperties(com.synopsys.integration.alert.test.common.MockAlertProperties) Test(org.junit.jupiter.api.Test)

Example 43 with SettingsProxyModel

use of com.synopsys.integration.alert.common.rest.model.SettingsProxyModel in project hub-alert by blackducksoftware.

the class ProxyConfigurationModelConverter method convert.

@Override
public Optional<SettingsProxyModel> convert(ConfigurationModel globalConfigurationModel) {
    Optional<SettingsProxyModel> convertedModel = Optional.empty();
    SettingsProxyModel model = new SettingsProxyModel();
    try {
        globalConfigurationModel.getField(FIELD_KEY_HOST).flatMap(ConfigurationFieldModel::getFieldValue).ifPresent(model::setProxyHost);
        globalConfigurationModel.getField(FIELD_KEY_PORT).flatMap(ConfigurationFieldModel::getFieldValue).map(Integer::valueOf).ifPresent(model::setProxyPort);
        globalConfigurationModel.getField(FIELD_KEY_NON_PROXY_HOSTS).map(ConfigurationFieldModel::getFieldValues).map(ArrayList::new).ifPresent(model::setNonProxyHosts);
        globalConfigurationModel.getField(FIELD_KEY_USERNAME).flatMap(ConfigurationFieldModel::getFieldValue).ifPresent(model::setProxyUsername);
        globalConfigurationModel.getField(FIELD_KEY_PASSWORD).flatMap(ConfigurationFieldModel::getFieldValue).ifPresent(model::setProxyPassword);
        convertedModel = Optional.of(model);
    } catch (NumberFormatException ex) {
        logger.error("Error converting field model to concrete proxy configuration", ex);
    }
    return convertedModel;
}
Also used : ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) SettingsProxyModel(com.synopsys.integration.alert.common.rest.model.SettingsProxyModel)

Example 44 with SettingsProxyModel

use of com.synopsys.integration.alert.common.rest.model.SettingsProxyModel in project hub-alert by blackducksoftware.

the class ProxySettingsEnvironmentHandlerFactory method updateFunction.

private EnvironmentProcessingResult updateFunction() {
    EnvironmentProcessingResult.Builder builder = new EnvironmentProcessingResult.Builder(PROXY_CONFIGURATION_KEYSET);
    SettingsProxyModel configModel = new SettingsProxyModel();
    configModel.setName(AlertRestConstants.DEFAULT_CONFIGURATION_NAME);
    configureProxySettings(configModel);
    // TODO: Refactor and remove duplicate code after 6.10.0 model package refactor
    ValidationResponseModel validationResponseModel = validator.validate(configModel);
    if (validationResponseModel.hasErrors()) {
        logger.error("Error inserting startup values: {}", validationResponseModel.getMessage());
        Map<String, AlertFieldStatus> errors = validationResponseModel.getErrors();
        for (Map.Entry<String, AlertFieldStatus> error : errors.entrySet()) {
            AlertFieldStatus status = error.getValue();
            logger.error("Field: '{}' failed with the error: {}", status.getFieldName(), status.getFieldMessage());
        }
        return EnvironmentProcessingResult.empty();
    }
    SettingsProxyModel obfuscatedModel = configModel.obfuscate();
    obfuscatedModel.getProxyHost().ifPresent(value -> builder.addVariableValue(PROXY_HOST_KEY, value));
    obfuscatedModel.getProxyPort().map(String::valueOf).ifPresent(value -> builder.addVariableValue(PROXY_PORT_KEY, value));
    obfuscatedModel.getProxyUsername().ifPresent(value -> builder.addVariableValue(PROXY_USERNAME_KEY, value));
    obfuscatedModel.getNonProxyHosts().map(String::valueOf).ifPresent(value -> builder.addVariableValue(PROXY_NON_PROXY_HOSTS_KEY, value));
    if (Boolean.TRUE.equals(obfuscatedModel.getIsProxyPasswordSet())) {
        builder.addVariableValue(PROXY_PASSWORD_KEY, AlertConstants.MASKED_VALUE);
    }
    EnvironmentProcessingResult result = builder.build();
    if (result.hasValues()) {
        try {
            configAccessor.createConfiguration(configModel);
        } catch (AlertConfigurationException ex) {
            logger.error("Error creating the configuration: {}", ex.getMessage());
        }
    }
    return result;
}
Also used : ValidationResponseModel(com.synopsys.integration.alert.common.rest.model.ValidationResponseModel) SettingsProxyModel(com.synopsys.integration.alert.common.rest.model.SettingsProxyModel) AlertFieldStatus(com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus) EnvironmentProcessingResult(com.synopsys.integration.alert.environment.EnvironmentProcessingResult) Map(java.util.Map) AlertConfigurationException(com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException)

Aggregations

SettingsProxyModel (com.synopsys.integration.alert.common.rest.model.SettingsProxyModel)44 Test (org.junit.jupiter.api.Test)32 ValidationResponseModel (com.synopsys.integration.alert.common.rest.model.ValidationResponseModel)18 AlertIntegrationTest (com.synopsys.integration.alert.util.AlertIntegrationTest)12 SettingsProxyTestAction (com.synopsys.integration.alert.component.settings.proxy.action.SettingsProxyTestAction)8 AuthorizationManager (com.synopsys.integration.alert.common.security.authorization.AuthorizationManager)7 URI (java.net.URI)6 MockHttpServletRequestBuilder (org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder)6 SettingsProxyCrudActions (com.synopsys.integration.alert.component.settings.proxy.action.SettingsProxyCrudActions)5 SettingsProxyConfigAccessor (com.synopsys.integration.alert.component.settings.proxy.database.accessor.SettingsProxyConfigAccessor)5 NonProxyHostsConfigurationRepository (com.synopsys.integration.alert.database.settings.proxy.NonProxyHostsConfigurationRepository)5 SettingsProxyConfigurationRepository (com.synopsys.integration.alert.database.settings.proxy.SettingsProxyConfigurationRepository)5 UUID (java.util.UUID)5 WithMockUser (org.springframework.security.test.context.support.WithMockUser)5 ConfigurationModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationModel)3 SettingsProxyConfigurationEntity (com.synopsys.integration.alert.database.settings.proxy.SettingsProxyConfigurationEntity)2 AssertionFailedError (org.opentest4j.AssertionFailedError)2 AlertConfigurationException (com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException)1 SettingsUtility (com.synopsys.integration.alert.common.descriptor.accessor.SettingsUtility)1 AlertFieldStatus (com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus)1