Search in sources :

Example 1 with DescriptorKey

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

the class ConfigurationValidationHelperTest method testValidationSuccess.

@Test
public void testValidationSuccess() {
    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));
    ConfigurationValidationHelper validationHelper = new ConfigurationValidationHelper(authorizationManager, ConfigContextEnum.GLOBAL, descriptorKey);
    ValidationActionResponse response = validationHelper.validate(() -> ValidationResponseModel.success());
    assertEquals(HttpStatus.OK, response.getHttpStatus());
}
Also used : PermissionMatrixModel(com.synopsys.integration.alert.common.persistence.model.PermissionMatrixModel) ValidationActionResponse(com.synopsys.integration.alert.common.action.ValidationActionResponse) 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) Test(org.junit.jupiter.api.Test)

Example 2 with DescriptorKey

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

the class ConfigurationValidationHelperTest method testValidationForbidden.

@Test
public void testValidationForbidden() {
    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));
    ConfigurationValidationHelper validationHelper = new ConfigurationValidationHelper(authorizationManager, ConfigContextEnum.GLOBAL, descriptorKey);
    ValidationActionResponse response = validationHelper.validate(() -> ValidationResponseModel.success());
    assertEquals(HttpStatus.FORBIDDEN, response.getHttpStatus());
}
Also used : PermissionMatrixModel(com.synopsys.integration.alert.common.persistence.model.PermissionMatrixModel) ValidationActionResponse(com.synopsys.integration.alert.common.action.ValidationActionResponse) 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) Test(org.junit.jupiter.api.Test)

Example 3 with DescriptorKey

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

the class DefaultDescriptorGlobalConfigUtilityTest method testGetFieldModelActionNull.

@Test
public void testGetFieldModelActionNull() throws Exception {
    DescriptorKey descriptorKey = createDescriptorKey();
    FieldModel fieldModel = new FieldModel(descriptorKey.getUniversalKey(), ConfigContextEnum.GLOBAL.name(), Map.of());
    ConfigurationModelConfigurationAccessor configurationModelConfigurationAccessor = Mockito.mock(ConfigurationModelConfigurationAccessor.class);
    ConfigurationFieldModelConverter converter = Mockito.mock(ConfigurationFieldModelConverter.class);
    ConfigurationModel configurationModel = Mockito.mock(ConfigurationModel.class);
    ApiAction apiAction = Mockito.mock(ApiAction.class);
    Mockito.when(configurationModelConfigurationAccessor.getConfigurationsByDescriptorKeyAndContext(Mockito.any(DescriptorKey.class), Mockito.any(ConfigContextEnum.class))).thenReturn(List.of(configurationModel));
    Mockito.when(converter.convertToFieldModel(Mockito.any())).thenReturn(fieldModel);
    Mockito.when(apiAction.afterGetAction(Mockito.eq(fieldModel))).thenReturn(null);
    DefaultDescriptorGlobalConfigUtility configUtility = new DefaultDescriptorGlobalConfigUtility(descriptorKey, configurationModelConfigurationAccessor, apiAction, converter);
    Optional<FieldModel> actualFieldModel = configUtility.getFieldModel();
    assertFalse(actualFieldModel.isPresent());
}
Also used : ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) ApiAction(com.synopsys.integration.alert.common.action.ApiAction) DescriptorKey(com.synopsys.integration.alert.descriptor.api.model.DescriptorKey) ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) FieldModel(com.synopsys.integration.alert.common.rest.model.FieldModel) ConfigurationModelConfigurationAccessor(com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor) ConfigContextEnum(com.synopsys.integration.alert.common.enumeration.ConfigContextEnum) ConfigurationFieldModelConverter(com.synopsys.integration.alert.common.persistence.util.ConfigurationFieldModelConverter) Test(org.junit.jupiter.api.Test)

Example 4 with DescriptorKey

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

the class DefaultDescriptorGlobalConfigUtilityTest method testGetConfiguration.

@Test
public void testGetConfiguration() throws Exception {
    DescriptorKey descriptorKey = createDescriptorKey();
    ConfigurationModelConfigurationAccessor configurationModelConfigurationAccessor = Mockito.mock(ConfigurationModelConfigurationAccessor.class);
    DefaultDescriptorGlobalConfigUtility configUtility = new DefaultDescriptorGlobalConfigUtility(descriptorKey, configurationModelConfigurationAccessor, null, null);
    assertFalse(configUtility.getConfiguration().isPresent());
    ConfigurationModel configurationModel = Mockito.mock(ConfigurationModel.class);
    Mockito.when(configurationModelConfigurationAccessor.getConfigurationsByDescriptorKeyAndContext(Mockito.any(DescriptorKey.class), Mockito.any(ConfigContextEnum.class))).thenReturn(List.of(configurationModel));
    assertTrue(configUtility.getConfiguration().isPresent());
}
Also used : ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) DescriptorKey(com.synopsys.integration.alert.descriptor.api.model.DescriptorKey) ConfigurationModelConfigurationAccessor(com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor) ConfigContextEnum(com.synopsys.integration.alert.common.enumeration.ConfigContextEnum) Test(org.junit.jupiter.api.Test)

Example 5 with DescriptorKey

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

the class DefaultDescriptorGlobalConfigUtilityTest method testGetFieldModelEmptyConfiguration.

@Test
public void testGetFieldModelEmptyConfiguration() throws Exception {
    DescriptorKey descriptorKey = createDescriptorKey();
    ConfigurationModelConfigurationAccessor configurationModelConfigurationAccessor = Mockito.mock(ConfigurationModelConfigurationAccessor.class);
    ConfigurationFieldModelConverter converter = Mockito.mock(ConfigurationFieldModelConverter.class);
    DefaultDescriptorGlobalConfigUtility configUtility = new DefaultDescriptorGlobalConfigUtility(descriptorKey, configurationModelConfigurationAccessor, null, converter);
    assertFalse(configUtility.getFieldModel().isPresent());
}
Also used : DescriptorKey(com.synopsys.integration.alert.descriptor.api.model.DescriptorKey) ConfigurationModelConfigurationAccessor(com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor) ConfigurationFieldModelConverter(com.synopsys.integration.alert.common.persistence.util.ConfigurationFieldModelConverter) Test(org.junit.jupiter.api.Test)

Aggregations

DescriptorKey (com.synopsys.integration.alert.descriptor.api.model.DescriptorKey)91 Test (org.junit.jupiter.api.Test)72 PermissionKey (com.synopsys.integration.alert.common.persistence.model.PermissionKey)42 PermissionMatrixModel (com.synopsys.integration.alert.common.persistence.model.PermissionMatrixModel)42 AuthenticationTestUtils (com.synopsys.integration.alert.test.common.AuthenticationTestUtils)41 AuthorizationManager (com.synopsys.integration.alert.common.security.authorization.AuthorizationManager)39 ConfigurationFieldModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel)29 ConfigurationModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationModel)28 ConfigContextEnum (com.synopsys.integration.alert.common.enumeration.ConfigContextEnum)23 ConfigurationFieldModelConverter (com.synopsys.integration.alert.common.persistence.util.ConfigurationFieldModelConverter)23 ChannelKey (com.synopsys.integration.alert.descriptor.api.model.ChannelKey)23 ActionResponse (com.synopsys.integration.alert.common.action.ActionResponse)21 ConfigurationModelConfigurationAccessor (com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor)18 DescriptorAccessor (com.synopsys.integration.alert.common.persistence.accessor.DescriptorAccessor)17 FieldModel (com.synopsys.integration.alert.common.rest.model.FieldModel)17 ValidationActionResponse (com.synopsys.integration.alert.common.action.ValidationActionResponse)13 EmailGlobalConfigurationValidator (com.synopsys.integration.alert.channel.email.validator.EmailGlobalConfigurationValidator)12 DefinedFieldModel (com.synopsys.integration.alert.common.persistence.model.DefinedFieldModel)12 EncryptionUtility (com.synopsys.integration.alert.common.security.EncryptionUtility)12 EmailGlobalConfigModel (com.synopsys.integration.alert.service.email.model.EmailGlobalConfigModel)12