use of com.thoughtworks.go.domain.config.ConfigurationProperty in project gocd by gocd.
the class PackageDefinitionTest method shouldNotAddFingerprintFieldErrorWhenPackageDefinitionWithSameFingerprintNotFound.
@Test
public void shouldNotAddFingerprintFieldErrorWhenPackageDefinitionWithSameFingerprintNotFound() throws Exception {
PackageRepository repository = PackageRepositoryMother.create("repo1");
PackageDefinition packageDefinition = PackageDefinitionMother.create("1", "pkg1", new Configuration(new ConfigurationProperty(new ConfigurationKey("k1"), new ConfigurationValue("v1"))), repository);
HashMap<String, Packages> map = new HashMap<>();
map.put(packageDefinition.getFingerprint(AbstractMaterialConfig.FINGERPRINT_DELIMITER), new Packages(packageDefinition));
packageDefinition.validateFingerprintUniqueness(map);
assertThat(packageDefinition.errors().getAllOn(PackageDefinition.ID), is(nullValue()));
}
use of com.thoughtworks.go.domain.config.ConfigurationProperty in project gocd by gocd.
the class PackageDefinitionTest method shouldClearConfigurationsWhichAreEmptyAndNoErrors.
@Test
public void shouldClearConfigurationsWhichAreEmptyAndNoErrors() throws Exception {
PackageDefinition packageDefinition = new PackageDefinition();
packageDefinition.getConfiguration().add(new ConfigurationProperty(new ConfigurationKey("name-one"), new ConfigurationValue()));
packageDefinition.getConfiguration().add(new ConfigurationProperty(new ConfigurationKey("name-two"), new EncryptedConfigurationValue()));
packageDefinition.getConfiguration().add(new ConfigurationProperty(new ConfigurationKey("name-three"), null, new EncryptedConfigurationValue(), null));
ConfigurationProperty configurationProperty = new ConfigurationProperty(new ConfigurationKey("name-four"), null, new EncryptedConfigurationValue(), null);
configurationProperty.addErrorAgainstConfigurationValue("error");
packageDefinition.getConfiguration().add(configurationProperty);
packageDefinition.clearEmptyConfigurations();
assertThat(packageDefinition.getConfiguration().size(), is(1));
assertThat(packageDefinition.getConfiguration().get(0).getConfigurationKey().getName(), is("name-four"));
}
use of com.thoughtworks.go.domain.config.ConfigurationProperty in project gocd by gocd.
the class PackageRepositoryTest method shouldMakeConfigurationSecureBasedOnMetadata.
@Test
public void shouldMakeConfigurationSecureBasedOnMetadata() throws Exception {
GoCipher goCipher = new GoCipher();
/*secure property is set based on metadata*/
ConfigurationProperty secureProperty = new ConfigurationProperty(new ConfigurationKey("key1"), new ConfigurationValue("value1"), null, goCipher);
ConfigurationProperty nonSecureProperty = new ConfigurationProperty(new ConfigurationKey("key2"), new ConfigurationValue("value2"), null, goCipher);
PackageDefinition packageDefinition = new PackageDefinition("go", "name", new Configuration(secureProperty, nonSecureProperty));
// meta data of package
PackageConfigurations packageConfigurations = new PackageConfigurations();
packageConfigurations.addConfiguration(new PackageConfiguration("key1").with(SECURE, true));
packageConfigurations.addConfiguration(new PackageConfiguration("key2").with(SECURE, false));
PackageMetadataStore.getInstance().addMetadataFor("plugin-id", packageConfigurations);
/*secure property is set based on metadata*/
ConfigurationProperty secureRepoProperty = new ConfigurationProperty(new ConfigurationKey("key1"), new ConfigurationValue("value1"), null, goCipher);
ConfigurationProperty nonSecureRepoProperty = new ConfigurationProperty(new ConfigurationKey("key2"), new ConfigurationValue("value2"), null, goCipher);
PackageRepository packageRepository = createPackageRepository("plugin-id", "version", "id", "name", new Configuration(secureRepoProperty, nonSecureRepoProperty), new Packages(packageDefinition));
// meta data of repo
PackageConfigurations repositoryConfiguration = new PackageConfigurations();
repositoryConfiguration.addConfiguration(new PackageConfiguration("key1").with(SECURE, true));
repositoryConfiguration.addConfiguration(new PackageConfiguration("key2").with(SECURE, false));
RepositoryMetadataStore.getInstance().addMetadataFor("plugin-id", repositoryConfiguration);
packageRepository.applyPackagePluginMetadata();
// assert package properties
assertThat(secureProperty.isSecure(), is(true));
assertThat(secureProperty.getEncryptedConfigurationValue(), is(notNullValue()));
assertThat(secureProperty.getEncryptedValue(), is(goCipher.encrypt("value1")));
assertThat(nonSecureProperty.isSecure(), is(false));
assertThat(nonSecureProperty.getValue(), is("value2"));
// assert repository properties
assertThat(secureRepoProperty.isSecure(), is(true));
assertThat(secureRepoProperty.getEncryptedConfigurationValue(), is(notNullValue()));
assertThat(secureRepoProperty.getEncryptedValue(), is(goCipher.encrypt("value1")));
assertThat(nonSecureRepoProperty.isSecure(), is(false));
assertThat(nonSecureRepoProperty.getValue(), is("value2"));
}
use of com.thoughtworks.go.domain.config.ConfigurationProperty in project gocd by gocd.
the class PackageRepositoryTest 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("value2"), null, goCipher);
PackageDefinition packageDefinition = new PackageDefinition("go", "name", new Configuration(secureProperty, nonSecureProperty));
ConfigurationProperty nonSecureRepoProperty = new ConfigurationProperty(new ConfigurationKey("key1"), new ConfigurationValue("value1"), null, goCipher);
ConfigurationProperty secureRepoProperty = new ConfigurationProperty(new ConfigurationKey("key2"), null, new EncryptedConfigurationValue("value"), goCipher);
PackageRepository packageRepository = createPackageRepository("plugin-id", "version", "id", "name", new Configuration(secureRepoProperty, nonSecureRepoProperty), new Packages(packageDefinition));
packageRepository.applyPackagePluginMetadata();
assertThat(secureProperty.getEncryptedConfigurationValue(), is(notNullValue()));
assertThat(secureProperty.getConfigurationValue(), is(nullValue()));
assertThat(nonSecureProperty.getConfigurationValue(), is(notNullValue()));
assertThat(nonSecureProperty.getEncryptedConfigurationValue(), is(nullValue()));
assertThat(secureRepoProperty.getEncryptedConfigurationValue(), is(notNullValue()));
assertThat(secureRepoProperty.getConfigurationValue(), is(nullValue()));
assertThat(nonSecureRepoProperty.getConfigurationValue(), is(notNullValue()));
assertThat(nonSecureRepoProperty.getEncryptedConfigurationValue(), is(nullValue()));
}
use of com.thoughtworks.go.domain.config.ConfigurationProperty in project gocd by gocd.
the class PackageRepositoryTest method shouldClearConfigurationsWhichAreEmptyAndNoErrors.
@Test
public void shouldClearConfigurationsWhichAreEmptyAndNoErrors() throws Exception {
PackageRepository packageRepository = new PackageRepository();
packageRepository.getConfiguration().add(new ConfigurationProperty(new ConfigurationKey("name-one"), new ConfigurationValue()));
packageRepository.getConfiguration().add(new ConfigurationProperty(new ConfigurationKey("name-two"), new EncryptedConfigurationValue()));
packageRepository.getConfiguration().add(new ConfigurationProperty(new ConfigurationKey("name-three"), null, new EncryptedConfigurationValue(), null));
ConfigurationProperty configurationProperty = new ConfigurationProperty(new ConfigurationKey("name-four"), null, new EncryptedConfigurationValue(), null);
configurationProperty.addErrorAgainstConfigurationValue("error");
packageRepository.getConfiguration().add(configurationProperty);
packageRepository.clearEmptyConfigurations();
assertThat(packageRepository.getConfiguration().size(), is(1));
assertThat(packageRepository.getConfiguration().get(0).getConfigurationKey().getName(), is("name-four"));
}
Aggregations