use of com.synopsys.integration.alert.common.persistence.model.ConfigurationModel 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));
}
use of com.synopsys.integration.alert.common.persistence.model.ConfigurationModel 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
}
}
use of com.synopsys.integration.alert.common.persistence.model.ConfigurationModel in project hub-alert by blackducksoftware.
the class ProxyConfigurationModelSaveActionsTest method createInvalidConversionTest.
@Test
void createInvalidConversionTest() {
AtomicReference<SettingsProxyConfigurationEntity> savedEntity = new AtomicReference<>();
AtomicReference<NonProxyHostConfigurationEntity> savedNonProxyHostEntity = new AtomicReference<>();
SettingsProxyConfigurationRepository settingsProxyConfigurationRepository = Mockito.mock(SettingsProxyConfigurationRepository.class);
NonProxyHostsConfigurationRepository nonProxyHostsConfigurationRepository = Mockito.mock(NonProxyHostsConfigurationRepository.class);
Mockito.when(settingsProxyConfigurationRepository.save(Mockito.any(SettingsProxyConfigurationEntity.class))).thenAnswer(invocation -> {
savedEntity.set(invocation.getArgument(0));
return savedEntity.get();
});
Mockito.when(nonProxyHostsConfigurationRepository.saveAll(Mockito.any(List.class))).thenAnswer(invocation -> {
Iterable<NonProxyHostConfigurationEntity> iterable = invocation.getArgument(0);
for (NonProxyHostConfigurationEntity entity : iterable) {
savedNonProxyHostEntity.set(entity);
}
return List.of(savedNonProxyHostEntity.get());
});
SettingsProxyConfigAccessor configurationAccessor = new SettingsProxyConfigAccessor(encryptionUtility, settingsProxyConfigurationRepository, nonProxyHostsConfigurationRepository);
SettingsProxyCrudActions settingsProxyCrudActions = new SettingsProxyCrudActions(authorizationManager, configurationAccessor, validator, settingsDescriptorKey);
ProxyConfigurationModelSaveActions saveActions = new ProxyConfigurationModelSaveActions(converter, settingsProxyCrudActions);
ConfigurationModel configurationModel = createDefaultConfigurationModel();
updateField(configurationModel, ProxyConfigurationModelConverter.FIELD_KEY_PORT, "badport");
saveActions.createConcreteModel(configurationModel);
SettingsProxyConfigurationEntity actualEntity = savedEntity.get();
NonProxyHostConfigurationEntity actualNonProxyHosts = savedNonProxyHostEntity.get();
assertNull(actualEntity);
assertNull(actualNonProxyHosts);
}
use of com.synopsys.integration.alert.common.persistence.model.ConfigurationModel in project hub-alert by blackducksoftware.
the class ProxyConfigurationModelSaveActionsTest method deleteTest.
@Test
void deleteTest() {
AtomicReference<SettingsProxyConfigurationEntity> savedEntity = new AtomicReference<>();
AtomicReference<NonProxyHostConfigurationEntity> savedNonProxyHostEntity = new AtomicReference<>();
SettingsProxyConfigurationRepository settingsProxyConfigurationRepository = Mockito.mock(SettingsProxyConfigurationRepository.class);
NonProxyHostsConfigurationRepository nonProxyHostsConfigurationRepository = Mockito.mock(NonProxyHostsConfigurationRepository.class);
Mockito.when(settingsProxyConfigurationRepository.save(Mockito.any(SettingsProxyConfigurationEntity.class))).thenAnswer(invocation -> {
savedEntity.set(invocation.getArgument(0));
return savedEntity.get();
});
Mockito.when(settingsProxyConfigurationRepository.findByName(Mockito.anyString())).thenAnswer(invocation -> Optional.ofNullable(savedEntity.get()));
Mockito.doAnswer(invocation -> {
savedEntity.set(null);
savedNonProxyHostEntity.set(null);
return null;
}).when(settingsProxyConfigurationRepository).deleteByName(Mockito.anyString());
Mockito.when(settingsProxyConfigurationRepository.existsByName(Mockito.anyString())).thenAnswer(invocation -> savedEntity.get() != null);
Mockito.when(nonProxyHostsConfigurationRepository.saveAll(Mockito.any(List.class))).thenAnswer(invocation -> {
Iterable<NonProxyHostConfigurationEntity> iterable = invocation.getArgument(0);
for (NonProxyHostConfigurationEntity entity : iterable) {
savedNonProxyHostEntity.set(entity);
}
return List.of(savedNonProxyHostEntity.get());
});
SettingsProxyConfigAccessor configurationAccessor = new SettingsProxyConfigAccessor(encryptionUtility, settingsProxyConfigurationRepository, nonProxyHostsConfigurationRepository);
SettingsProxyCrudActions settingsProxyCrudActions = new SettingsProxyCrudActions(authorizationManager, configurationAccessor, validator, settingsDescriptorKey);
ProxyConfigurationModelSaveActions saveActions = new ProxyConfigurationModelSaveActions(converter, settingsProxyCrudActions);
ConfigurationModel configurationModel = createDefaultConfigurationModel();
saveActions.createConcreteModel(configurationModel);
SettingsProxyConfigurationEntity actualEntity = savedEntity.get();
NonProxyHostConfigurationEntity actualNonProxyHosts = savedNonProxyHostEntity.get();
assertNotNull(actualEntity);
assertNotNull(actualNonProxyHosts);
saveActions.deleteConcreteModel(configurationModel);
actualEntity = savedEntity.get();
actualNonProxyHosts = savedNonProxyHostEntity.get();
assertNull(actualEntity);
assertNull(actualNonProxyHosts);
}
use of com.synopsys.integration.alert.common.persistence.model.ConfigurationModel in project hub-alert by blackducksoftware.
the class ProxyConfigurationModelSaveActionsTest method updateInvalidConversionTest.
@Test
void updateInvalidConversionTest() {
AtomicReference<SettingsProxyConfigurationEntity> savedEntity = new AtomicReference<>();
AtomicReference<NonProxyHostConfigurationEntity> savedNonProxyHostEntity = new AtomicReference<>();
SettingsProxyConfigurationRepository settingsProxyConfigurationRepository = Mockito.mock(SettingsProxyConfigurationRepository.class);
NonProxyHostsConfigurationRepository nonProxyHostsConfigurationRepository = Mockito.mock(NonProxyHostsConfigurationRepository.class);
Mockito.when(settingsProxyConfigurationRepository.save(Mockito.any(SettingsProxyConfigurationEntity.class))).thenAnswer(invocation -> {
savedEntity.set(invocation.getArgument(0));
return savedEntity.get();
});
Mockito.when(settingsProxyConfigurationRepository.findByName(Mockito.anyString())).thenAnswer(invocation -> Optional.ofNullable(savedEntity.get()));
Mockito.when(nonProxyHostsConfigurationRepository.saveAll(Mockito.any(List.class))).thenAnswer(invocation -> {
Iterable<NonProxyHostConfigurationEntity> iterable = invocation.getArgument(0);
for (NonProxyHostConfigurationEntity entity : iterable) {
savedNonProxyHostEntity.set(entity);
}
return List.of(savedNonProxyHostEntity.get());
});
SettingsProxyConfigAccessor configurationAccessor = new SettingsProxyConfigAccessor(encryptionUtility, settingsProxyConfigurationRepository, nonProxyHostsConfigurationRepository);
SettingsProxyCrudActions settingsProxyCrudActions = new SettingsProxyCrudActions(authorizationManager, configurationAccessor, validator, settingsDescriptorKey);
ProxyConfigurationModelSaveActions saveActions = new ProxyConfigurationModelSaveActions(converter, settingsProxyCrudActions);
String newHost = "updatedHost";
ConfigurationModel configurationModel = createDefaultConfigurationModel();
saveActions.createConcreteModel(configurationModel);
updateField(configurationModel, ProxyConfigurationModelConverter.FIELD_KEY_HOST, newHost);
updateField(configurationModel, ProxyConfigurationModelConverter.FIELD_KEY_PORT, "badPort");
saveActions.updateConcreteModel(configurationModel);
// Assert that the update failed and the original created values are used.
SettingsProxyConfigurationEntity actualEntity = savedEntity.get();
assertEquals(TEST_PROXY_HOST, actualEntity.getHost());
assertEquals(Integer.valueOf(TEST_PROXY_PORT), actualEntity.getPort());
assertEquals(TEST_PROXY_USERNAME, actualEntity.getUsername());
assertEquals(TEST_PROXY_PASSWORD, encryptionUtility.decrypt(actualEntity.getPassword()));
}
Aggregations