Search in sources :

Example 1 with FilePersistenceUtil

use of com.synopsys.integration.alert.common.persistence.util.FilePersistenceUtil in project hub-alert by blackducksoftware.

the class SettingsEncryptionValidatorTest method validateNotInitializedTest.

@Test
public void validateNotInitializedTest() {
    MockAlertProperties alertPropertiesNoEncryption = new MockAlertProperties();
    alertPropertiesNoEncryption.setEncryptionPassword("");
    alertPropertiesNoEncryption.setEncryptionSalt("");
    FilePersistenceUtil filePersistenceUtilWithoutProperties = new FilePersistenceUtil(alertPropertiesNoEncryption, gson);
    EncryptionUtility encryptionUtilityWithoutProperties = new EncryptionUtility(alertPropertiesNoEncryption, filePersistenceUtilWithoutProperties);
    SettingsEncryptionModel settingsEncryptionModel = new SettingsEncryptionModel();
    settingsEncryptionModel.setEncryptionPassword("password");
    settingsEncryptionModel.setEncryptionGlobalSalt("globalSalt");
    SettingsEncryptionValidator validator = new SettingsEncryptionValidator(encryptionUtilityWithoutProperties, systemMessageAccessor);
    ValidationResponseModel validationResponseModel = validator.validate(settingsEncryptionModel);
    assertFalse(validationResponseModel.hasErrors());
}
Also used : ValidationResponseModel(com.synopsys.integration.alert.common.rest.model.ValidationResponseModel) FilePersistenceUtil(com.synopsys.integration.alert.common.persistence.util.FilePersistenceUtil) SettingsEncryptionModel(com.synopsys.integration.alert.component.settings.encryption.model.SettingsEncryptionModel) MockAlertProperties(com.synopsys.integration.alert.test.common.MockAlertProperties) EncryptionUtility(com.synopsys.integration.alert.common.security.EncryptionUtility) Test(org.junit.jupiter.api.Test)

Example 2 with FilePersistenceUtil

use of com.synopsys.integration.alert.common.persistence.util.FilePersistenceUtil in project hub-alert by blackducksoftware.

the class SamlManagerTest method init.

@BeforeEach
public void init() throws Exception {
    gson = new Gson();
    context = Mockito.mock(SAMLContext.class);
    parserPool = Mockito.mock(ParserPool.class);
    extendedMetadata = Mockito.mock(ExtendedMetadata.class);
    metadataManager = new CachingMetadataManager(Collections.emptyList());
    metadataManager.setKeyManager(new EmptyKeyManager());
    metadataGenerator = Mockito.mock(MetadataGenerator.class);
    currentConfiguration = Mockito.mock(ConfigurationModel.class);
    alertProperties = Mockito.mock(AlertProperties.class);
    Mockito.when(alertProperties.getAlertSecretsDir()).thenReturn("./testDB/run/secrets");
    filePersistenceUtil = new FilePersistenceUtil(alertProperties, gson);
}
Also used : ParserPool(org.opensaml.xml.parse.ParserPool) ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) FilePersistenceUtil(com.synopsys.integration.alert.common.persistence.util.FilePersistenceUtil) Gson(com.google.gson.Gson) ExtendedMetadata(org.springframework.security.saml.metadata.ExtendedMetadata) EmptyKeyManager(org.springframework.security.saml.key.EmptyKeyManager) AlertProperties(com.synopsys.integration.alert.common.AlertProperties) CachingMetadataManager(org.springframework.security.saml.metadata.CachingMetadataManager) MetadataGenerator(org.springframework.security.saml.metadata.MetadataGenerator) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 3 with FilePersistenceUtil

use of com.synopsys.integration.alert.common.persistence.util.FilePersistenceUtil in project hub-alert by blackducksoftware.

the class AuthenticationConfigurationValidatorTest method hasSamlMetadataFile.

@Test
public void hasSamlMetadataFile() {
    Map<String, FieldValueModel> keyToValues = createValidSamlValues();
    keyToValues.remove(AuthenticationDescriptor.KEY_SAML_METADATA_URL);
    keyToValues.remove(AuthenticationDescriptor.KEY_SAML_ENTITY_BASE_URL);
    FilePersistenceUtil filePersistenceUtil = Mockito.mock(FilePersistenceUtil.class);
    Mockito.when(filePersistenceUtil.uploadFileExists(Mockito.anyString())).thenReturn(true);
    AuthenticationConfigurationFieldModelValidator authenticationConfigurationValidator = new AuthenticationConfigurationFieldModelValidator(filePersistenceUtil);
    Set<AlertFieldStatus> alertFieldStatuses = authenticationConfigurationValidator.validate(new FieldModel(new AuthenticationDescriptorKey().getUniversalKey(), ConfigContextEnum.GLOBAL.name(), keyToValues));
    assertEquals(1, alertFieldStatuses.size());
}
Also used : FilePersistenceUtil(com.synopsys.integration.alert.common.persistence.util.FilePersistenceUtil) AlertFieldStatus(com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus) FieldModel(com.synopsys.integration.alert.common.rest.model.FieldModel) AuthenticationDescriptorKey(com.synopsys.integration.alert.component.authentication.descriptor.AuthenticationDescriptorKey) FieldValueModel(com.synopsys.integration.alert.common.rest.model.FieldValueModel) Test(org.junit.jupiter.api.Test)

Example 4 with FilePersistenceUtil

use of com.synopsys.integration.alert.common.persistence.util.FilePersistenceUtil in project hub-alert by blackducksoftware.

the class AuthenticationConfigurationValidatorTest method createValidatorAsserter.

private GlobalConfigurationValidatorAsserter createValidatorAsserter(Map<String, FieldValueModel> keyToValues) {
    AlertProperties mockAlertProperties = new MockAlertProperties();
    FilePersistenceUtil filePersistenceUtil = new FilePersistenceUtil(mockAlertProperties, new Gson());
    return new GlobalConfigurationValidatorAsserter(new AuthenticationDescriptorKey().getUniversalKey(), new AuthenticationConfigurationFieldModelValidator(filePersistenceUtil), keyToValues);
}
Also used : FilePersistenceUtil(com.synopsys.integration.alert.common.persistence.util.FilePersistenceUtil) MockAlertProperties(com.synopsys.integration.alert.test.common.MockAlertProperties) Gson(com.google.gson.Gson) AlertProperties(com.synopsys.integration.alert.common.AlertProperties) MockAlertProperties(com.synopsys.integration.alert.test.common.MockAlertProperties) GlobalConfigurationValidatorAsserter(com.synopsys.integration.alert.test.common.channel.GlobalConfigurationValidatorAsserter) AuthenticationDescriptorKey(com.synopsys.integration.alert.component.authentication.descriptor.AuthenticationDescriptorKey)

Example 5 with FilePersistenceUtil

use of com.synopsys.integration.alert.common.persistence.util.FilePersistenceUtil in project hub-alert by blackducksoftware.

the class SAMLStartupComponentTest method testInitialize.

@Test
public void testInitialize() throws Exception {
    SAMLContext context = Mockito.mock(SAMLContext.class);
    ParserPool parserPool = Mockito.mock(ParserPool.class);
    ExtendedMetadata extendedMetadata = Mockito.mock(ExtendedMetadata.class);
    MetadataManager metadataManager = Mockito.mock(MetadataManager.class);
    MetadataGenerator metadataGenerator = Mockito.mock(MetadataGenerator.class);
    ConfigurationModel currentConfiguration = Mockito.mock(ConfigurationModel.class);
    FilePersistenceUtil filePersistenceUtil = Mockito.mock(FilePersistenceUtil.class);
    Mockito.when(context.getCurrentConfiguration()).thenReturn(currentConfiguration);
    Mockito.when(context.isSAMLEnabled(Mockito.any(ConfigurationModel.class))).thenReturn(Boolean.TRUE.booleanValue());
    Mockito.when(context.getFieldValueOrEmpty(Mockito.any(ConfigurationModel.class), Mockito.eq(AuthenticationDescriptor.KEY_SAML_METADATA_URL))).thenReturn("metadataURL");
    Mockito.when(context.getFieldValueOrEmpty(Mockito.any(ConfigurationModel.class), Mockito.eq(AuthenticationDescriptor.KEY_SAML_ENTITY_ID))).thenReturn("entityId");
    Mockito.when(context.getFieldValueOrEmpty(Mockito.any(ConfigurationModel.class), Mockito.eq(AuthenticationDescriptor.KEY_SAML_ENTITY_BASE_URL))).thenReturn("baseURL");
    SAMLManager samlManager = new SAMLManager(parserPool, extendedMetadata, metadataManager, metadataGenerator, filePersistenceUtil, context);
    SAMLStartupComponent startupComponent = new SAMLStartupComponent(samlManager);
    startupComponent.initializeComponent();
    Mockito.verify(context).disableSAML();
}
Also used : ParserPool(org.opensaml.xml.parse.ParserPool) ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) MetadataManager(org.springframework.security.saml.metadata.MetadataManager) FilePersistenceUtil(com.synopsys.integration.alert.common.persistence.util.FilePersistenceUtil) SAMLContext(com.synopsys.integration.alert.component.authentication.security.saml.SAMLContext) ExtendedMetadata(org.springframework.security.saml.metadata.ExtendedMetadata) SAMLManager(com.synopsys.integration.alert.component.authentication.security.saml.SAMLManager) MetadataGenerator(org.springframework.security.saml.metadata.MetadataGenerator) Test(org.junit.jupiter.api.Test)

Aggregations

FilePersistenceUtil (com.synopsys.integration.alert.common.persistence.util.FilePersistenceUtil)11 Test (org.junit.jupiter.api.Test)7 EncryptionUtility (com.synopsys.integration.alert.common.security.EncryptionUtility)5 MockAlertProperties (com.synopsys.integration.alert.test.common.MockAlertProperties)5 Gson (com.google.gson.Gson)4 AlertProperties (com.synopsys.integration.alert.common.AlertProperties)4 SettingsEncryptionModel (com.synopsys.integration.alert.component.settings.encryption.model.SettingsEncryptionModel)4 ValidationResponseModel (com.synopsys.integration.alert.common.rest.model.ValidationResponseModel)3 ParserPool (org.opensaml.xml.parse.ParserPool)3 ExtendedMetadata (org.springframework.security.saml.metadata.ExtendedMetadata)3 MetadataGenerator (org.springframework.security.saml.metadata.MetadataGenerator)3 ConfigurationModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationModel)2 AuthenticationDescriptorKey (com.synopsys.integration.alert.component.authentication.descriptor.AuthenticationDescriptorKey)2 SAMLContext (com.synopsys.integration.alert.component.authentication.security.saml.SAMLContext)2 SAMLManager (com.synopsys.integration.alert.component.authentication.security.saml.SAMLManager)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 MetadataManager (org.springframework.security.saml.metadata.MetadataManager)2 AlertConfigurationException (com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException)1 AlertFieldStatus (com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus)1 FieldModel (com.synopsys.integration.alert.common.rest.model.FieldModel)1