Search in sources :

Example 1 with SettingsEncryptionModel

use of com.synopsys.integration.alert.component.settings.encryption.model.SettingsEncryptionModel in project hub-alert by blackducksoftware.

the class SettingsEncryptionCrudActions method createMaskedSettingsEncryptionModel.

private SettingsEncryptionModel createMaskedSettingsEncryptionModel() {
    // EncryptionUtility does not return a model. A SettingsEncryptionModel with values must be created in order to obfuscate in the ConfigurationCrudHelper later.
    SettingsEncryptionModel settingsEncryptionModel = new SettingsEncryptionModel();
    settingsEncryptionModel.setIsEncryptionPasswordSet(encryptionUtility.isPasswordSet());
    settingsEncryptionModel.setIsEncryptionGlobalSaltSet(encryptionUtility.isGlobalSaltSet());
    settingsEncryptionModel.setReadOnly(encryptionUtility.isEncryptionFromEnvironment());
    return settingsEncryptionModel;
}
Also used : SettingsEncryptionModel(com.synopsys.integration.alert.component.settings.encryption.model.SettingsEncryptionModel)

Example 2 with SettingsEncryptionModel

use of com.synopsys.integration.alert.component.settings.encryption.model.SettingsEncryptionModel in project hub-alert by blackducksoftware.

the class SettingsEncryptionControllerTestIT method testValidate.

@Test
@WithMockUser(roles = AlertIntegrationTestConstants.ROLE_ALERT_ADMIN)
public void testValidate() throws Exception {
    SettingsEncryptionModel settingsEncryptionModel = new SettingsEncryptionModel();
    settingsEncryptionModel.setEncryptionPassword("password");
    settingsEncryptionModel.setEncryptionGlobalSalt("globalSalt");
    String url = AlertRestConstants.SETTINGS_ENCRYPTION_PATH + "/validate";
    MockHttpServletRequestBuilder request = MockMvcRequestBuilders.post(new URI(url)).with(SecurityMockMvcRequestPostProcessors.user("admin").roles(AlertIntegrationTestConstants.ROLE_ALERT_ADMIN)).with(SecurityMockMvcRequestPostProcessors.csrf()).content(gson.toJson(settingsEncryptionModel)).contentType(contentType);
    mockMvc.perform(request).andExpect(MockMvcResultMatchers.status().isOk());
}
Also used : SettingsEncryptionModel(com.synopsys.integration.alert.component.settings.encryption.model.SettingsEncryptionModel) MockHttpServletRequestBuilder(org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder) URI(java.net.URI) WithMockUser(org.springframework.security.test.context.support.WithMockUser) AlertIntegrationTest(com.synopsys.integration.alert.util.AlertIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 3 with SettingsEncryptionModel

use of com.synopsys.integration.alert.component.settings.encryption.model.SettingsEncryptionModel in project hub-alert by blackducksoftware.

the class SettingsEncryptionValidatorTest method validateNotInitializedTest.

@Test
public void validateNotInitializedTest() {
    MockAlertProperties alertPropertiesNoEncryption = new MockAlertProperties();
    alertPropertiesNoEncryption.setEncryptionPassword("");
    alertPropertiesNoEncryption.setEncryptionSalt("");
    FilePersistenceUtil filePersistenceUtilWithoutProperties = new FilePersistenceUtil(alertPropertiesNoEncryption, gson);
    EncryptionUtility encryptionUtilityWithoutProperties = new EncryptionUtility(alertPropertiesNoEncryption, filePersistenceUtilWithoutProperties);
    SettingsEncryptionModel settingsEncryptionModel = new SettingsEncryptionModel();
    settingsEncryptionModel.setEncryptionPassword("password");
    settingsEncryptionModel.setEncryptionGlobalSalt("globalSalt");
    SettingsEncryptionValidator validator = new SettingsEncryptionValidator(encryptionUtilityWithoutProperties, systemMessageAccessor);
    ValidationResponseModel validationResponseModel = validator.validate(settingsEncryptionModel);
    assertFalse(validationResponseModel.hasErrors());
}
Also used : ValidationResponseModel(com.synopsys.integration.alert.common.rest.model.ValidationResponseModel) FilePersistenceUtil(com.synopsys.integration.alert.common.persistence.util.FilePersistenceUtil) SettingsEncryptionModel(com.synopsys.integration.alert.component.settings.encryption.model.SettingsEncryptionModel) MockAlertProperties(com.synopsys.integration.alert.test.common.MockAlertProperties) EncryptionUtility(com.synopsys.integration.alert.common.security.EncryptionUtility) Test(org.junit.jupiter.api.Test)

Example 4 with SettingsEncryptionModel

use of com.synopsys.integration.alert.component.settings.encryption.model.SettingsEncryptionModel in project hub-alert by blackducksoftware.

the class SettingsEncryptionValidatorTest method fieldNameTooShortTest.

@Test
public void fieldNameTooShortTest() {
    SettingsEncryptionValidator validator = new SettingsEncryptionValidator(encryptionUtility, systemMessageAccessor);
    SettingsEncryptionModel settingsEncryptionModel = new SettingsEncryptionModel();
    settingsEncryptionModel.setEncryptionPassword("too");
    settingsEncryptionModel.setEncryptionGlobalSalt("short");
    ValidationResponseModel validationResponseModel = validator.validate(settingsEncryptionModel);
    assertTrue(validationResponseModel.hasErrors());
    assertEquals(2, validationResponseModel.getErrors().size());
}
Also used : ValidationResponseModel(com.synopsys.integration.alert.common.rest.model.ValidationResponseModel) SettingsEncryptionModel(com.synopsys.integration.alert.component.settings.encryption.model.SettingsEncryptionModel) Test(org.junit.jupiter.api.Test)

Example 5 with SettingsEncryptionModel

use of com.synopsys.integration.alert.component.settings.encryption.model.SettingsEncryptionModel in project hub-alert by blackducksoftware.

the class SettingsEncryptionCrudActionsTest method assertModelObfuscated.

private void assertModelObfuscated(ActionResponse<SettingsEncryptionModel> actionResponse) {
    Optional<SettingsEncryptionModel> optionalSettingsEncryptionModel = actionResponse.getContent();
    assertTrue(optionalSettingsEncryptionModel.isPresent());
    SettingsEncryptionModel settingsEncryptionModel = optionalSettingsEncryptionModel.get();
    assertTrue(settingsEncryptionModel.getEncryptionPassword().isEmpty());
    assertTrue(settingsEncryptionModel.getEncryptionGlobalSalt().isEmpty());
    assertTrue(settingsEncryptionModel.getIsEncryptionPasswordSet());
    assertTrue(settingsEncryptionModel.getIsEncryptionGlobalSaltSet());
    assertTrue(settingsEncryptionModel.isReadOnly());
}
Also used : SettingsEncryptionModel(com.synopsys.integration.alert.component.settings.encryption.model.SettingsEncryptionModel)

Aggregations

SettingsEncryptionModel (com.synopsys.integration.alert.component.settings.encryption.model.SettingsEncryptionModel)12 Test (org.junit.jupiter.api.Test)10 ValidationResponseModel (com.synopsys.integration.alert.common.rest.model.ValidationResponseModel)5 FilePersistenceUtil (com.synopsys.integration.alert.common.persistence.util.FilePersistenceUtil)4 EncryptionUtility (com.synopsys.integration.alert.common.security.EncryptionUtility)4 MockAlertProperties (com.synopsys.integration.alert.test.common.MockAlertProperties)4 SettingsEncryptionCrudActions (com.synopsys.integration.alert.component.settings.encryption.action.SettingsEncryptionCrudActions)3 AlertIntegrationTest (com.synopsys.integration.alert.util.AlertIntegrationTest)2 URI (java.net.URI)2 WithMockUser (org.springframework.security.test.context.support.WithMockUser)2 MockHttpServletRequestBuilder (org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder)2