Search in sources :

Example 1 with DefaultConfigurationModelConfigurationAccessor

use of com.synopsys.integration.alert.database.api.DefaultConfigurationModelConfigurationAccessor in project hub-alert by blackducksoftware.

the class PhoneHomeTest method runTest.

@Test
public void runTest() {
    RestApiAuditAccessor auditAccessor = Mockito.mock(RestApiAuditAccessor.class);
    Mockito.when(auditAccessor.findFirstByJobId(Mockito.any())).thenReturn(Optional.empty());
    TaskScheduler taskScheduler = Mockito.mock(TaskScheduler.class);
    ProxyManager proxyManager = Mockito.mock(ProxyManager.class);
    Mockito.when(proxyManager.createProxyInfoForHost(Mockito.anyString())).thenReturn(ProxyInfo.NO_PROXY_INFO);
    AboutReader aboutReader = Mockito.mock(AboutReader.class);
    Mockito.when(aboutReader.getProductVersion()).thenReturn(TEST_VERSION);
    JobAccessor jobAccessor = Mockito.mock(JobAccessor.class);
    // FIXME implement mocks
    DefaultConfigurationModelConfigurationAccessor configurationModelConfigurationAccessor = Mockito.mock(DefaultConfigurationModelConfigurationAccessor.class);
    ConfigurationModel config = Mockito.mock(ConfigurationModel.class);
    Mockito.when(configurationModelConfigurationAccessor.getConfigurationsByDescriptorKey(Mockito.any(DescriptorKey.class))).thenReturn(List.of(config));
    DescriptorMap descriptorMap = Mockito.mock(DescriptorMap.class);
    Descriptor descriptor = Mockito.mock(Descriptor.class);
    DescriptorKey descriptorKey = Mockito.mock(DescriptorKey.class);
    Mockito.when(descriptorKey.getUniversalKey()).thenReturn(TEST_DESCRIPTOR_NAME);
    Mockito.when(descriptorMap.getDescriptorMap()).thenReturn(Collections.singletonMap(descriptorKey, descriptor));
    List<ProviderPhoneHomeHandler> providerHandlers = List.of();
    ProviderKey providerKey = new BlackDuckProviderKey();
    PhoneHomeTask phoneHomeTask = new PhoneHomeTask(taskScheduler, aboutReader, jobAccessor, configurationModelConfigurationAccessor, null, proxyManager, new Gson(), auditAccessor, providerHandlers, providerKey);
    try {
        phoneHomeTask.run();
    } catch (Exception e) {
        fail("Unexpected exception");
    }
}
Also used : ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) BlackDuckProviderKey(com.synopsys.integration.alert.descriptor.api.BlackDuckProviderKey) PhoneHomeTask(com.synopsys.integration.alert.task.PhoneHomeTask) ProxyManager(com.synopsys.integration.alert.common.rest.proxy.ProxyManager) DescriptorKey(com.synopsys.integration.alert.descriptor.api.model.DescriptorKey) Gson(com.google.gson.Gson) TaskScheduler(org.springframework.scheduling.TaskScheduler) ProviderPhoneHomeHandler(com.synopsys.integration.alert.api.provider.ProviderPhoneHomeHandler) AboutReader(com.synopsys.integration.alert.web.api.about.AboutReader) JobAccessor(com.synopsys.integration.alert.common.persistence.accessor.JobAccessor) DescriptorMap(com.synopsys.integration.alert.common.descriptor.DescriptorMap) ProviderKey(com.synopsys.integration.alert.descriptor.api.model.ProviderKey) BlackDuckProviderKey(com.synopsys.integration.alert.descriptor.api.BlackDuckProviderKey) Descriptor(com.synopsys.integration.alert.common.descriptor.Descriptor) RestApiAuditAccessor(com.synopsys.integration.alert.common.persistence.accessor.RestApiAuditAccessor) DefaultConfigurationModelConfigurationAccessor(com.synopsys.integration.alert.database.api.DefaultConfigurationModelConfigurationAccessor) Test(org.junit.jupiter.api.Test)

Example 2 with DefaultConfigurationModelConfigurationAccessor

use of com.synopsys.integration.alert.database.api.DefaultConfigurationModelConfigurationAccessor in project hub-alert by blackducksoftware.

the class LdapManagerTest method testAuthenticationTypeDigest.

@Test
public void testAuthenticationTypeDigest() throws Exception {
    final String authenticationType = "digest";
    ConfigurationModel configurationModel = createConfigurationModel();
    configurationModel.getField(AuthenticationDescriptor.KEY_LDAP_AUTHENTICATION_TYPE).get().setFieldValue(authenticationType);
    DefaultConfigurationModelConfigurationAccessor configurationModelConfigurationAccessor = Mockito.mock(DefaultConfigurationModelConfigurationAccessor.class);
    Mockito.when(configurationModelConfigurationAccessor.getConfigurationsByDescriptorKey(Mockito.any(DescriptorKey.class))).thenReturn(List.of(configurationModel));
    UserManagementAuthoritiesPopulator authoritiesPopulator = Mockito.mock(UserManagementAuthoritiesPopulator.class);
    LdapManager ldapManager = new LdapManager(AUTHENTICATION_DESCRIPTOR_KEY, configurationModelConfigurationAccessor, authoritiesPopulator, LDAP_USER_CONTEXT_MAPPER);
    ldapManager.getAuthenticationProvider();
    FieldUtility updatedProperties = ldapManager.getCurrentConfiguration();
    assertEquals(authenticationType, updatedProperties.getField(AuthenticationDescriptor.KEY_LDAP_AUTHENTICATION_TYPE).flatMap(ConfigurationFieldModel::getFieldValue).orElse(null));
}
Also used : ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) UserManagementAuthoritiesPopulator(com.synopsys.integration.alert.component.authentication.security.UserManagementAuthoritiesPopulator) DescriptorKey(com.synopsys.integration.alert.descriptor.api.model.DescriptorKey) AuthenticationDescriptorKey(com.synopsys.integration.alert.component.authentication.descriptor.AuthenticationDescriptorKey) FieldUtility(com.synopsys.integration.alert.common.persistence.accessor.FieldUtility) DefaultConfigurationModelConfigurationAccessor(com.synopsys.integration.alert.database.api.DefaultConfigurationModelConfigurationAccessor) Test(org.junit.jupiter.api.Test)

Example 3 with DefaultConfigurationModelConfigurationAccessor

use of com.synopsys.integration.alert.database.api.DefaultConfigurationModelConfigurationAccessor in project hub-alert by blackducksoftware.

the class LdapManagerTest method testAuthenticationTypeSimple.

@Test
public void testAuthenticationTypeSimple() throws Exception {
    final String authenticationType = "simple";
    ConfigurationModel configurationModel = createConfigurationModel();
    configurationModel.getField(AuthenticationDescriptor.KEY_LDAP_AUTHENTICATION_TYPE).get().setFieldValue(authenticationType);
    DefaultConfigurationModelConfigurationAccessor configurationModelConfigurationAccessor = Mockito.mock(DefaultConfigurationModelConfigurationAccessor.class);
    Mockito.when(configurationModelConfigurationAccessor.getConfigurationsByDescriptorKey(Mockito.any(DescriptorKey.class))).thenReturn(List.of(configurationModel));
    UserManagementAuthoritiesPopulator authoritiesPopulator = Mockito.mock(UserManagementAuthoritiesPopulator.class);
    LdapManager ldapManager = new LdapManager(AUTHENTICATION_DESCRIPTOR_KEY, configurationModelConfigurationAccessor, authoritiesPopulator, LDAP_USER_CONTEXT_MAPPER);
    ldapManager.getAuthenticationProvider();
    FieldUtility updatedProperties = ldapManager.getCurrentConfiguration();
    assertEquals(authenticationType, updatedProperties.getField(AuthenticationDescriptor.KEY_LDAP_AUTHENTICATION_TYPE).flatMap(ConfigurationFieldModel::getFieldValue).orElse(null));
}
Also used : ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) UserManagementAuthoritiesPopulator(com.synopsys.integration.alert.component.authentication.security.UserManagementAuthoritiesPopulator) DescriptorKey(com.synopsys.integration.alert.descriptor.api.model.DescriptorKey) AuthenticationDescriptorKey(com.synopsys.integration.alert.component.authentication.descriptor.AuthenticationDescriptorKey) FieldUtility(com.synopsys.integration.alert.common.persistence.accessor.FieldUtility) DefaultConfigurationModelConfigurationAccessor(com.synopsys.integration.alert.database.api.DefaultConfigurationModelConfigurationAccessor) Test(org.junit.jupiter.api.Test)

Example 4 with DefaultConfigurationModelConfigurationAccessor

use of com.synopsys.integration.alert.database.api.DefaultConfigurationModelConfigurationAccessor in project hub-alert by blackducksoftware.

the class LdapManagerTest method testExceptionOnAuthenticator.

@Test
public void testExceptionOnAuthenticator() {
    final String userSearchBase = "";
    final String userSearchFilter = "";
    final String userDNPatterns = "";
    ConfigurationModel configurationModel = createConfigurationModel();
    configurationModel.getField(AuthenticationDescriptor.KEY_LDAP_USER_SEARCH_BASE).get().setFieldValue(userSearchBase);
    configurationModel.getField(AuthenticationDescriptor.KEY_LDAP_USER_SEARCH_FILTER).get().setFieldValue(userSearchFilter);
    configurationModel.getField(AuthenticationDescriptor.KEY_LDAP_USER_DN_PATTERNS).get().setFieldValue(userDNPatterns);
    DefaultConfigurationModelConfigurationAccessor configurationModelConfigurationAccessor = Mockito.mock(DefaultConfigurationModelConfigurationAccessor.class);
    Mockito.when(configurationModelConfigurationAccessor.getConfigurationsByDescriptorKey(Mockito.any(DescriptorKey.class))).thenReturn(List.of(configurationModel));
    UserManagementAuthoritiesPopulator authoritiesPopulator = Mockito.mock(UserManagementAuthoritiesPopulator.class);
    LdapManager ldapManager = new LdapManager(AUTHENTICATION_DESCRIPTOR_KEY, configurationModelConfigurationAccessor, authoritiesPopulator, LDAP_USER_CONTEXT_MAPPER);
    try {
        ldapManager.getAuthenticationProvider();
        fail();
    } catch (AlertConfigurationException ex) {
    // exception occurred
    }
}
Also used : ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) UserManagementAuthoritiesPopulator(com.synopsys.integration.alert.component.authentication.security.UserManagementAuthoritiesPopulator) DescriptorKey(com.synopsys.integration.alert.descriptor.api.model.DescriptorKey) AuthenticationDescriptorKey(com.synopsys.integration.alert.component.authentication.descriptor.AuthenticationDescriptorKey) DefaultConfigurationModelConfigurationAccessor(com.synopsys.integration.alert.database.api.DefaultConfigurationModelConfigurationAccessor) AlertConfigurationException(com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException) Test(org.junit.jupiter.api.Test)

Example 5 with DefaultConfigurationModelConfigurationAccessor

use of com.synopsys.integration.alert.database.api.DefaultConfigurationModelConfigurationAccessor in project hub-alert by blackducksoftware.

the class LdapManagerTest method testAuthenticationProviderCreated.

@Test
public void testAuthenticationProviderCreated() throws Exception {
    ConfigurationModel configurationModel = createConfigurationModel();
    DefaultConfigurationModelConfigurationAccessor configurationModelConfigurationAccessor = Mockito.mock(DefaultConfigurationModelConfigurationAccessor.class);
    Mockito.when(configurationModelConfigurationAccessor.getConfigurationsByDescriptorKey(Mockito.any(DescriptorKey.class))).thenReturn(List.of(configurationModel));
    UserManagementAuthoritiesPopulator authoritiesPopulator = Mockito.mock(UserManagementAuthoritiesPopulator.class);
    LdapManager ldapManager = new LdapManager(AUTHENTICATION_DESCRIPTOR_KEY, configurationModelConfigurationAccessor, authoritiesPopulator, LDAP_USER_CONTEXT_MAPPER);
    assertNotNull(ldapManager.getAuthenticationProvider());
}
Also used : ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) UserManagementAuthoritiesPopulator(com.synopsys.integration.alert.component.authentication.security.UserManagementAuthoritiesPopulator) DescriptorKey(com.synopsys.integration.alert.descriptor.api.model.DescriptorKey) AuthenticationDescriptorKey(com.synopsys.integration.alert.component.authentication.descriptor.AuthenticationDescriptorKey) DefaultConfigurationModelConfigurationAccessor(com.synopsys.integration.alert.database.api.DefaultConfigurationModelConfigurationAccessor) Test(org.junit.jupiter.api.Test)

Aggregations

DefaultConfigurationModelConfigurationAccessor (com.synopsys.integration.alert.database.api.DefaultConfigurationModelConfigurationAccessor)9 ConfigurationModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationModel)8 DescriptorKey (com.synopsys.integration.alert.descriptor.api.model.DescriptorKey)8 Test (org.junit.jupiter.api.Test)8 AuthenticationDescriptorKey (com.synopsys.integration.alert.component.authentication.descriptor.AuthenticationDescriptorKey)7 UserManagementAuthoritiesPopulator (com.synopsys.integration.alert.component.authentication.security.UserManagementAuthoritiesPopulator)7 FieldUtility (com.synopsys.integration.alert.common.persistence.accessor.FieldUtility)3 AlertConfigurationException (com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException)2 ConfigurationFieldModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel)2 Gson (com.google.gson.Gson)1 ProviderPhoneHomeHandler (com.synopsys.integration.alert.api.provider.ProviderPhoneHomeHandler)1 Descriptor (com.synopsys.integration.alert.common.descriptor.Descriptor)1 DescriptorMap (com.synopsys.integration.alert.common.descriptor.DescriptorMap)1 JobAccessor (com.synopsys.integration.alert.common.persistence.accessor.JobAccessor)1 RestApiAuditAccessor (com.synopsys.integration.alert.common.persistence.accessor.RestApiAuditAccessor)1 ProxyManager (com.synopsys.integration.alert.common.rest.proxy.ProxyManager)1 BlackDuckProviderKey (com.synopsys.integration.alert.descriptor.api.BlackDuckProviderKey)1 ProviderKey (com.synopsys.integration.alert.descriptor.api.model.ProviderKey)1 PhoneHomeTask (com.synopsys.integration.alert.task.PhoneHomeTask)1 AboutReader (com.synopsys.integration.alert.web.api.about.AboutReader)1