use of com.synopsys.integration.alert.environment.EnvironmentVariableUtility 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.EnvironmentVariableUtility in project hub-alert by blackducksoftware.
the class ConfigurationOverridesStartupComponentTest method testInitializeResetPasswordDifferentUsername.
@Test
public void testInitializeResetPasswordDifferentUsername() throws AlertException {
Environment environment = Mockito.mock(Environment.class);
Mockito.when(environment.getProperty(ConfigurationOverridesStartupComponent.ENV_VAR_ADMIN_USER_PASSWORD_RESET)).thenReturn("true");
EnvironmentVariableUtility environmentVariableUtility = new EnvironmentVariableUtility(environment);
ConfigurationOverridesStartupComponent configurationOverridesStartupComponent = new ConfigurationOverridesStartupComponent(environmentVariableUtility, userAccessor, descriptorKey, configurationModelConfigurationAccessor, apiAction, configurationFieldModelConverter);
String newUsername = "UpdatedAdmin";
// Update the sysadmin username and password
Optional<UserModel> sysadminOptional = userAccessor.getUser(UserAccessor.DEFAULT_ADMIN_USER_ID);
assertTrue(sysadminOptional.isPresent());
UserModel sysadmin = sysadminOptional.get();
assertEquals(DEFAULT_PASSWORD_ENCODED, sysadmin.getPassword());
UserModel updatedSysadmin = changeUserNameAndPassword(sysadmin, newUsername, UPDATED_PASSWORD);
userAccessor.updateUser(updatedSysadmin, false);
// Run the initialize method
configurationOverridesStartupComponent.initialize();
// Verify the sysadmin password is the default password
sysadminOptional = userAccessor.getUser(UserAccessor.DEFAULT_ADMIN_USER_ID);
assertTrue(sysadminOptional.isPresent());
sysadmin = sysadminOptional.get();
assertEquals(DEFAULT_PASSWORD_ENCODED, sysadmin.getPassword());
HttpServletRequest servletRequest = Mockito.mock(HttpServletRequest.class);
HttpSession session = Mockito.mock(HttpSession.class);
Mockito.when(servletRequest.getSession()).thenReturn(session);
HttpServletResponse servletResponse = Mockito.mock(HttpServletResponse.class);
// Try to login with the updated password
LoginConfig updatedLoginConfig = new LoginConfig(newUsername, UPDATED_PASSWORD);
ActionResponse<Void> actionResponse = authenticationActions.authenticateUser(servletRequest, servletResponse, updatedLoginConfig);
assertEquals(HttpStatus.UNAUTHORIZED, actionResponse.getHttpStatus());
// Try to login with the default password
LoginConfig defaultLoginConfig = new LoginConfig(newUsername, DEFAULT_PASSWORD);
actionResponse = authenticationActions.authenticateUser(servletRequest, servletResponse, defaultLoginConfig);
assertEquals(HttpStatus.NO_CONTENT, actionResponse.getHttpStatus());
}
use of com.synopsys.integration.alert.environment.EnvironmentVariableUtility 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.EnvironmentVariableUtility 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"));
}
use of com.synopsys.integration.alert.environment.EnvironmentVariableUtility in project hub-alert by blackducksoftware.
the class EmailEnvironmentHandlerFactoryTestIT method testExistingEmailConfig.
@Test
void testExistingEmailConfig() throws AlertConfigurationException {
EmailGlobalConfigModel emailGlobalConfigModel = new EmailGlobalConfigModel();
emailGlobalConfigModel.setName(AlertRestConstants.DEFAULT_CONFIGURATION_NAME);
emailGlobalConfigModel.setSmtpAuth(Boolean.valueOf(TEST_AUTH_REQUIRED));
emailGlobalConfigModel.setSmtpFrom(TEST_FROM);
emailGlobalConfigModel.setSmtpHost(TEST_SMTP_HOST);
emailGlobalConfigModel.setSmtpPassword(TEST_PASSWORD);
emailGlobalConfigModel.setSmtpPort(Integer.valueOf(TEST_PORT));
emailGlobalConfigModel.setSmtpUsername(TEST_USER);
emailGlobalConfigAccessor.createConfiguration(emailGlobalConfigModel);
Environment environment = setupMockedEnvironment();
EnvironmentVariableUtility environmentVariableUtility = new EnvironmentVariableUtility(environment);
EnvironmentVariableHandlerFactory factory = new EmailEnvironmentVariableHandlerFactory(emailGlobalConfigAccessor, environmentVariableUtility, validator);
EnvironmentVariableHandler handler = factory.build();
EnvironmentProcessingResult result = handler.updateFromEnvironment();
assertEquals(ChannelKeys.EMAIL.getDisplayName(), handler.getName());
assertFalse(result.hasValues());
}
Aggregations