use of com.thoughtworks.go.plugin.access.packagematerial.PackageConfiguration in project gocd by gocd.
the class PackageDefinitionTest method shouldGetFingerprint.
@Test
public void shouldGetFingerprint() {
String pluginId = "pluginid";
PackageConfigurations repositoryConfigurations = new PackageConfigurations();
repositoryConfigurations.add(new PackageConfiguration("k1", "v1").with(PackageConfiguration.PART_OF_IDENTITY, true));
RepositoryMetadataStore.getInstance().addMetadataFor(pluginId, repositoryConfigurations);
PackageConfigurations packageConfigurations = new PackageConfigurations();
packageConfigurations.add(new PackageConfiguration("k2", "v2").with(PackageConfiguration.PART_OF_IDENTITY, true));
PackageMetadataStore.getInstance().addMetadataFor(pluginId, packageConfigurations);
PackageRepository repository = PackageRepositoryMother.create("repo-id", "repo", pluginId, "version", new Configuration(create("k1", false, "v1")));
PackageDefinition packageDefinition = PackageDefinitionMother.create("p-id", "name", new Configuration(create("k2", false, "v2")), repository);
String fingerprint = packageDefinition.getFingerprint(AbstractMaterial.FINGERPRINT_DELIMITER);
assertThat(fingerprint, is(CachedDigestUtils.sha256Hex("plugin-id=pluginid<|>k2=v2<|>k1=v1")));
}
use of com.thoughtworks.go.plugin.access.packagematerial.PackageConfiguration 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.plugin.access.packagematerial.PackageConfiguration in project gocd by gocd.
the class MagicalGoConfigXmlLoaderTest method shouldFailValidationIfPackageDefinitionWithDuplicateFingerprintExists.
@Test
public void shouldFailValidationIfPackageDefinitionWithDuplicateFingerprintExists() throws Exception {
com.thoughtworks.go.plugin.api.material.packagerepository.PackageConfiguration packageConfiguration = new com.thoughtworks.go.plugin.api.material.packagerepository.PackageConfiguration();
packageConfiguration.add(new PackageMaterialProperty("PKG-KEY1"));
RepositoryConfiguration repositoryConfiguration = new RepositoryConfiguration();
repositoryConfiguration.add(new PackageMaterialProperty("REPO-KEY1"));
repositoryConfiguration.add(new PackageMaterialProperty("REPO-KEY2").with(REQUIRED, false).with(PART_OF_IDENTITY, false));
repositoryConfiguration.add(new PackageMaterialProperty("REPO-KEY3").with(REQUIRED, false).with(PART_OF_IDENTITY, false).with(SECURE, true));
PackageMetadataStore.getInstance().addMetadataFor("plugin-1", new PackageConfigurations(packageConfiguration));
RepositoryMetadataStore.getInstance().addMetadataFor("plugin-1", new PackageConfigurations(repositoryConfiguration));
String xml = "<cruise schemaVersion='" + CONFIG_SCHEMA_VERSION + "'>\n" + "<repositories>\n" + " <repository id='repo-id-1' name='name-1'>\n" + " <pluginConfiguration id='plugin-1' version='1.0'/>\n" + " <configuration>\n" + " <property>\n" + " <key>REPO-KEY1</key>\n" + " <value>repo-key1</value>\n" + " </property>\n" + " <property>\n" + " <key>REPO-KEY2</key>\n" + " <value>repo-key2</value>\n" + " </property>\n" + " <property>\n" + " <key>REPO-KEY3</key>\n" + " <value>repo-key3</value>\n" + " </property>\n" + " </configuration>\n" + " <packages>\n" + " <package id='package-id-1' name='name-1'>\n" + " <configuration>\n" + " <property>\n" + " <key>PKG-KEY1</key>\n" + " <value>pkg-key1</value>\n" + " </property>\n" + " </configuration>\n" + " </package>\n" + " </packages>\n" + " </repository>\n" + " <repository id='repo-id-2' name='name-2'>\n" + " <pluginConfiguration id='plugin-1' version='1.0'/>\n" + " <configuration>\n" + " <property>\n" + " <key>REPO-KEY1</key>\n" + " <value>repo-key1</value>\n" + " </property>\n" + " <property>\n" + " <key>REPO-KEY2</key>\n" + " <value>another-repo-key2</value>\n" + " </property>\n" + " <property>\n" + " <key>REPO-KEY3</key>\n" + " <value>another-repo-key3</value>\n" + " </property>\n" + " </configuration>\n" + " <packages>\n" + " <package id='package-id-2' name='name-2'>\n" + " <configuration>\n" + " <property>\n" + " <key>PKG-KEY1</key>\n" + " <value>pkg-key1</value>\n" + " </property>\n" + " </configuration>\n" + " </package>\n" + " </packages>\n" + " </repository>\n" + " </repositories>" + "</cruise>";
try {
xmlLoader.loadConfigHolder(xml);
fail("should have thrown duplicate fingerprint exception");
} catch (GoConfigInvalidException e) {
assertThat(e.getMessage(), is("Cannot save package or repo, found duplicate packages. [Repo Name: 'name-1', Package Name: 'name-1'], [Repo Name: 'name-2', Package Name: 'name-2']"));
}
}
use of com.thoughtworks.go.plugin.access.packagematerial.PackageConfiguration in project gocd by gocd.
the class ScheduledPipelineLoaderIntegrationTest method setupPipelineWithPackageMaterial.
private PipelineConfig setupPipelineWithPackageMaterial(String pipelineName, String stageName, String jobName) {
PackageMaterialConfig packageMaterialConfig = new PackageMaterialConfig("p-id");
Configuration repoConfig = new Configuration(ConfigurationPropertyMother.create("repo-key1", false, "repo-k1-value"), ConfigurationPropertyMother.create("repo-key2", false, "repo-k2-value"));
PackageRepository repository = PackageRepositoryMother.create("repo-id", "repo-name", "pluginid", "version", repoConfig);
Configuration packageConfig = new Configuration(ConfigurationPropertyMother.create("package-key1", false, "package-key1-value"), ConfigurationPropertyMother.create("package-key2", false, "package-key2-value"));
PackageDefinition packageDefinition = PackageDefinitionMother.create("p-id", "package-name", packageConfig, repository);
packageMaterialConfig.setPackageDefinition(packageDefinition);
repository.getPackages().add(packageDefinition);
PipelineConfig pipelineConfig = PipelineConfigMother.pipelineConfig(pipelineName, stageName, new MaterialConfigs(packageMaterialConfig), jobName);
configHelper.addPackageDefinition(packageMaterialConfig);
configHelper.addPipeline(pipelineConfig);
PackageConfigurations packageConfigurations = new PackageConfigurations();
packageConfigurations.add(new PackageConfiguration("package-key1").with(PackageConfiguration.PART_OF_IDENTITY, true));
packageConfigurations.add(new PackageConfiguration("package-key2").with(PackageConfiguration.PART_OF_IDENTITY, false));
PackageMetadataStore.getInstance().addMetadataFor(packageMaterialConfig.getPluginId(), packageConfigurations);
PackageConfigurations configuration = new PackageConfigurations();
configuration.add(new PackageConfiguration("repo-key1").with(PackageConfiguration.PART_OF_IDENTITY, true));
configuration.add(new PackageConfiguration("repo-key2").with(PackageConfiguration.PART_OF_IDENTITY, false));
RepositoryMetadataStore.getInstance().addMetadataFor(packageMaterialConfig.getPluginId(), configuration);
return pipelineConfig;
}
use of com.thoughtworks.go.plugin.access.packagematerial.PackageConfiguration in project gocd by gocd.
the class ConfigurationPropertyTest method shouldSetConfigAttributesForNonSecureProperty.
@Test
public void shouldSetConfigAttributesForNonSecureProperty() throws Exception {
ConfigurationProperty configurationProperty = new ConfigurationProperty();
HashMap attributes = new HashMap();
HashMap keyMap = new HashMap();
keyMap.put("name", "fooKey");
attributes.put(ConfigurationProperty.CONFIGURATION_KEY, keyMap);
HashMap valueMap = new HashMap();
valueMap.put("value", "fooValue");
attributes.put(ConfigurationProperty.CONFIGURATION_VALUE, valueMap);
PackageConfigurations metadata = new PackageConfigurations();
metadata.addConfiguration(new PackageConfiguration("fooKey", null));
attributes.put(Configuration.METADATA, metadata);
configurationProperty.setConfigAttributes(attributes, null);
assertThat(configurationProperty.getConfigurationKey().getName(), is("fooKey"));
assertThat(configurationProperty.getConfigurationValue().getValue(), is("fooValue"));
}
Aggregations