Search in sources :

Example 76 with AuthorizationManager

use of com.synopsys.integration.alert.common.security.authorization.AuthorizationManager 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)

Example 77 with AuthorizationManager

use of com.synopsys.integration.alert.common.security.authorization.AuthorizationManager in project hub-alert by blackducksoftware.

the class EmailGlobalTestActionTest method testConfigMissingDestinationTest.

@Test
public void testConfigMissingDestinationTest() {
    AuthorizationManager authorizationManager = createAuthorizationManager(255);
    EmailGlobalConfigurationValidator validator = new EmailGlobalConfigurationValidator();
    EmailAddressGatherer emailAddressGatherer = Mockito.mock(EmailAddressGatherer.class);
    Mockito.when(emailAddressGatherer.gatherEmailAddresses(Mockito.any(), Mockito.any())).thenReturn(Set.of());
    JobEmailAddressValidator emailAddressValidator = Mockito.mock(JobEmailAddressValidator.class);
    Mockito.when(emailAddressValidator.validate(Mockito.any(), Mockito.anyCollection())).thenReturn(new ValidatedEmailAddresses(Set.of(), Set.of()));
    MockAlertProperties testAlertProperties = new MockAlertProperties();
    MessageContentGroupCsvCreator messageContentGroupCsvCreator = new MessageContentGroupCsvCreator();
    Gson gson = new Gson();
    EmailAttachmentFileCreator emailAttachmentFileCreator = new EmailAttachmentFileCreator(testAlertProperties, messageContentGroupCsvCreator, gson);
    FreemarkerTemplatingService freemarkerTemplatingService = new FreemarkerTemplatingService();
    EmailMessagingService emailMessagingService = new EmailMessagingService(freemarkerTemplatingService);
    EmailChannelMessagingService emailChannelMessagingService = new EmailChannelMessagingService(testAlertProperties, emailMessagingService, emailAttachmentFileCreator);
    JavamailPropertiesFactory javamailPropertiesFactory = new JavamailPropertiesFactory();
    EmailGlobalTestAction emailGlobalTestAction = new EmailGlobalTestAction(authorizationManager, validator, emailChannelMessagingService, javamailPropertiesFactory, configurationAccessor);
    ConfigurationTestResult testResult = emailGlobalTestAction.testConfigModelContent("", new EmailGlobalConfigModel());
    assertFalse(testResult.isSuccess());
}
Also used : MessageContentGroupCsvCreator(com.synopsys.integration.alert.channel.email.attachment.MessageContentGroupCsvCreator) EmailGlobalConfigModel(com.synopsys.integration.alert.service.email.model.EmailGlobalConfigModel) EmailMessagingService(com.synopsys.integration.alert.service.email.EmailMessagingService) EmailAttachmentFileCreator(com.synopsys.integration.alert.channel.email.attachment.EmailAttachmentFileCreator) Gson(com.google.gson.Gson) EmailAddressGatherer(com.synopsys.integration.alert.channel.email.distribution.address.EmailAddressGatherer) ConfigurationTestResult(com.synopsys.integration.alert.common.message.model.ConfigurationTestResult) EmailGlobalConfigurationValidator(com.synopsys.integration.alert.channel.email.validator.EmailGlobalConfigurationValidator) FreemarkerTemplatingService(com.synopsys.integration.alert.service.email.template.FreemarkerTemplatingService) JobEmailAddressValidator(com.synopsys.integration.alert.channel.email.distribution.address.JobEmailAddressValidator) MockAlertProperties(com.synopsys.integration.alert.test.common.MockAlertProperties) AuthorizationManager(com.synopsys.integration.alert.common.security.authorization.AuthorizationManager) ValidatedEmailAddresses(com.synopsys.integration.alert.channel.email.distribution.address.ValidatedEmailAddresses) EmailChannelMessagingService(com.synopsys.integration.alert.channel.email.distribution.EmailChannelMessagingService) JavamailPropertiesFactory(com.synopsys.integration.alert.service.email.JavamailPropertiesFactory) Test(org.junit.jupiter.api.Test)

Example 78 with AuthorizationManager

use of com.synopsys.integration.alert.common.security.authorization.AuthorizationManager in project hub-alert by blackducksoftware.

the class EmailGlobalTestActionTest method testPermissionConfigValidTest.

@Test
public void testPermissionConfigValidTest() throws AlertException {
    TestProperties testProperties = new TestProperties();
    AuthorizationManager authorizationManager = createAuthorizationManager(AuthenticationTestUtils.FULL_PERMISSIONS);
    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);
    EmailGlobalConfigModel globalConfigModel = createValidEmailGlobalConfigModel(testProperties);
    ActionResponse<ValidationResponseModel> response = emailGlobalTestAction.testWithPermissionCheck("noreply@synopsys.com", globalConfigModel);
    assertEquals(HttpStatus.OK, response.getHttpStatus());
    assertTrue(response.isSuccessful());
    assertTrue(response.hasContent());
    assertFalse(response.getContent().get().hasErrors(), "Expected the message result to not have errors");
}
Also used : TestProperties(com.synopsys.integration.alert.test.common.TestProperties) EmailGlobalConfigModel(com.synopsys.integration.alert.service.email.model.EmailGlobalConfigModel) ValidationResponseModel(com.synopsys.integration.alert.common.rest.model.ValidationResponseModel) 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) Test(org.junit.jupiter.api.Test)

Example 79 with AuthorizationManager

use of com.synopsys.integration.alert.common.security.authorization.AuthorizationManager in project hub-alert by blackducksoftware.

the class EmailGlobalTestActionTest method testPermissionForbiddenTest.

@Test
public void testPermissionForbiddenTest() throws AlertException {
    AuthorizationManager authorizationManager = createAuthorizationManager(0);
    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);
    ActionResponse<ValidationResponseModel> response = emailGlobalTestAction.testWithPermissionCheck("noreply@synopsys.com", new EmailGlobalConfigModel());
    assertEquals(HttpStatus.FORBIDDEN, response.getHttpStatus());
}
Also used : ValidationResponseModel(com.synopsys.integration.alert.common.rest.model.ValidationResponseModel) 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) Test(org.junit.jupiter.api.Test)

Example 80 with AuthorizationManager

use of com.synopsys.integration.alert.common.security.authorization.AuthorizationManager in project hub-alert by blackducksoftware.

the class EmailGlobalTestActionTest method testConfigITTest.

@Test
@Tags(value = { @Tag(TestTags.DEFAULT_INTEGRATION), @Tag(TestTags.CUSTOM_EXTERNAL_CONNECTION) })
public void testConfigITTest() {
    AuthorizationManager authorizationManager = createAuthorizationManager(AuthenticationTestUtils.FULL_PERMISSIONS);
    EmailGlobalConfigurationValidator validator = new EmailGlobalConfigurationValidator();
    TestProperties testProperties = new TestProperties();
    String emailAddress = testProperties.getProperty(TestPropertyKey.TEST_EMAIL_RECIPIENT);
    JavamailPropertiesFactory javamailPropertiesFactory = new JavamailPropertiesFactory();
    EmailChannelMessagingService validEmailChannelMessagingService = createValidEmailChannelMessagingService(emailAddress);
    EmailGlobalTestAction emailGlobalTestAction = new EmailGlobalTestAction(authorizationManager, validator, validEmailChannelMessagingService, javamailPropertiesFactory, configurationAccessor);
    EmailGlobalConfigModel globalConfigModel = createValidEmailGlobalConfigModel(testProperties);
    ConfigurationTestResult testResult = emailGlobalTestAction.testConfigModelContent(emailAddress, globalConfigModel);
    assertTrue(testResult.isSuccess(), "Expected the message result to not have errors");
}
Also used : TestProperties(com.synopsys.integration.alert.test.common.TestProperties) 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) JavamailPropertiesFactory(com.synopsys.integration.alert.service.email.JavamailPropertiesFactory) EmailChannelMessagingService(com.synopsys.integration.alert.channel.email.distribution.EmailChannelMessagingService) ConfigurationTestResult(com.synopsys.integration.alert.common.message.model.ConfigurationTestResult) Test(org.junit.jupiter.api.Test) TestTags(com.synopsys.integration.alert.test.common.TestTags) Tags(org.junit.jupiter.api.Tags)

Aggregations

AuthorizationManager (com.synopsys.integration.alert.common.security.authorization.AuthorizationManager)83 Test (org.junit.jupiter.api.Test)78 DescriptorKey (com.synopsys.integration.alert.descriptor.api.model.DescriptorKey)49 PermissionKey (com.synopsys.integration.alert.common.persistence.model.PermissionKey)38 PermissionMatrixModel (com.synopsys.integration.alert.common.persistence.model.PermissionMatrixModel)38 AuthenticationTestUtils (com.synopsys.integration.alert.test.common.AuthenticationTestUtils)38 EmailGlobalConfigModel (com.synopsys.integration.alert.service.email.model.EmailGlobalConfigModel)27 EmailGlobalConfigurationValidator (com.synopsys.integration.alert.channel.email.validator.EmailGlobalConfigurationValidator)26 ChannelKey (com.synopsys.integration.alert.descriptor.api.model.ChannelKey)23 ValidationResponseModel (com.synopsys.integration.alert.common.rest.model.ValidationResponseModel)20 AlertIntegrationTest (com.synopsys.integration.alert.util.AlertIntegrationTest)16 ActionResponse (com.synopsys.integration.alert.common.action.ActionResponse)15 ConfigContextEnum (com.synopsys.integration.alert.common.enumeration.ConfigContextEnum)14 EmailGlobalConfigAccessor (com.synopsys.integration.alert.channel.email.database.accessor.EmailGlobalConfigAccessor)13 ConfigurationTestResult (com.synopsys.integration.alert.common.message.model.ConfigurationTestResult)12 EmailChannelMessagingService (com.synopsys.integration.alert.channel.email.distribution.EmailChannelMessagingService)9 JavamailPropertiesFactory (com.synopsys.integration.alert.service.email.JavamailPropertiesFactory)9 JiraServerGlobalConfigurationValidator (com.synopsys.integration.alert.channel.jira.server.validator.JiraServerGlobalConfigurationValidator)8 ValidationActionResponse (com.synopsys.integration.alert.common.action.ValidationActionResponse)8 SettingsProxyModel (com.synopsys.integration.alert.common.rest.model.SettingsProxyModel)7