Search in sources :

Example 51 with AuthorizationManager

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

the class SettingsProxyTestActionTestIT method missingTargetUrlTest.

@Test
void missingTargetUrlTest() {
    SettingsProxyModel settingsProxyModel = createSettingsProxyModel(testProperties);
    AuthorizationManager authorizationManager = createAuthorizationManager(AuthenticationTestUtils.FULL_PERMISSIONS);
    settingsProxyTestAction = new SettingsProxyTestAction(authorizationManager, settingsProxyValidator, settingsDescriptorKey, proxyTestService, settingsProxyConfigAccessor);
    ActionResponse<ValidationResponseModel> testResult = settingsProxyTestAction.testWithPermissionCheck("", settingsProxyModel);
    assertTrue(testResult.isSuccessful());
    assertTrue(testResult.getContent().isPresent());
    ValidationResponseModel validationResponseModel = testResult.getContent().get();
    assertTrue(validationResponseModel.hasErrors());
}
Also used : ValidationResponseModel(com.synopsys.integration.alert.common.rest.model.ValidationResponseModel) SettingsProxyTestAction(com.synopsys.integration.alert.component.settings.proxy.action.SettingsProxyTestAction) SettingsProxyModel(com.synopsys.integration.alert.common.rest.model.SettingsProxyModel) AuthorizationManager(com.synopsys.integration.alert.common.security.authorization.AuthorizationManager) AlertIntegrationTest(com.synopsys.integration.alert.util.AlertIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 52 with AuthorizationManager

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

the class SettingsProxyTestActionTestIT method testWithPermissionCheckTest.

@Test
void testWithPermissionCheckTest() {
    SettingsProxyModel settingsProxyModel = createSettingsProxyModel(testProperties);
    AuthorizationManager authorizationManager = createAuthorizationManager(AuthenticationTestUtils.FULL_PERMISSIONS);
    settingsProxyTestAction = new SettingsProxyTestAction(authorizationManager, settingsProxyValidator, settingsDescriptorKey, proxyTestService, settingsProxyConfigAccessor);
    ActionResponse<ValidationResponseModel> testResult = settingsProxyTestAction.testWithPermissionCheck(validTargetUrl, settingsProxyModel);
    assertTrue(testResult.isSuccessful());
    assertTrue(testResult.getContent().isPresent());
    ValidationResponseModel validationResponseModel = testResult.getContent().get();
    assertFalse(validationResponseModel.hasErrors());
}
Also used : ValidationResponseModel(com.synopsys.integration.alert.common.rest.model.ValidationResponseModel) SettingsProxyTestAction(com.synopsys.integration.alert.component.settings.proxy.action.SettingsProxyTestAction) SettingsProxyModel(com.synopsys.integration.alert.common.rest.model.SettingsProxyModel) AuthorizationManager(com.synopsys.integration.alert.common.security.authorization.AuthorizationManager) AlertIntegrationTest(com.synopsys.integration.alert.util.AlertIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 53 with AuthorizationManager

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

the class TaskActionTest method testReadTasks.

@Test
public void testReadTasks() {
    Long expectedDelay = 1000L;
    TaskScheduler scheduler = Mockito.mock(TaskScheduler.class);
    ScheduledFuture scheduledFuture = Mockito.mock(ScheduledFuture.class);
    Mockito.when(scheduledFuture.isDone()).thenReturn(Boolean.FALSE);
    Mockito.when(scheduledFuture.getDelay(Mockito.eq(TimeUnit.MILLISECONDS))).thenReturn(expectedDelay);
    Mockito.when(scheduler.scheduleAtFixedRate(Mockito.any(), Mockito.anyLong())).thenReturn(scheduledFuture);
    ScheduledTask task = new ScheduledTask(scheduler) {

        @Override
        public void runTask() {
        }

        @Override
        public String scheduleCronExpression() {
            return ScheduledTask.EVERY_MINUTE_CRON_EXPRESSION;
        }
    };
    TaskManagementDescriptorKey descriptorKey = new TaskManagementDescriptorKey();
    AuthorizationManager authorizationManager = Mockito.mock(AuthorizationManager.class);
    Mockito.when(authorizationManager.hasReadPermission(Mockito.eq(ConfigContextEnum.GLOBAL), Mockito.eq(descriptorKey))).thenReturn(Boolean.TRUE);
    TaskManager taskManager = new TaskManager();
    taskManager.registerTask(task);
    taskManager.scheduleExecutionAtFixedRate(expectedDelay, task.getTaskName());
    TaskActions actions = new TaskActions(descriptorKey, authorizationManager, taskManager);
    ActionResponse<MultiTaskMetaDataModel> response = actions.getTasks();
    assertTrue(response.isSuccessful());
    assertTrue(response.hasContent());
    MultiTaskMetaDataModel tasksModel = response.getContent().orElse(new MultiTaskMetaDataModel(List.of()));
    TaskMetaData model = tasksModel.getTasks().stream().findFirst().orElse(null);
    assertNotNull(model);
    assertNotNull(task.getTaskName());
    assertEquals(task.getFormatedNextRunTime().orElse(""), model.getNextRunTime());
}
Also used : TaskManagementDescriptorKey(com.synopsys.integration.alert.component.tasks.TaskManagementDescriptorKey) TaskManager(com.synopsys.integration.alert.api.task.TaskManager) TaskMetaData(com.synopsys.integration.alert.api.task.TaskMetaData) ScheduledTask(com.synopsys.integration.alert.api.task.ScheduledTask) AuthorizationManager(com.synopsys.integration.alert.common.security.authorization.AuthorizationManager) TaskScheduler(org.springframework.scheduling.TaskScheduler) ScheduledFuture(java.util.concurrent.ScheduledFuture) Test(org.junit.jupiter.api.Test)

Example 54 with AuthorizationManager

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

the class TaskActionTest method testReadForbiddenTasks.

@Test
public void testReadForbiddenTasks() {
    TaskManagementDescriptorKey descriptorKey = new TaskManagementDescriptorKey();
    AuthorizationManager authorizationManager = Mockito.mock(AuthorizationManager.class);
    Mockito.when(authorizationManager.hasReadPermission(Mockito.eq(ConfigContextEnum.GLOBAL), Mockito.eq(descriptorKey))).thenReturn(Boolean.FALSE);
    TaskManager taskManager = new TaskManager();
    TaskActions actions = new TaskActions(descriptorKey, authorizationManager, taskManager);
    ActionResponse<MultiTaskMetaDataModel> response = actions.getTasks();
    assertTrue(response.isError());
    assertFalse(response.hasContent());
}
Also used : TaskManagementDescriptorKey(com.synopsys.integration.alert.component.tasks.TaskManagementDescriptorKey) TaskManager(com.synopsys.integration.alert.api.task.TaskManager) AuthorizationManager(com.synopsys.integration.alert.common.security.authorization.AuthorizationManager) Test(org.junit.jupiter.api.Test)

Example 55 with AuthorizationManager

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

the class ConfigurationCrudHelperTest method testGetOneEmpty.

@Test
public void testGetOneEmpty() {
    AuthenticationTestUtils authenticationTestUtils = new AuthenticationTestUtils();
    DescriptorKey descriptorKey = new ChannelKey("channel_key", "channel-display-name");
    PermissionKey permissionKey = new PermissionKey(ConfigContextEnum.GLOBAL.name(), descriptorKey.getUniversalKey());
    Map<PermissionKey, Integer> permissions = Map.of(permissionKey, 255);
    AuthorizationManager authorizationManager = authenticationTestUtils.createAuthorizationManagerWithCurrentUserSet("admin", "admin", () -> new PermissionMatrixModel(permissions));
    ConfigurationCrudHelper configurationHelper = new ConfigurationCrudHelper(authorizationManager, ConfigContextEnum.GLOBAL, descriptorKey);
    ActionResponse response = configurationHelper.getOne(() -> createEmptyOptional());
    assertEquals(HttpStatus.NOT_FOUND, response.getHttpStatus());
}
Also used : PermissionMatrixModel(com.synopsys.integration.alert.common.persistence.model.PermissionMatrixModel) PermissionKey(com.synopsys.integration.alert.common.persistence.model.PermissionKey) ChannelKey(com.synopsys.integration.alert.descriptor.api.model.ChannelKey) 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) ActionResponse(com.synopsys.integration.alert.common.action.ActionResponse) Test(org.junit.jupiter.api.Test)

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