Search in sources :

Example 1 with ConfigurationValue

use of com.thoughtworks.go.domain.config.ConfigurationValue in project gocd by gocd.

the class PackageDefinitionTest method shouldValidateUniqueKeysInConfiguration.

@Test
public void shouldValidateUniqueKeysInConfiguration() {
    ConfigurationProperty one = new ConfigurationProperty(new ConfigurationKey("one"), new ConfigurationValue("value1"));
    ConfigurationProperty duplicate1 = new ConfigurationProperty(new ConfigurationKey("ONE"), new ConfigurationValue("value2"));
    ConfigurationProperty duplicate2 = new ConfigurationProperty(new ConfigurationKey("ONE"), new ConfigurationValue("value3"));
    ConfigurationProperty two = new ConfigurationProperty(new ConfigurationKey("two"), new ConfigurationValue());
    PackageDefinition packageDefinition = new PackageDefinition();
    packageDefinition.setConfiguration(new Configuration(one, duplicate1, duplicate2, two));
    packageDefinition.setName("go-server");
    packageDefinition.validate(null);
    assertThat(one.errors().isEmpty(), is(false));
    assertThat(one.errors().getAllOn(ConfigurationProperty.CONFIGURATION_KEY).contains("Duplicate key 'ONE' found for Package 'go-server'"), is(true));
    assertThat(duplicate1.errors().isEmpty(), is(false));
    assertThat(one.errors().getAllOn(ConfigurationProperty.CONFIGURATION_KEY).contains("Duplicate key 'ONE' found for Package 'go-server'"), is(true));
    assertThat(duplicate2.errors().isEmpty(), is(false));
    assertThat(one.errors().getAllOn(ConfigurationProperty.CONFIGURATION_KEY).contains("Duplicate key 'ONE' found for Package 'go-server'"), is(true));
    assertThat(two.errors().isEmpty(), is(true));
}
Also used : ConfigurationProperty(com.thoughtworks.go.domain.config.ConfigurationProperty) ConfigurationValue(com.thoughtworks.go.domain.config.ConfigurationValue) EncryptedConfigurationValue(com.thoughtworks.go.domain.config.EncryptedConfigurationValue) ConfigurationKey(com.thoughtworks.go.domain.config.ConfigurationKey) Configuration(com.thoughtworks.go.domain.config.Configuration) PluginConfiguration(com.thoughtworks.go.domain.config.PluginConfiguration) PackageConfiguration(com.thoughtworks.go.plugin.access.packagematerial.PackageConfiguration) Test(org.junit.Test)

Example 2 with ConfigurationValue

use of com.thoughtworks.go.domain.config.ConfigurationValue in project gocd by gocd.

the class PackageDefinitionTest method shouldAddFingerprintFieldErrorWhenPackageDefinitionWithSameFingerprintExist.

@Test
public void shouldAddFingerprintFieldErrorWhenPackageDefinitionWithSameFingerprintExist() throws Exception {
    String expectedErrorMessage = "Cannot save package or repo, found duplicate packages. [Repo Name: 'repo-repo1', Package Name: 'pkg1'], [Repo Name: 'repo-repo1', Package Name: 'pkg3']";
    PackageRepository repository = PackageRepositoryMother.create("repo1");
    PackageDefinition definition1 = PackageDefinitionMother.create("1", "pkg1", new Configuration(new ConfigurationProperty(new ConfigurationKey("k1"), new ConfigurationValue("v1"))), repository);
    PackageDefinition definition2 = PackageDefinitionMother.create("2", "pkg2", new Configuration(new ConfigurationProperty(new ConfigurationKey("k2"), new ConfigurationValue("v2"))), repository);
    PackageDefinition definition3 = PackageDefinitionMother.create("3", "pkg3", new Configuration(new ConfigurationProperty(new ConfigurationKey("k1"), new ConfigurationValue("v1"))), repository);
    HashMap<String, Packages> map = new HashMap<>();
    map.put(definition1.getFingerprint(AbstractMaterialConfig.FINGERPRINT_DELIMITER), new Packages(definition1, definition3));
    map.put(definition2.getFingerprint(AbstractMaterialConfig.FINGERPRINT_DELIMITER), new Packages(definition2));
    definition1.validateFingerprintUniqueness(map);
    definition2.validateFingerprintUniqueness(map);
    definition3.validateFingerprintUniqueness(map);
    assertThat(definition1.errors().getAllOn(PackageDefinition.ID), is(asList(expectedErrorMessage)));
    assertThat(definition3.errors().getAllOn(PackageDefinition.ID), is(asList(expectedErrorMessage)));
    assertThat(definition2.errors().getAllOn(PackageDefinition.ID), is(nullValue()));
}
Also used : ConfigurationProperty(com.thoughtworks.go.domain.config.ConfigurationProperty) ConfigurationValue(com.thoughtworks.go.domain.config.ConfigurationValue) EncryptedConfigurationValue(com.thoughtworks.go.domain.config.EncryptedConfigurationValue) Configuration(com.thoughtworks.go.domain.config.Configuration) PluginConfiguration(com.thoughtworks.go.domain.config.PluginConfiguration) PackageConfiguration(com.thoughtworks.go.plugin.access.packagematerial.PackageConfiguration) ConfigurationKey(com.thoughtworks.go.domain.config.ConfigurationKey) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 3 with ConfigurationValue

use of com.thoughtworks.go.domain.config.ConfigurationValue in project gocd by gocd.

the class PluggableTaskTest method testConfigAsMap.

@Test
public void testConfigAsMap() throws Exception {
    PluginConfiguration pluginConfiguration = new PluginConfiguration("test-plugin-id", "13.4");
    GoCipher cipher = new GoCipher();
    List<String> keys = Arrays.asList("Avengers 1", "Avengers 2", "Avengers 3", "Avengers 4");
    List<String> values = Arrays.asList("Iron man", "Hulk", "Thor", "Captain America");
    Configuration configuration = new Configuration(new ConfigurationProperty(new ConfigurationKey(keys.get(0)), new ConfigurationValue(values.get(0))), new ConfigurationProperty(new ConfigurationKey(keys.get(1)), new ConfigurationValue(values.get(1))), new ConfigurationProperty(new ConfigurationKey(keys.get(2)), new ConfigurationValue(values.get(2))), new ConfigurationProperty(new ConfigurationKey(keys.get(3)), null, new EncryptedConfigurationValue(cipher.encrypt(values.get(3))), cipher));
    PluggableTask task = new PluggableTask(pluginConfiguration, configuration);
    Map<String, Map<String, String>> configMap = task.configAsMap();
    assertThat(configMap.keySet().size(), is(keys.size()));
    assertThat(configMap.values().size(), is(values.size()));
    assertThat(configMap.keySet().containsAll(keys), is(true));
    for (int i = 0; i < keys.size(); i++) {
        assertThat(configMap.get(keys.get(i)).get(PluggableTask.VALUE_KEY), is(values.get(i)));
    }
}
Also used : ConfigurationProperty(com.thoughtworks.go.domain.config.ConfigurationProperty) GoCipher(com.thoughtworks.go.security.GoCipher) Configuration(com.thoughtworks.go.domain.config.Configuration) PluginConfiguration(com.thoughtworks.go.domain.config.PluginConfiguration) EncryptedConfigurationValue(com.thoughtworks.go.domain.config.EncryptedConfigurationValue) ConfigurationValue(com.thoughtworks.go.domain.config.ConfigurationValue) EncryptedConfigurationValue(com.thoughtworks.go.domain.config.EncryptedConfigurationValue) ConfigurationKey(com.thoughtworks.go.domain.config.ConfigurationKey) PluginConfiguration(com.thoughtworks.go.domain.config.PluginConfiguration) Map(java.util.Map) Test(org.junit.Test)

Example 4 with ConfigurationValue

use of com.thoughtworks.go.domain.config.ConfigurationValue in project gocd by gocd.

the class PackageRepositoriesTest method shouldFailValidationIfMaterialWithDuplicateFingerprintIsFound.

@Test
public void shouldFailValidationIfMaterialWithDuplicateFingerprintIsFound() {
    com.thoughtworks.go.plugin.api.material.packagerepository.PackageConfiguration packageConfiguration = new com.thoughtworks.go.plugin.api.material.packagerepository.PackageConfiguration();
    packageConfiguration.add(new PackageMaterialProperty("k1"));
    packageConfiguration.add(new PackageMaterialProperty("k2").with(PART_OF_IDENTITY, false));
    PackageMetadataStore.getInstance().addMetadataFor("plugin", new PackageConfigurations(packageConfiguration));
    String expectedErrorMessage = "Cannot save package or repo, found duplicate packages. [Repo Name: 'repo-repo1', Package Name: 'pkg1'], [Repo Name: 'repo-repo1', Package Name: 'pkg3'], [Repo Name: 'repo-repo1', Package Name: 'pkg5']";
    PackageRepository repository = PackageRepositoryMother.create("repo1");
    PackageDefinition definition1 = PackageDefinitionMother.create("1", "pkg1", new Configuration(new ConfigurationProperty(new ConfigurationKey("k1"), new ConfigurationValue("v1"))), repository);
    PackageDefinition definition2 = PackageDefinitionMother.create("2", "pkg2", new Configuration(new ConfigurationProperty(new ConfigurationKey("k1"), new ConfigurationValue("v2"))), repository);
    PackageDefinition definition3 = PackageDefinitionMother.create("3", "pkg3", new Configuration(new ConfigurationProperty(new ConfigurationKey("k1"), new ConfigurationValue("v1"))), repository);
    PackageDefinition definition4 = PackageDefinitionMother.create("4", "pkg4", new Configuration(new ConfigurationProperty(new ConfigurationKey("k1"), new ConfigurationValue("V1"))), repository);
    PackageDefinition definition5 = PackageDefinitionMother.create("5", "pkg5", new Configuration(new ConfigurationProperty(new ConfigurationKey("k1"), new ConfigurationValue("v1")), new ConfigurationProperty(new ConfigurationKey("k2"), new ConfigurationValue("v2"))), repository);
    repository.setPackages(new Packages(definition1, definition2, definition3, definition4, definition5));
    PackageRepositories packageRepositories = new PackageRepositories(repository);
    packageRepositories.validate(null);
    assertThat(definition1.errors().getAllOn(PackageDefinition.ID), is(asList(expectedErrorMessage)));
    assertThat(definition3.errors().getAllOn(PackageDefinition.ID), is(asList(expectedErrorMessage)));
    assertThat(definition3.getFingerprint(AbstractMaterialConfig.FINGERPRINT_DELIMITER).equals(definition1.getFingerprint(AbstractMaterialConfig.FINGERPRINT_DELIMITER)), is(true));
    assertThat(definition5.errors().getAllOn(PackageDefinition.ID), is(asList(expectedErrorMessage)));
    assertThat(definition5.getFingerprint(AbstractMaterialConfig.FINGERPRINT_DELIMITER).equals(definition1.getFingerprint(AbstractMaterialConfig.FINGERPRINT_DELIMITER)), is(true));
    assertThat(definition2.errors().getAllOn(PackageDefinition.ID), is(nullValue()));
    assertThat(definition2.getFingerprint(AbstractMaterialConfig.FINGERPRINT_DELIMITER).equals(definition1.getFingerprint(AbstractMaterialConfig.FINGERPRINT_DELIMITER)), is(false));
    assertThat(definition4.errors().getAllOn(PackageDefinition.ID), is(nullValue()));
    assertThat(definition4.getFingerprint(AbstractMaterialConfig.FINGERPRINT_DELIMITER).equals(definition1.getFingerprint(AbstractMaterialConfig.FINGERPRINT_DELIMITER)), is(false));
}
Also used : ConfigurationProperty(com.thoughtworks.go.domain.config.ConfigurationProperty) Configuration(com.thoughtworks.go.domain.config.Configuration) ConfigurationValue(com.thoughtworks.go.domain.config.ConfigurationValue) ConfigurationKey(com.thoughtworks.go.domain.config.ConfigurationKey) PackageMaterialProperty(com.thoughtworks.go.plugin.api.material.packagerepository.PackageMaterialProperty) PackageConfigurations(com.thoughtworks.go.plugin.access.packagematerial.PackageConfigurations) Test(org.junit.Test)

Example 5 with ConfigurationValue

use of com.thoughtworks.go.domain.config.ConfigurationValue in project gocd by gocd.

the class SCMTest method shouldNotUpdateSecurePropertyWhenPluginIsMissing.

@Test
public void shouldNotUpdateSecurePropertyWhenPluginIsMissing() {
    GoCipher goCipher = new GoCipher();
    ConfigurationProperty secureProperty = new ConfigurationProperty(new ConfigurationKey("key1"), null, new EncryptedConfigurationValue("value"), goCipher);
    ConfigurationProperty nonSecureProperty = new ConfigurationProperty(new ConfigurationKey("key2"), new ConfigurationValue("value1"), null, goCipher);
    SCM scm = SCMMother.create("scm-id", "scm-name", "plugin-id", "version", new Configuration(secureProperty, nonSecureProperty));
    scm.applyPluginMetadata();
    assertThat(secureProperty.getEncryptedConfigurationValue(), is(notNullValue()));
    assertThat(secureProperty.getConfigurationValue(), is(nullValue()));
    assertThat(nonSecureProperty.getConfigurationValue(), is(notNullValue()));
    assertThat(nonSecureProperty.getEncryptedConfigurationValue(), is(nullValue()));
}
Also used : ConfigurationProperty(com.thoughtworks.go.domain.config.ConfigurationProperty) EncryptedConfigurationValue(com.thoughtworks.go.domain.config.EncryptedConfigurationValue) ConfigurationValue(com.thoughtworks.go.domain.config.ConfigurationValue) EncryptedConfigurationValue(com.thoughtworks.go.domain.config.EncryptedConfigurationValue) GoCipher(com.thoughtworks.go.security.GoCipher) ConfigurationKey(com.thoughtworks.go.domain.config.ConfigurationKey) Configuration(com.thoughtworks.go.domain.config.Configuration) PluginConfiguration(com.thoughtworks.go.domain.config.PluginConfiguration) SCMConfiguration(com.thoughtworks.go.plugin.access.scm.SCMConfiguration) Test(org.junit.Test)

Aggregations

ConfigurationValue (com.thoughtworks.go.domain.config.ConfigurationValue)34 ConfigurationProperty (com.thoughtworks.go.domain.config.ConfigurationProperty)28 ConfigurationKey (com.thoughtworks.go.domain.config.ConfigurationKey)27 Test (org.junit.Test)27 Configuration (com.thoughtworks.go.domain.config.Configuration)20 EncryptedConfigurationValue (com.thoughtworks.go.domain.config.EncryptedConfigurationValue)16 PluginConfiguration (com.thoughtworks.go.domain.config.PluginConfiguration)14 PackageConfiguration (com.thoughtworks.go.plugin.access.packagematerial.PackageConfiguration)9 GoCipher (com.thoughtworks.go.security.GoCipher)8 ValidationResult (com.thoughtworks.go.plugin.api.response.validation.ValidationResult)5 ElasticProfile (com.thoughtworks.go.config.elastic.ElasticProfile)4 SCMConfiguration (com.thoughtworks.go.plugin.access.scm.SCMConfiguration)4 ValidationError (com.thoughtworks.go.plugin.api.response.validation.ValidationError)4 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)4 SCM (com.thoughtworks.go.domain.scm.SCM)3 PackageConfigurations (com.thoughtworks.go.plugin.access.packagematerial.PackageConfigurations)3 HashMap (java.util.HashMap)3 BasicCruiseConfig (com.thoughtworks.go.config.BasicCruiseConfig)2 SecurityAuthConfig (com.thoughtworks.go.config.SecurityAuthConfig)2 PackageRepository (com.thoughtworks.go.domain.packagerepository.PackageRepository)2