Search in sources :

Example 21 with ChannelKey

use of com.synopsys.integration.alert.descriptor.api.model.ChannelKey in project hub-alert by blackducksoftware.

the class ConfigurationCrudHelperTest method testCreateForbidden.

@Test
public void testCreateForbidden() {
    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, AuthenticationTestUtils.NO_PERMISSIONS);
    AuthorizationManager authorizationManager = authenticationTestUtils.createAuthorizationManagerWithCurrentUserSet("admin", "admin", () -> new PermissionMatrixModel(permissions));
    ConfigurationCrudHelper configurationHelper = new ConfigurationCrudHelper(authorizationManager, ConfigContextEnum.GLOBAL, descriptorKey);
    ActionResponse response = configurationHelper.create(() -> ValidationResponseModel.success(), () -> Boolean.FALSE, () -> createDefault());
    assertEquals(HttpStatus.FORBIDDEN, 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)

Example 22 with ChannelKey

use of com.synopsys.integration.alert.descriptor.api.model.ChannelKey in project hub-alert by blackducksoftware.

the class ConfigurationCrudHelperTest method testUpdateException.

@Test
public void testUpdateException() {
    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, AuthenticationTestUtils.FULL_PERMISSIONS);
    AuthorizationManager authorizationManager = authenticationTestUtils.createAuthorizationManagerWithCurrentUserSet("admin", "admin", () -> new PermissionMatrixModel(permissions));
    ThrowingSupplier createdModelSupplier = () -> {
        throw new AlertException("error getting test message");
    };
    ConfigurationCrudHelper configurationHelper = new ConfigurationCrudHelper(authorizationManager, ConfigContextEnum.GLOBAL, descriptorKey);
    ActionResponse response = configurationHelper.update(() -> ValidationResponseModel.success(), () -> true, createdModelSupplier);
    assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, 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) ThrowingSupplier(com.synopsys.integration.function.ThrowingSupplier) AuthorizationManager(com.synopsys.integration.alert.common.security.authorization.AuthorizationManager) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException) ActionResponse(com.synopsys.integration.alert.common.action.ActionResponse) Test(org.junit.jupiter.api.Test)

Example 23 with ChannelKey

use of com.synopsys.integration.alert.descriptor.api.model.ChannelKey in project hub-alert by blackducksoftware.

the class ConfigurationCrudHelperTest method testUpdateModelNotFound.

@Test
public void testUpdateModelNotFound() {
    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, AuthenticationTestUtils.FULL_PERMISSIONS);
    AuthorizationManager authorizationManager = authenticationTestUtils.createAuthorizationManagerWithCurrentUserSet("admin", "admin", () -> new PermissionMatrixModel(permissions));
    ConfigurationCrudHelper configurationHelper = new ConfigurationCrudHelper(authorizationManager, ConfigContextEnum.GLOBAL, descriptorKey);
    ActionResponse response = configurationHelper.update(() -> ValidationResponseModel.success(), () -> false, () -> createDefault());
    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)

Example 24 with ChannelKey

use of com.synopsys.integration.alert.descriptor.api.model.ChannelKey in project hub-alert by blackducksoftware.

the class ConfigurationCrudHelperTest method testCreateValidationError.

@Test
public void testCreateValidationError() {
    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.create(() -> ValidationResponseModel.generalError("Validation Error"), () -> Boolean.FALSE, () -> createDefault());
    assertEquals(HttpStatus.BAD_REQUEST, 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)

Example 25 with ChannelKey

use of com.synopsys.integration.alert.descriptor.api.model.ChannelKey in project hub-alert by blackducksoftware.

the class ConfigurationCrudHelperTest method testDeleteModelNotFound.

@Test
public void testDeleteModelNotFound() {
    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, AuthenticationTestUtils.FULL_PERMISSIONS);
    AuthorizationManager authorizationManager = authenticationTestUtils.createAuthorizationManagerWithCurrentUserSet("admin", "admin", () -> new PermissionMatrixModel(permissions));
    ConfigurationCrudHelper configurationHelper = new ConfigurationCrudHelper(authorizationManager, ConfigContextEnum.GLOBAL, descriptorKey);
    ActionResponse response = configurationHelper.delete(() -> false, () -> {
    });
    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

ChannelKey (com.synopsys.integration.alert.descriptor.api.model.ChannelKey)33 Test (org.junit.jupiter.api.Test)28 PermissionKey (com.synopsys.integration.alert.common.persistence.model.PermissionKey)23 PermissionMatrixModel (com.synopsys.integration.alert.common.persistence.model.PermissionMatrixModel)23 AuthorizationManager (com.synopsys.integration.alert.common.security.authorization.AuthorizationManager)23 DescriptorKey (com.synopsys.integration.alert.descriptor.api.model.DescriptorKey)23 AuthenticationTestUtils (com.synopsys.integration.alert.test.common.AuthenticationTestUtils)23 ActionResponse (com.synopsys.integration.alert.common.action.ActionResponse)15 ValidationActionResponse (com.synopsys.integration.alert.common.action.ValidationActionResponse)8 DistributionJobDetailsModel (com.synopsys.integration.alert.common.persistence.model.job.details.DistributionJobDetailsModel)6 UUID (java.util.UUID)6 AlertException (com.synopsys.integration.alert.api.common.model.exception.AlertException)5 ValidationResponseModel (com.synopsys.integration.alert.common.rest.model.ValidationResponseModel)4 JobDetailsAccessor (com.synopsys.integration.alert.common.persistence.accessor.JobDetailsAccessor)3 ProcessingAuditAccessor (com.synopsys.integration.alert.common.persistence.accessor.ProcessingAuditAccessor)3 DistributionEvent (com.synopsys.integration.alert.processor.api.distribute.DistributionEvent)3 Optional (java.util.Optional)3 Set (java.util.Set)3 Mockito (org.mockito.Mockito)3 AzureBoardsJobDetailsEntity (com.synopsys.integration.alert.database.job.azure.boards.AzureBoardsJobDetailsEntity)2