use of com.synopsys.integration.alert.common.persistence.model.ConfigurationModel 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());
}
use of com.synopsys.integration.alert.common.persistence.model.ConfigurationModel in project hub-alert by blackducksoftware.
the class LdapManagerTest method testExceptionOnContext.
@Test
public void testExceptionOnContext() {
final String managerDN = "";
final String managerPassword = "";
ConfigurationModel configurationModel = createConfigurationModel();
configurationModel.getField(AuthenticationDescriptor.KEY_LDAP_SERVER).get().setFieldValue(null);
configurationModel.getField(AuthenticationDescriptor.KEY_LDAP_MANAGER_DN).get().setFieldValue(managerDN);
configurationModel.getField(AuthenticationDescriptor.KEY_LDAP_MANAGER_PWD).get().setFieldValue(managerPassword);
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
}
}
use of com.synopsys.integration.alert.common.persistence.model.ConfigurationModel in project hub-alert by blackducksoftware.
the class ProxyConfigurationModelConverterTest method createDefaultConfigurationModel.
private ConfigurationModel createDefaultConfigurationModel() {
Map<String, ConfigurationFieldModel> fieldValuesMap = new HashMap<>();
ConfigurationFieldModel hostField = ConfigurationFieldModel.create(ProxyConfigurationModelConverter.FIELD_KEY_HOST);
ConfigurationFieldModel portField = ConfigurationFieldModel.create(ProxyConfigurationModelConverter.FIELD_KEY_PORT);
ConfigurationFieldModel passwordField = ConfigurationFieldModel.create(ProxyConfigurationModelConverter.FIELD_KEY_PASSWORD);
ConfigurationFieldModel userField = ConfigurationFieldModel.create(ProxyConfigurationModelConverter.FIELD_KEY_USERNAME);
ConfigurationFieldModel nonProxyHostField = ConfigurationFieldModel.create(ProxyConfigurationModelConverter.FIELD_KEY_NON_PROXY_HOSTS);
hostField.setFieldValue(TEST_SMTP_HOST);
portField.setFieldValue(TEST_SMTP_PORT);
passwordField.setFieldValue(TEST_AUTH_PASSWORD);
userField.setFieldValue(TEST_AUTH_USER);
nonProxyHostField.setFieldValues(TEST_NON_PROXY_HOSTS);
fieldValuesMap.put(ProxyConfigurationModelConverter.FIELD_KEY_HOST, hostField);
fieldValuesMap.put(ProxyConfigurationModelConverter.FIELD_KEY_PORT, portField);
fieldValuesMap.put(ProxyConfigurationModelConverter.FIELD_KEY_PASSWORD, passwordField);
fieldValuesMap.put(ProxyConfigurationModelConverter.FIELD_KEY_USERNAME, userField);
fieldValuesMap.put(ProxyConfigurationModelConverter.FIELD_KEY_NON_PROXY_HOSTS, nonProxyHostField);
return new ConfigurationModel(1L, 1L, "", "", ConfigContextEnum.GLOBAL, fieldValuesMap);
}
use of com.synopsys.integration.alert.common.persistence.model.ConfigurationModel in project hub-alert by blackducksoftware.
the class ProxyConfigurationModelConverterTest method invalidPortTest.
@Test
void invalidPortTest() {
ConfigurationModel configurationModel = createDefaultConfigurationModel();
configurationModel.getField(ProxyConfigurationModelConverter.FIELD_KEY_PORT).ifPresent(field -> field.setFieldValue("twenty-five"));
ProxyConfigurationModelConverter converter = new ProxyConfigurationModelConverter();
Optional<SettingsProxyModel> model = converter.convert(configurationModel);
assertTrue(model.isEmpty());
}
use of com.synopsys.integration.alert.common.persistence.model.ConfigurationModel in project hub-alert by blackducksoftware.
the class ProxyConfigurationModelConverterTest method emptyFieldsTest.
@Test
void emptyFieldsTest() {
ConfigurationModel emptyModel = new ConfigurationModel(1L, 1L, "", "", ConfigContextEnum.GLOBAL, Map.of());
ProxyConfigurationModelConverter converter = new ProxyConfigurationModelConverter();
Optional<SettingsProxyModel> model = converter.convert(emptyModel);
assertTrue(model.isPresent());
SettingsProxyModel proxyModel = model.get();
assertTrue(proxyModel.getProxyUsername().isEmpty());
assertTrue(proxyModel.getProxyPassword().isEmpty());
assertTrue(proxyModel.getProxyHost().isEmpty());
assertTrue(proxyModel.getProxyPort().isEmpty());
assertTrue(proxyModel.getNonProxyHosts().isEmpty());
}
Aggregations