Search in sources :

Example 21 with EmailGlobalConfigAccessor

use of com.synopsys.integration.alert.channel.email.database.accessor.EmailGlobalConfigAccessor in project hub-alert by blackducksoftware.

the class EmailGlobalConfigurationActionTest method testCreateForbidden.

@Test
public void testCreateForbidden() {
    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.NO_PERMISSIONS);
    AuthorizationManager authorizationManager = authenticationTestUtils.createAuthorizationManagerWithCurrentUserSet("admin", "admin", () -> new PermissionMatrixModel(permissions));
    EmailGlobalConfigurationValidator validator = new EmailGlobalConfigurationValidator();
    EmailGlobalConfigAccessor emailGlobalConfigAccessor = Mockito.mock(EmailGlobalConfigAccessor.class);
    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.create(model);
    assertEquals(HttpStatus.FORBIDDEN, response.getHttpStatus());
}
Also used : EmailGlobalConfigModel(com.synopsys.integration.alert.service.email.model.EmailGlobalConfigModel) 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) DescriptorKey(com.synopsys.integration.alert.descriptor.api.model.DescriptorKey) AuthorizationManager(com.synopsys.integration.alert.common.security.authorization.AuthorizationManager) Test(org.junit.jupiter.api.Test)

Example 22 with EmailGlobalConfigAccessor

use of com.synopsys.integration.alert.channel.email.database.accessor.EmailGlobalConfigAccessor in project hub-alert by blackducksoftware.

the class EmailGlobalConfigurationActionTest method testUpdateForbidden.

@Test
public void testUpdateForbidden() {
    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.NO_PERMISSIONS);
    AuthorizationManager authorizationManager = authenticationTestUtils.createAuthorizationManagerWithCurrentUserSet("admin", "admin", () -> new PermissionMatrixModel(permissions));
    UUID configId = UUID.randomUUID();
    EmailGlobalConfigurationValidator validator = new EmailGlobalConfigurationValidator();
    EmailGlobalConfigAccessor emailGlobalConfigAccessor = Mockito.mock(EmailGlobalConfigAccessor.class);
    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.FORBIDDEN, 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

EmailGlobalConfigAccessor (com.synopsys.integration.alert.channel.email.database.accessor.EmailGlobalConfigAccessor)22 Test (org.junit.jupiter.api.Test)22 EmailGlobalConfigurationValidator (com.synopsys.integration.alert.channel.email.validator.EmailGlobalConfigurationValidator)12 EmailGlobalConfigModel (com.synopsys.integration.alert.service.email.model.EmailGlobalConfigModel)11 PermissionKey (com.synopsys.integration.alert.common.persistence.model.PermissionKey)10 PermissionMatrixModel (com.synopsys.integration.alert.common.persistence.model.PermissionMatrixModel)10 AuthorizationManager (com.synopsys.integration.alert.common.security.authorization.AuthorizationManager)10 DescriptorKey (com.synopsys.integration.alert.descriptor.api.model.DescriptorKey)10 AuthenticationTestUtils (com.synopsys.integration.alert.test.common.AuthenticationTestUtils)10 EmailGlobalCrudActions (com.synopsys.integration.alert.channel.email.action.EmailGlobalCrudActions)6 EmailConfigurationEntity (com.synopsys.integration.alert.channel.email.database.configuration.EmailConfigurationEntity)6 EmailConfigurationRepository (com.synopsys.integration.alert.channel.email.database.configuration.EmailConfigurationRepository)6 EmailConfigurationPropertiesRepository (com.synopsys.integration.alert.channel.email.database.configuration.properties.EmailConfigurationPropertiesRepository)6 EmailConfigurationsPropertyEntity (com.synopsys.integration.alert.channel.email.database.configuration.properties.EmailConfigurationsPropertyEntity)6 List (java.util.List)6 AtomicReference (java.util.concurrent.atomic.AtomicReference)6 ConfigurationModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationModel)5 EnvironmentProcessingResult (com.synopsys.integration.alert.environment.EnvironmentProcessingResult)4 EnvironmentVariableHandler (com.synopsys.integration.alert.environment.EnvironmentVariableHandler)4 EnvironmentVariableHandlerFactory (com.synopsys.integration.alert.environment.EnvironmentVariableHandlerFactory)4