Search in sources :

Example 11 with EmailGlobalConfigModel

use of com.synopsys.integration.alert.service.email.model.EmailGlobalConfigModel in project hub-alert by blackducksoftware.

the class EmailGlobalTestActionTest method testConfigValidTest.

@Test
public void testConfigValidTest() throws AlertException {
    AuthorizationManager authorizationManager = createAuthorizationManager(255);
    EmailGlobalConfigurationValidator validator = new EmailGlobalConfigurationValidator();
    EmailChannelMessagingService emailChannelMessagingService = Mockito.mock(EmailChannelMessagingService.class);
    Mockito.when(emailChannelMessagingService.sendMessage(Mockito.any(), Mockito.any())).thenReturn(new MessageResult("PASS"));
    JavamailPropertiesFactory javamailPropertiesFactory = new JavamailPropertiesFactory();
    EmailGlobalTestAction emailGlobalTestAction = new EmailGlobalTestAction(authorizationManager, validator, emailChannelMessagingService, javamailPropertiesFactory, configurationAccessor);
    ConfigurationTestResult testResult = emailGlobalTestAction.testConfigModelContent("noreply@synopsys.com", new EmailGlobalConfigModel());
    assertTrue(testResult.isSuccess(), "Expected the message result to not have errors");
}
Also used : EmailGlobalConfigModel(com.synopsys.integration.alert.service.email.model.EmailGlobalConfigModel) EmailGlobalConfigurationValidator(com.synopsys.integration.alert.channel.email.validator.EmailGlobalConfigurationValidator) AuthorizationManager(com.synopsys.integration.alert.common.security.authorization.AuthorizationManager) MessageResult(com.synopsys.integration.alert.common.message.model.MessageResult) EmailChannelMessagingService(com.synopsys.integration.alert.channel.email.distribution.EmailChannelMessagingService) JavamailPropertiesFactory(com.synopsys.integration.alert.service.email.JavamailPropertiesFactory) ConfigurationTestResult(com.synopsys.integration.alert.common.message.model.ConfigurationTestResult) Test(org.junit.jupiter.api.Test)

Example 12 with EmailGlobalConfigModel

use of com.synopsys.integration.alert.service.email.model.EmailGlobalConfigModel in project hub-alert by blackducksoftware.

the class EmailGlobalConfigurationModelSaveActions method createConcreteModel.

@Override
public void createConcreteModel(ConfigurationModel configurationModel) {
    Optional<EmailGlobalConfigModel> emailGlobalConfigModel = emailFieldModelConverter.convert(configurationModel);
    if (emailGlobalConfigModel.isPresent()) {
        EmailGlobalConfigModel model = emailGlobalConfigModel.get();
        model.setName(AlertRestConstants.DEFAULT_CONFIGURATION_NAME);
        configurationActions.create(model);
    }
}
Also used : EmailGlobalConfigModel(com.synopsys.integration.alert.service.email.model.EmailGlobalConfigModel)

Example 13 with EmailGlobalConfigModel

use of com.synopsys.integration.alert.service.email.model.EmailGlobalConfigModel in project hub-alert by blackducksoftware.

the class EmailGlobalConfigurationModelSaveActions method updateConcreteModel.

@Override
public void updateConcreteModel(ConfigurationModel configurationModel) {
    Optional<UUID> defaultConfigurationId = configurationAccessor.getConfiguration().map(EmailGlobalConfigModel::getId).map(UUID::fromString);
    Optional<EmailGlobalConfigModel> emailGlobalConfigModel = emailFieldModelConverter.convert(configurationModel);
    if (defaultConfigurationId.isPresent() && emailGlobalConfigModel.isPresent()) {
        EmailGlobalConfigModel model = emailGlobalConfigModel.get();
        model.setName(AlertRestConstants.DEFAULT_CONFIGURATION_NAME);
        configurationActions.update(model);
    }
}
Also used : EmailGlobalConfigModel(com.synopsys.integration.alert.service.email.model.EmailGlobalConfigModel) UUID(java.util.UUID)

Example 14 with EmailGlobalConfigModel

use of com.synopsys.integration.alert.service.email.model.EmailGlobalConfigModel in project hub-alert by blackducksoftware.

the class EmailEnvironmentVariableHandlerFactory method updateConfiguration.

private EnvironmentProcessingResult updateConfiguration() {
    EnvironmentProcessingResult.Builder builder = new EnvironmentProcessingResult.Builder(EMAIL_CONFIGURATION_KEYSET).addVariableNames(OLD_ADDITIONAL_PROPERTY_KEYSET);
    EmailGlobalConfigModel configModel = new EmailGlobalConfigModel();
    configModel.setName(AlertRestConstants.DEFAULT_CONFIGURATION_NAME);
    configureEmailSettings(configModel);
    configureAdditionalProperties(builder, configModel);
    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();
    }
    EmailGlobalConfigModel obfuscatedModel = configModel.obfuscate();
    obfuscatedModel.getSmtpHost().ifPresent(value -> builder.addVariableValue(EMAIL_HOST_KEY, value));
    obfuscatedModel.getSmtpPort().map(String::valueOf).ifPresent(value -> builder.addVariableValue(EMAIL_PORT_KEY, value));
    obfuscatedModel.getSmtpFrom().ifPresent(value -> builder.addVariableValue(EMAIL_FROM_KEY, value));
    obfuscatedModel.getSmtpAuth().map(String::valueOf).ifPresent(value -> builder.addVariableValue(AUTH_REQUIRED_KEY, value));
    obfuscatedModel.getSmtpUsername().ifPresent(value -> builder.addVariableValue(AUTH_USER_KEY, value));
    if (Boolean.TRUE.equals(obfuscatedModel.getIsSmtpPasswordSet())) {
        builder.addVariableValue(AUTH_PASSWORD_KEY, AlertConstants.MASKED_VALUE);
    }
    EnvironmentProcessingResult result = builder.build();
    if (result.hasValues()) {
        try {
            configAccessor.createConfiguration(configModel);
        } catch (AlertConfigurationException ex) {
            logger.error("Failed to create config: ", ex);
        }
    }
    return result;
}
Also used : EmailGlobalConfigModel(com.synopsys.integration.alert.service.email.model.EmailGlobalConfigModel) ValidationResponseModel(com.synopsys.integration.alert.common.rest.model.ValidationResponseModel) AlertFieldStatus(com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus) EnvironmentProcessingResult(com.synopsys.integration.alert.environment.EnvironmentProcessingResult) HashMap(java.util.HashMap) Map(java.util.Map) AlertConfigurationException(com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException)

Example 15 with EmailGlobalConfigModel

use of com.synopsys.integration.alert.service.email.model.EmailGlobalConfigModel in project hub-alert by blackducksoftware.

the class EmailGlobalConfigurationActionTest method testUpdateNotFound.

@Test
public void testUpdateNotFound() {
    AuthenticationTestUtils authenticationTestUtils = new AuthenticationTestUtils();
    DescriptorKey descriptorKey = ChannelKeys.EMAIL;
    PermissionKey permissionKey = new PermissionKey(ConfigContextEnum.GLOBAL.name(), descriptorKey.getUniversalKey());
    Map<PermissionKey, Integer> permissions = Map.of(permissionKey, AuthenticationTestUtils.FULL_PERMISSIONS);
    AuthorizationManager authorizationManager = authenticationTestUtils.createAuthorizationManagerWithCurrentUserSet("admin", "admin", () -> new PermissionMatrixModel(permissions));
    UUID configId = UUID.randomUUID();
    EmailGlobalConfigurationValidator validator = new EmailGlobalConfigurationValidator();
    EmailGlobalConfigAccessor emailGlobalConfigAccessor = Mockito.mock(EmailGlobalConfigAccessor.class);
    Mockito.when(emailGlobalConfigAccessor.getConfiguration()).thenReturn(Optional.empty());
    EmailGlobalConfigModel model = new EmailGlobalConfigModel();
    model.setSmtpHost("host");
    model.setSmtpFrom("from");
    model.setSmtpAuth(true);
    model.setSmtpUsername("user");
    model.setSmtpPassword("password");
    EmailGlobalCrudActions configActions = new EmailGlobalCrudActions(authorizationManager, emailGlobalConfigAccessor, validator);
    ActionResponse<EmailGlobalConfigModel> response = configActions.update(model);
    assertEquals(HttpStatus.NOT_FOUND, response.getHttpStatus());
}
Also used : EmailGlobalConfigModel(com.synopsys.integration.alert.service.email.model.EmailGlobalConfigModel) DescriptorKey(com.synopsys.integration.alert.descriptor.api.model.DescriptorKey) EmailGlobalConfigurationValidator(com.synopsys.integration.alert.channel.email.validator.EmailGlobalConfigurationValidator) PermissionMatrixModel(com.synopsys.integration.alert.common.persistence.model.PermissionMatrixModel) PermissionKey(com.synopsys.integration.alert.common.persistence.model.PermissionKey) EmailGlobalConfigAccessor(com.synopsys.integration.alert.channel.email.database.accessor.EmailGlobalConfigAccessor) AuthenticationTestUtils(com.synopsys.integration.alert.test.common.AuthenticationTestUtils) AuthorizationManager(com.synopsys.integration.alert.common.security.authorization.AuthorizationManager) UUID(java.util.UUID) Test(org.junit.jupiter.api.Test)

Aggregations

EmailGlobalConfigModel (com.synopsys.integration.alert.service.email.model.EmailGlobalConfigModel)51 Test (org.junit.jupiter.api.Test)41 AuthorizationManager (com.synopsys.integration.alert.common.security.authorization.AuthorizationManager)27 EmailGlobalConfigurationValidator (com.synopsys.integration.alert.channel.email.validator.EmailGlobalConfigurationValidator)26 PermissionKey (com.synopsys.integration.alert.common.persistence.model.PermissionKey)15 PermissionMatrixModel (com.synopsys.integration.alert.common.persistence.model.PermissionMatrixModel)15 ValidationResponseModel (com.synopsys.integration.alert.common.rest.model.ValidationResponseModel)15 DescriptorKey (com.synopsys.integration.alert.descriptor.api.model.DescriptorKey)15 AuthenticationTestUtils (com.synopsys.integration.alert.test.common.AuthenticationTestUtils)15 EmailGlobalConfigAccessor (com.synopsys.integration.alert.channel.email.database.accessor.EmailGlobalConfigAccessor)14 JavamailPropertiesFactory (com.synopsys.integration.alert.service.email.JavamailPropertiesFactory)10 EmailChannelMessagingService (com.synopsys.integration.alert.channel.email.distribution.EmailChannelMessagingService)9 AlertFieldStatus (com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus)8 AlertConfigurationException (com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException)6 ConfigurationTestResult (com.synopsys.integration.alert.common.message.model.ConfigurationTestResult)6 MessageResult (com.synopsys.integration.alert.common.message.model.MessageResult)5 UUID (java.util.UUID)5 EmailGlobalCrudActions (com.synopsys.integration.alert.channel.email.action.EmailGlobalCrudActions)4 ValidatedEmailAddresses (com.synopsys.integration.alert.channel.email.distribution.address.ValidatedEmailAddresses)4 AlertIntegrationTest (com.synopsys.integration.alert.util.AlertIntegrationTest)4