use of com.synopsys.integration.alert.environment.EnvironmentProcessingResult in project hub-alert by blackducksoftware.
the class ProxySettingsEnvironmentHandlerFactoryTest method testProxySetInEnvironment.
@Test
void testProxySetInEnvironment() {
Environment environment = Mockito.mock(Environment.class);
SettingsProxyConfigAccessor configAccessor = Mockito.mock(SettingsProxyConfigAccessor.class);
Mockito.when(configAccessor.getConfiguration()).thenReturn(Optional.empty());
Set<String> expectedVariableNames = ProxySettingsEnvironmentHandlerFactory.PROXY_CONFIGURATION_KEYSET;
String proxyHost = "https://proxyHostUrl";
String proxyPort = "3128";
String proxyUsername = "testUser";
String proxyPassword = "testPassword";
String nonProxyHosts = "https://nonProxyHostUrl";
EnvironmentVariableMockingUtil.addEnvironmentVariableValueToMock(environment, (ignored) -> Boolean.TRUE, ProxySettingsEnvironmentHandlerFactory.PROXY_HOST_KEY, proxyHost);
EnvironmentVariableMockingUtil.addEnvironmentVariableValueToMock(environment, (ignored) -> Boolean.TRUE, ProxySettingsEnvironmentHandlerFactory.PROXY_PORT_KEY, proxyPort);
EnvironmentVariableMockingUtil.addEnvironmentVariableValueToMock(environment, (ignored) -> Boolean.TRUE, ProxySettingsEnvironmentHandlerFactory.PROXY_USERNAME_KEY, proxyUsername);
EnvironmentVariableMockingUtil.addEnvironmentVariableValueToMock(environment, (ignored) -> Boolean.TRUE, ProxySettingsEnvironmentHandlerFactory.PROXY_PASSWORD_KEY, proxyPassword);
EnvironmentVariableMockingUtil.addEnvironmentVariableValueToMock(environment, (ignored) -> Boolean.TRUE, ProxySettingsEnvironmentHandlerFactory.PROXY_NON_PROXY_HOSTS_KEY, nonProxyHosts);
EnvironmentVariableUtility environmentVariableUtility = new EnvironmentVariableUtility(environment);
EnvironmentVariableHandlerFactory factory = new ProxySettingsEnvironmentHandlerFactory(configAccessor, environmentVariableUtility, validator);
EnvironmentVariableHandler handler = factory.build();
EnvironmentProcessingResult result = handler.updateFromEnvironment();
assertEquals(ProxySettingsEnvironmentHandlerFactory.HANDLER_NAME, handler.getName());
assertEquals(expectedVariableNames, handler.getVariableNames());
assertTrue(result.hasValues());
assertEquals(proxyHost, result.getVariableValue(ProxySettingsEnvironmentHandlerFactory.PROXY_HOST_KEY).orElse("Proxy host value is missing"));
assertEquals(proxyPort, result.getVariableValue(ProxySettingsEnvironmentHandlerFactory.PROXY_PORT_KEY).orElse("Proxy port value is missing"));
assertEquals(proxyUsername, result.getVariableValue(ProxySettingsEnvironmentHandlerFactory.PROXY_USERNAME_KEY).orElse("Proxy username value is missing"));
assertEquals(AlertConstants.MASKED_VALUE, result.getVariableValue(ProxySettingsEnvironmentHandlerFactory.PROXY_PASSWORD_KEY).orElse("Proxy password value is missing"));
assertEquals(List.of(nonProxyHosts).toString(), result.getVariableValue(ProxySettingsEnvironmentHandlerFactory.PROXY_NON_PROXY_HOSTS_KEY).orElse("Proxy non-proxy hosts value is missing"));
}
use of com.synopsys.integration.alert.environment.EnvironmentProcessingResult in project hub-alert by blackducksoftware.
the class EncryptionSettingsEnvironmentHandlerFactoryTest method testEncryptionSetInEnvironment.
@Test
void testEncryptionSetInEnvironment() {
Environment environment = Mockito.mock(Environment.class);
Set<String> variableNames = Set.of(EncryptionSettingsEnvironmentHandlerFactory.ENCRYPTION_PASSWORD_KEY, EncryptionSettingsEnvironmentHandlerFactory.ENCRYPTION_SALT_KEY);
for (String variableName : variableNames) {
Mockito.when(environment.containsProperty(variableName)).thenReturn(Boolean.TRUE);
Mockito.when(environment.getProperty(variableName)).thenReturn("a value");
}
EnvironmentVariableUtility environmentVariableUtility = new EnvironmentVariableUtility(environment);
EnvironmentVariableHandlerFactory factory = new EncryptionSettingsEnvironmentHandlerFactory(environmentVariableUtility);
EnvironmentVariableHandler handler = factory.build();
EnvironmentProcessingResult result = handler.updateFromEnvironment();
assertTrue(result.hasValues());
assertEquals(AlertConstants.MASKED_VALUE, result.getVariableValue(EncryptionSettingsEnvironmentHandlerFactory.ENCRYPTION_PASSWORD_KEY).orElse("Password value is missing"));
assertEquals(AlertConstants.MASKED_VALUE, result.getVariableValue(EncryptionSettingsEnvironmentHandlerFactory.ENCRYPTION_SALT_KEY).orElse("Salt value is missing"));
}
use of com.synopsys.integration.alert.environment.EnvironmentProcessingResult in project hub-alert by blackducksoftware.
the class EncryptionSettingsEnvironmentHandlerFactoryTest method testEncryptionMissingFromEnvironment.
@Test
void testEncryptionMissingFromEnvironment() {
Environment environment = Mockito.mock(Environment.class);
EnvironmentVariableUtility environmentVariableUtility = new EnvironmentVariableUtility(environment);
Set<String> expectedVariableNames = Set.of(EncryptionSettingsEnvironmentHandlerFactory.ENCRYPTION_PASSWORD_KEY, EncryptionSettingsEnvironmentHandlerFactory.ENCRYPTION_SALT_KEY);
EnvironmentVariableHandlerFactory factory = new EncryptionSettingsEnvironmentHandlerFactory(environmentVariableUtility);
EnvironmentVariableHandler handler = factory.build();
EnvironmentProcessingResult result = handler.updateFromEnvironment();
assertEquals(EncryptionSettingsEnvironmentHandlerFactory.HANDLER_NAME, handler.getName());
assertEquals(expectedVariableNames, handler.getVariableNames());
assertFalse(result.hasValues());
}
use of com.synopsys.integration.alert.environment.EnvironmentProcessingResult in project hub-alert by blackducksoftware.
the class EmailEnvironmentHandlerFactoryTest method testEmailConfigPresent.
@Test
void testEmailConfigPresent() {
Environment environment = Mockito.mock(Environment.class);
EmailGlobalConfigAccessor configAccessor = Mockito.mock(EmailGlobalConfigAccessor.class);
Mockito.when(configAccessor.doesConfigurationExist()).thenReturn(true);
EnvironmentVariableUtility environmentVariableUtility = new EnvironmentVariableUtility(environment);
EnvironmentVariableHandlerFactory factory = new EmailEnvironmentVariableHandlerFactory(configAccessor, environmentVariableUtility, validator);
EnvironmentVariableHandler handler = factory.build();
EnvironmentProcessingResult result = handler.updateFromEnvironment();
assertEquals(ChannelKeys.EMAIL.getDisplayName(), handler.getName());
assertFalse(result.hasValues());
}
use of com.synopsys.integration.alert.environment.EnvironmentProcessingResult in project hub-alert by blackducksoftware.
the class EmailEnvironmentHandlerFactoryTest method testEmailSetInEnvironment.
@Test
void testEmailSetInEnvironment() {
Environment environment = Mockito.mock(Environment.class);
EmailGlobalConfigAccessor configAccessor = Mockito.mock(EmailGlobalConfigAccessor.class);
Mockito.when(configAccessor.doesConfigurationExist()).thenReturn(false);
Set<String> expectedVariableNames = Stream.concat(EmailEnvironmentVariableHandlerFactory.EMAIL_CONFIGURATION_KEYSET.stream(), EmailEnvironmentVariableHandlerFactory.OLD_ADDITIONAL_PROPERTY_KEYSET.stream()).collect(Collectors.toSet());
String authRequired = "true";
String from = "noreply@example.com";
String smtpHost = "test.smtp.server.example.com";
String passwordValue = "a test value";
String port = "25";
String username = "testuser";
Predicate<String> hasEnvVarCheck = (variableName) -> !EmailEnvironmentVariableHandlerFactory.OLD_ADDITIONAL_PROPERTY_KEYSET.contains(variableName);
Mockito.when(environment.containsProperty(Mockito.anyString())).thenReturn(Boolean.TRUE);
EnvironmentVariableMockingUtil.addEnvironmentVariableValueToMock(environment, hasEnvVarCheck, EmailEnvironmentVariableHandlerFactory.AUTH_REQUIRED_KEY, authRequired);
EnvironmentVariableMockingUtil.addEnvironmentVariableValueToMock(environment, hasEnvVarCheck, EmailEnvironmentVariableHandlerFactory.EMAIL_FROM_KEY, from);
EnvironmentVariableMockingUtil.addEnvironmentVariableValueToMock(environment, hasEnvVarCheck, EmailEnvironmentVariableHandlerFactory.EMAIL_HOST_KEY, smtpHost);
EnvironmentVariableMockingUtil.addEnvironmentVariableValueToMock(environment, hasEnvVarCheck, EmailEnvironmentVariableHandlerFactory.AUTH_PASSWORD_KEY, passwordValue);
EnvironmentVariableMockingUtil.addEnvironmentVariableValueToMock(environment, hasEnvVarCheck, EmailEnvironmentVariableHandlerFactory.EMAIL_PORT_KEY, port);
EnvironmentVariableMockingUtil.addEnvironmentVariableValueToMock(environment, hasEnvVarCheck, EmailEnvironmentVariableHandlerFactory.AUTH_USER_KEY, username);
EnvironmentVariableUtility environmentVariableUtility = new EnvironmentVariableUtility(environment);
EnvironmentVariableHandlerFactory factory = new EmailEnvironmentVariableHandlerFactory(configAccessor, environmentVariableUtility, validator);
EnvironmentVariableHandler handler = factory.build();
EnvironmentProcessingResult result = handler.updateFromEnvironment();
assertEquals(ChannelKeys.EMAIL.getDisplayName(), handler.getName());
assertEquals(expectedVariableNames, handler.getVariableNames());
assertTrue(result.hasValues());
assertEquals(authRequired, result.getVariableValue(EmailEnvironmentVariableHandlerFactory.AUTH_REQUIRED_KEY).orElse("Auth required value missing"));
assertEquals(from, result.getVariableValue(EmailEnvironmentVariableHandlerFactory.EMAIL_FROM_KEY).orElse("SMTP from value missing"));
assertEquals(smtpHost, result.getVariableValue(EmailEnvironmentVariableHandlerFactory.EMAIL_HOST_KEY).orElse("SMTP host value missing"));
assertEquals(AlertConstants.MASKED_VALUE, result.getVariableValue(EmailEnvironmentVariableHandlerFactory.AUTH_PASSWORD_KEY).orElse("Auth password value missing"));
assertEquals(port, result.getVariableValue(EmailEnvironmentVariableHandlerFactory.EMAIL_PORT_KEY).orElse("SMTP port value missing"));
assertEquals(username, result.getVariableValue(EmailEnvironmentVariableHandlerFactory.AUTH_USER_KEY).orElse("Auth user value missing"));
}
Aggregations