Search in sources :

Example 1 with TestConfiguration

use of net.nemerosa.ontrack.extension.api.support.TestConfiguration in project ontrack by nemerosa.

the class ConfigurationServiceIT method test_ok_on_new_configuration_with_blank_password.

/**
 * Regression test for #531
 */
@Test
public void test_ok_on_new_configuration_with_blank_password() throws Exception {
    TestConfiguration configuration = new TestConfiguration(uid("T"), "", "");
    ConnectionResult result = asUser().with(GlobalSettings.class).call(() -> configurationService.test(configuration));
    assertEquals(ConnectionResult.ConnectionResultType.OK, result.getType());
}
Also used : ConnectionResult(net.nemerosa.ontrack.model.support.ConnectionResult) TestConfiguration(net.nemerosa.ontrack.extension.api.support.TestConfiguration) GlobalSettings(net.nemerosa.ontrack.model.security.GlobalSettings) Test(org.junit.Test)

Example 2 with TestConfiguration

use of net.nemerosa.ontrack.extension.api.support.TestConfiguration in project ontrack by nemerosa.

the class ConfigurationServiceIT method encryptedPasswordForSavedConfigWithNoNewPassword.

@Test
public void encryptedPasswordForSavedConfigWithNoNewPassword() throws Exception {
    // Creates a new configuration, with a password we want to keep secret
    TestConfiguration configuration = config("test3");
    asUser().with(GlobalSettings.class).call(() -> {
        // Saves this configuration in the database
        TestConfiguration savedConfiguration = configurationService.newConfiguration(configuration);
        // Now saves again this configuration with no new password
        configurationService.updateConfiguration("test3", savedConfiguration.withPassword(""));
        // Loads the configuration
        TestConfiguration loadedConfiguration = configurationService.getConfiguration("test3");
        assertEquals(PLAIN_PASSWORD, loadedConfiguration.getPassword());
        // Now, checks the raw result in the repository
        Optional<TestConfiguration> rawConfiguration = configurationRepository.find(TestConfiguration.class, "test3");
        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 3 with TestConfiguration

use of net.nemerosa.ontrack.extension.api.support.TestConfiguration in project ontrack by nemerosa.

the class ConfigurationServiceIT method configuration_property_removed_on_configuration_deleted.

/**
 * Checks that configuration properties are removed when an associated configuration is deleted.
 */
@Test
public void configuration_property_removed_on_configuration_deleted() throws Exception {
    // Creates two configurations
    String conf1Name = uid("C");
    String conf2Name = uid("C");
    TestConfiguration conf1 = asUser().with(GlobalSettings.class).call(() -> configurationService.newConfiguration(config(conf1Name)));
    TestConfiguration conf2 = asUser().with(GlobalSettings.class).call(() -> configurationService.newConfiguration(config(conf2Name)));
    // Creates two projects
    Project p1 = doCreateProject();
    Project p2 = doCreateProject();
    // Sets the properties
    asUser().with(p1, ProjectEdit.class).call(() -> propertyService.editProperty(p1, TestPropertyType.class, TestProperty.of(conf1, "1")));
    asUser().with(p2, ProjectEdit.class).call(() -> propertyService.editProperty(p2, TestPropertyType.class, TestProperty.of(conf2, "2")));
    // Assert the properties are there
    asUser().with(p1, ProjectView.class).execute(() -> assertTrue(propertyService.hasProperty(p1, TestPropertyType.class)));
    asUser().with(p2, ProjectView.class).execute(() -> assertTrue(propertyService.hasProperty(p2, TestPropertyType.class)));
    // Deletes the first configuration
    asUser().with(GlobalSettings.class).execute(() -> configurationService.deleteConfiguration(conf1Name));
    // Checks the property 1 is gone
    asUser().with(p1, ProjectView.class).execute(() -> assertFalse("Project configuration should be gone", propertyService.hasProperty(p1, TestPropertyType.class)));
    // ... but not the second one
    asUser().with(p2, ProjectView.class).execute(() -> assertTrue(propertyService.hasProperty(p2, TestPropertyType.class)));
}
Also used : Project(net.nemerosa.ontrack.model.structure.Project) TestPropertyType(net.nemerosa.ontrack.extension.api.support.TestPropertyType) TestConfiguration(net.nemerosa.ontrack.extension.api.support.TestConfiguration) GlobalSettings(net.nemerosa.ontrack.model.security.GlobalSettings) ProjectView(net.nemerosa.ontrack.model.security.ProjectView) ProjectEdit(net.nemerosa.ontrack.model.security.ProjectEdit) Test(org.junit.Test)

Example 4 with TestConfiguration

use of net.nemerosa.ontrack.extension.api.support.TestConfiguration in project ontrack by nemerosa.

the class ConfigurationServiceIT method validate_ok_on_new_configuration.

@Test
public void validate_ok_on_new_configuration() throws Exception {
    TestConfiguration configuration = new TestConfiguration(uid("T"), "check", "test");
    TestConfiguration savedConfig = asUser().with(GlobalSettings.class).call(() -> configurationService.newConfiguration(configuration));
    assertEquals(configuration.getName(), savedConfig.getName());
    assertTrue(StringUtils.isEmpty(savedConfig.getPassword()));
}
Also used : TestConfiguration(net.nemerosa.ontrack.extension.api.support.TestConfiguration) GlobalSettings(net.nemerosa.ontrack.model.security.GlobalSettings) Test(org.junit.Test)

Example 5 with TestConfiguration

use of net.nemerosa.ontrack.extension.api.support.TestConfiguration in project ontrack by nemerosa.

the class ConfigurationServiceIT method validate_nok_on_updated_configuration_with_wrong_old_password.

@Test(expected = ConfigurationValidationException.class)
public void validate_nok_on_updated_configuration_with_wrong_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", "xxx");
    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)

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