use of com.thoughtworks.go.plugin.access.packagematerial.PackageConfigurations in project gocd by gocd.
the class PackageDefinitionTest method shouldSetConfigAttributes.
@Test
public void shouldSetConfigAttributes() throws Exception {
PackageDefinition definition = new PackageDefinition();
String pluginId = "plugin";
Map config = createPackageDefinitionConfiguration("package-name", pluginId, new ConfigurationHolder("key1", "value1"), new ConfigurationHolder("key2", "value2", "encrypted-value", true, "1"), new ConfigurationHolder("key3", "test", "encrypted-value", true, "0"));
PackageConfigurations metadata = new PackageConfigurations();
metadata.addConfiguration(new PackageConfiguration("key1"));
metadata.addConfiguration(new PackageConfiguration("key2").with(PackageConfiguration.SECURE, true));
metadata.addConfiguration(new PackageConfiguration("key3").with(PackageConfiguration.SECURE, true));
PackageMetadataStore.getInstance().addMetadataFor(pluginId, metadata);
definition.setRepository(PackageRepositoryMother.create("1"));
definition.setConfigAttributes(config);
String encryptedValue = new GoCipher().encrypt("value2");
assertThat(definition.getName(), is("package-name"));
assertThat(definition.getConfiguration().size(), is(3));
assertThat(definition.getConfiguration().getProperty("key1").getConfigurationValue().getValue(), is("value1"));
assertThat(definition.getConfiguration().getProperty("key1").getEncryptedConfigurationValue(), is(nullValue()));
assertThat(definition.getConfiguration().getProperty("key2").getEncryptedValue(), is(encryptedValue));
assertThat(definition.getConfiguration().getProperty("key2").getConfigurationValue(), is(nullValue()));
assertThat(definition.getConfiguration().getProperty("key3").getEncryptedValue(), is("encrypted-value"));
assertThat(definition.getConfiguration().getProperty("key3").getConfigurationValue(), is(nullValue()));
}
use of com.thoughtworks.go.plugin.access.packagematerial.PackageConfigurations in project gocd by gocd.
the class PackageDefinitionTest method shouldMakeConfigurationSecureBasedOnMetadata.
@Test
public void shouldMakeConfigurationSecureBasedOnMetadata() throws Exception {
/*secure property is set based on metadata*/
ConfigurationProperty secureProperty = new ConfigurationProperty(new ConfigurationKey("key1"), new ConfigurationValue("value1"), null, new GoCipher());
ConfigurationProperty nonSecureProperty = new ConfigurationProperty(new ConfigurationKey("key2"), new ConfigurationValue("value2"), null, new GoCipher());
PackageDefinition packageDefinition = new PackageDefinition("go", "name", new Configuration(secureProperty, nonSecureProperty));
PackageRepository packageRepository = new PackageRepository();
packageRepository.setPluginConfiguration(new PluginConfiguration("plugin-id", "1.0"));
packageDefinition.setRepository(packageRepository);
PackageConfigurations packageConfigurations = new PackageConfigurations();
packageConfigurations.addConfiguration(new PackageConfiguration("key1").with(PackageConfiguration.SECURE, true));
packageConfigurations.addConfiguration(new PackageConfiguration("key2").with(PackageConfiguration.SECURE, false));
PackageMetadataStore.getInstance().addMetadataFor("plugin-id", packageConfigurations);
packageDefinition.applyPackagePluginMetadata("plugin-id");
assertThat(secureProperty.isSecure(), is(true));
assertThat(nonSecureProperty.isSecure(), is(false));
}
use of com.thoughtworks.go.plugin.access.packagematerial.PackageConfigurations in project gocd by gocd.
the class PackageDefinitionTest method shouldOnlyDisplayFieldsWhichAreNonSecureAndPartOfIdentityInGetConfigForDisplayWhenPluginExists.
@Test
public void shouldOnlyDisplayFieldsWhichAreNonSecureAndPartOfIdentityInGetConfigForDisplayWhenPluginExists() {
String pluginId = "plugin-id";
PackageConfigurations repositoryConfigurations = new PackageConfigurations();
repositoryConfigurations.add(new PackageConfiguration("rk1", "rv1").with(PackageConfiguration.PART_OF_IDENTITY, true).with(PackageConfiguration.SECURE, false));
repositoryConfigurations.add(new PackageConfiguration("rk2", "rv2").with(PackageConfiguration.PART_OF_IDENTITY, false).with(PackageConfiguration.SECURE, false));
repositoryConfigurations.add(new PackageConfiguration("rk3", "rv3").with(PackageConfiguration.PART_OF_IDENTITY, true).with(PackageConfiguration.SECURE, true));
RepositoryMetadataStore.getInstance().addMetadataFor(pluginId, repositoryConfigurations);
PackageConfigurations packageConfigurations = new PackageConfigurations();
packageConfigurations.add(new PackageConfiguration("pk1", "pv1").with(PackageConfiguration.PART_OF_IDENTITY, true).with(PackageConfiguration.SECURE, false));
packageConfigurations.add(new PackageConfiguration("pk2", "pv2").with(PackageConfiguration.PART_OF_IDENTITY, false).with(PackageConfiguration.SECURE, false));
packageConfigurations.add(new PackageConfiguration("pk3", "pv3").with(PackageConfiguration.PART_OF_IDENTITY, true).with(PackageConfiguration.SECURE, true));
packageConfigurations.add(new PackageConfiguration("pk4", "pv4").with(PackageConfiguration.PART_OF_IDENTITY, false).with(PackageConfiguration.SECURE, true));
packageConfigurations.add(new PackageConfiguration("pk5", "pv5").with(PackageConfiguration.PART_OF_IDENTITY, true).with(PackageConfiguration.SECURE, false));
PackageMetadataStore.getInstance().addMetadataFor(pluginId, packageConfigurations);
PackageRepository repository = PackageRepositoryMother.create("repo-id", "repo", pluginId, "version", new Configuration(create("rk1", false, "rv1"), create("rk2", false, "rv2"), create("rk3", true, "rv3")));
Configuration packageConfig = new Configuration(create("pk1", false, "pv1"), create("pk2", false, "pv2"), create("pk3", true, "pv3"), create("pk4", true, "pv4"), create("pk5", false, "pv5"));
PackageDefinition packageDefinition = PackageDefinitionMother.create("p-id", "name", packageConfig, repository);
packageDefinition.setRepository(repository);
assertThat(packageDefinition.getConfigForDisplay(), is("Repository: [rk1=rv1] - Package: [pk1=pv1, pk5=pv5]"));
}
use of com.thoughtworks.go.plugin.access.packagematerial.PackageConfigurations 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.PackageConfigurations in project gocd by gocd.
the class PackageRepositoryTest method shouldNotDisplayEmptyValuesInGetConfigForDisplay.
@Test
public void shouldNotDisplayEmptyValuesInGetConfigForDisplay() throws Exception {
RepositoryMetadataStore.getInstance().addMetadataFor("some-plugin", new PackageConfigurations());
PackageMetadataStore.getInstance().addMetadataFor("some-plugin", new PackageConfigurations());
Configuration configuration = new Configuration(create("rk1", false, ""), create("rk2", false, "some-non-empty-value"), create("rk3", false, null));
PackageRepository repository = PackageRepositoryMother.create("repo-id", "repo", "some-plugin", "version", configuration);
assertThat(repository.getConfigForDisplay(), is("Repository: [rk2=some-non-empty-value]"));
}
Aggregations