Search in sources :

Example 6 with TestConfiguration

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;
    });
}
Also used : TestConfiguration(net.nemerosa.ontrack.extension.api.support.TestConfiguration) GlobalSettings(net.nemerosa.ontrack.model.security.GlobalSettings) Test(org.junit.Test)

Example 7 with TestConfiguration

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;
    });
}
Also used : TestConfiguration(net.nemerosa.ontrack.extension.api.support.TestConfiguration) GlobalSettings(net.nemerosa.ontrack.model.security.GlobalSettings) Test(org.junit.Test)

Example 8 with TestConfiguration

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;
    });
}
Also used : TestConfiguration(net.nemerosa.ontrack.extension.api.support.TestConfiguration) GlobalSettings(net.nemerosa.ontrack.model.security.GlobalSettings) Test(org.junit.Test)

Example 9 with TestConfiguration

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));
}
Also used : TestConfiguration(net.nemerosa.ontrack.extension.api.support.TestConfiguration) GlobalSettings(net.nemerosa.ontrack.model.security.GlobalSettings) Test(org.junit.Test)

Example 10 with TestConfiguration

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);
}
Also used : TestConfiguration(net.nemerosa.ontrack.extension.api.support.TestConfiguration) Event(net.nemerosa.ontrack.model.events.Event) Test(org.junit.Test)

Aggregations

TestConfiguration (net.nemerosa.ontrack.extension.api.support.TestConfiguration)17 Test (org.junit.Test)16 GlobalSettings (net.nemerosa.ontrack.model.security.GlobalSettings)10 Event (net.nemerosa.ontrack.model.events.Event)3 PreparedStatement (java.sql.PreparedStatement)1 TestPropertyType (net.nemerosa.ontrack.extension.api.support.TestPropertyType)1 ProjectEdit (net.nemerosa.ontrack.model.security.ProjectEdit)1 ProjectView (net.nemerosa.ontrack.model.security.ProjectView)1 Project (net.nemerosa.ontrack.model.structure.Project)1 ConnectionResult (net.nemerosa.ontrack.model.support.ConnectionResult)1