use of net.nemerosa.ontrack.extension.api.support.TestConfiguration in project ontrack by nemerosa.
the class ConfigurationServiceIT method encryptedPasswordForSavedConfigWithNewPassword.
@Test
public void encryptedPasswordForSavedConfigWithNewPassword() throws Exception {
// Creates a new configuration, with a password we want to keep secret
String testName = "test2";
TestConfiguration configuration = config(testName);
asUser().with(GlobalSettings.class).call(() -> {
// Saves this configuration in the database
TestConfiguration savedConfiguration = configurationService.newConfiguration(configuration);
// Now saves again this configuration with a new password
configurationService.updateConfiguration("test2", savedConfiguration.withPassword("newpassword"));
// Loads the configuration
TestConfiguration loadedConfiguration = configurationService.getConfiguration("test2");
assertEquals("newpassword", loadedConfiguration.getPassword());
// Now, checks the raw result in the repository
Optional<TestConfiguration> rawConfiguration = configurationRepository.find(TestConfiguration.class, "test2");
assertTrue(rawConfiguration.isPresent());
assertNotEquals("Password must be encrypted", PLAIN_PASSWORD, rawConfiguration.get().getPassword());
assertNotEquals("Password must be encrypted", "newpassword", rawConfiguration.get().getPassword());
// End of test
return true;
});
}
use of net.nemerosa.ontrack.extension.api.support.TestConfiguration in project ontrack by nemerosa.
the class ConfigurationServiceIT method validate_ok_on_updated_configuration_without_old_password.
@Test
public void validate_ok_on_updated_configuration_without_old_password() throws Exception {
// Creates a configuration
String name = uid("T");
TestConfiguration configuration = new TestConfiguration(name, "check", "test");
asUser().with(GlobalSettings.class).call(() -> configurationService.newConfiguration(configuration));
// Updates the configuration and fills the password
TestConfiguration updatedConfiguration = new TestConfiguration(name, "check", "");
asUser().with(GlobalSettings.class).call(() -> {
configurationService.updateConfiguration(name, updatedConfiguration);
return null;
});
}
use of net.nemerosa.ontrack.extension.api.support.TestConfiguration in project ontrack by nemerosa.
the class ConfigurationServiceIT method encryptedPasswordForNewConfig.
@Test
public void encryptedPasswordForNewConfig() throws Exception {
// Creates a new configuration, with a password we want to keep secret
TestConfiguration configuration = config("test1");
asUser().with(GlobalSettings.class).call(() -> {
// Saves this configuration in the database
TestConfiguration savedConfiguration = configurationService.newConfiguration(configuration);
// The returned password is not encrypted (we may need it)
assertEquals("", savedConfiguration.getPassword());
// Loads the configuration
// The returned password is not encrypted (we may need it)
TestConfiguration loadedConfiguration = configurationService.getConfiguration("test1");
assertEquals(PLAIN_PASSWORD, loadedConfiguration.getPassword());
// Now, checks the raw result in the repository
Optional<TestConfiguration> rawConfiguration = configurationRepository.find(TestConfiguration.class, "test1");
assertTrue(rawConfiguration.isPresent());
assertNotEquals("Password must be encrypted", PLAIN_PASSWORD, rawConfiguration.get().getPassword());
// End of test
return true;
});
}
use of net.nemerosa.ontrack.extension.api.support.TestConfiguration in project ontrack by nemerosa.
the class ConfigurationServiceIT method validate_nok_on_new_configuration.
@Test(expected = ConfigurationValidationException.class)
public void validate_nok_on_new_configuration() throws Exception {
TestConfiguration configuration = new TestConfiguration(uid("T"), "check", "xxx");
asUser().with(GlobalSettings.class).call(() -> configurationService.newConfiguration(configuration));
}
use of net.nemerosa.ontrack.extension.api.support.TestConfiguration in project ontrack by nemerosa.
the class ConfigurationServiceTest method event_on_delete_configuration.
@Test
public void event_on_delete_configuration() {
TestConfiguration config = config("test");
Event event = Event.of(EventFactory.DELETE_CONFIGURATION).with("configuration", "test").get();
when(configurationRepository.find(TestConfiguration.class, "test")).thenReturn(Optional.of(config));
when(eventFactory.deleteConfiguration(config.withPassword("xxxxx"))).thenReturn(event);
when(encryptionService.decrypt(PLAIN_PASSWORD)).thenReturn("xxxxx");
configurationService.deleteConfiguration("test");
verify(eventPostService).post(event);
}
Aggregations