use of com.synopsys.integration.alert.service.email.model.EmailGlobalConfigModel in project hub-alert by blackducksoftware.
the class EmailGlobalConfigurationModelConverterTest method validConversionTest.
@Test
void validConversionTest() {
ConfigurationModel configurationModel = createDefaultConfigurationModel();
EmailGlobalConfigurationModelConverter converter = new EmailGlobalConfigurationModelConverter();
Optional<EmailGlobalConfigModel> model = converter.convert(configurationModel);
assertTrue(model.isPresent());
EmailGlobalConfigModel emailModel = model.get();
assertEquals(Boolean.TRUE, emailModel.getSmtpAuth().orElse(Boolean.FALSE));
assertEquals(TEST_AUTH_USER, emailModel.getSmtpUsername().orElse(null));
assertEquals(TEST_AUTH_PASSWORD, emailModel.getSmtpPassword().orElse(null));
assertEquals(TEST_SMTP_HOST, emailModel.getSmtpHost().orElse(null));
assertEquals(Integer.valueOf(TEST_SMTP_PORT), emailModel.getSmtpPort().orElse(null));
assertEquals(TEST_FROM, emailModel.getSmtpFrom().orElse(null));
Map<String, String> additionalProperties = emailModel.getAdditionalJavaMailProperties().orElse(Map.of());
assertEquals(1, additionalProperties.size());
assertEquals("true", additionalProperties.get(EmailPropertyKeys.JAVAMAIL_EHLO_KEY.getPropertyKey()));
}
use of com.synopsys.integration.alert.service.email.model.EmailGlobalConfigModel in project hub-alert by blackducksoftware.
the class EmailGlobalValidationActionTest method testValidationSuccess.
@Test
public void testValidationSuccess() {
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));
EmailGlobalConfigurationValidator validator = new EmailGlobalConfigurationValidator();
EmailGlobalValidationAction validationAction = new EmailGlobalValidationAction(validator, authorizationManager);
EmailGlobalConfigModel model = new EmailGlobalConfigModel();
model.setSmtpHost("host");
model.setSmtpFrom("from");
model.setSmtpAuth(true);
model.setSmtpUsername("user");
model.setSmtpPassword("password");
ActionResponse<ValidationResponseModel> response = validationAction.validate(model);
assertEquals(HttpStatus.OK, response.getHttpStatus());
}
use of com.synopsys.integration.alert.service.email.model.EmailGlobalConfigModel in project hub-alert by blackducksoftware.
the class EmailGlobalValidationActionTest method testValidationForbidden.
@Test
public void testValidationForbidden() {
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();
EmailGlobalValidationAction validationAction = new EmailGlobalValidationAction(validator, authorizationManager);
EmailGlobalConfigModel model = new EmailGlobalConfigModel();
model.setSmtpHost("host");
model.setSmtpFrom("from");
model.setSmtpAuth(true);
model.setSmtpUsername("user");
model.setSmtpPassword("password");
ActionResponse<ValidationResponseModel> response = validationAction.validate(model);
assertEquals(HttpStatus.FORBIDDEN, response.getHttpStatus());
}
use of com.synopsys.integration.alert.service.email.model.EmailGlobalConfigModel in project hub-alert by blackducksoftware.
the class EmailGlobalConfigurationActionTest method testDeleteForbidden.
@Test
public void testDeleteForbidden() {
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);
EmailGlobalCrudActions configActions = new EmailGlobalCrudActions(authorizationManager, emailGlobalConfigAccessor, validator);
ActionResponse<EmailGlobalConfigModel> response = configActions.delete();
assertEquals(HttpStatus.FORBIDDEN, response.getHttpStatus());
}
use of com.synopsys.integration.alert.service.email.model.EmailGlobalConfigModel in project hub-alert by blackducksoftware.
the class EmailGlobalConfigurationActionTest method testDelete.
@Test
public void testDelete() {
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));
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");
Mockito.when(emailGlobalConfigAccessor.getConfiguration()).thenReturn(Optional.of(model));
Mockito.when(emailGlobalConfigAccessor.doesConfigurationExist()).thenReturn(true);
EmailGlobalCrudActions configActions = new EmailGlobalCrudActions(authorizationManager, emailGlobalConfigAccessor, validator);
ActionResponse<EmailGlobalConfigModel> response = configActions.delete();
assertEquals(HttpStatus.NO_CONTENT, response.getHttpStatus());
}
Aggregations