Search in sources :

Example 21 with PackageConfigurations

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()));
}
Also used : GoCipher(com.thoughtworks.go.security.GoCipher) ConfigurationHolder(com.thoughtworks.go.config.helper.ConfigurationHolder) PackageConfiguration(com.thoughtworks.go.plugin.access.packagematerial.PackageConfiguration) HashMap(java.util.HashMap) Map(java.util.Map) PackageConfigurations(com.thoughtworks.go.plugin.access.packagematerial.PackageConfigurations) Test(org.junit.Test)

Example 22 with PackageConfigurations

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));
}
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) GoCipher(com.thoughtworks.go.security.GoCipher) Configuration(com.thoughtworks.go.domain.config.Configuration) PluginConfiguration(com.thoughtworks.go.domain.config.PluginConfiguration) PackageConfiguration(com.thoughtworks.go.plugin.access.packagematerial.PackageConfiguration) PluginConfiguration(com.thoughtworks.go.domain.config.PluginConfiguration) PackageConfiguration(com.thoughtworks.go.plugin.access.packagematerial.PackageConfiguration) PackageConfigurations(com.thoughtworks.go.plugin.access.packagematerial.PackageConfigurations) Test(org.junit.Test)

Example 23 with PackageConfigurations

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]"));
}
Also used : Configuration(com.thoughtworks.go.domain.config.Configuration) PluginConfiguration(com.thoughtworks.go.domain.config.PluginConfiguration) PackageConfiguration(com.thoughtworks.go.plugin.access.packagematerial.PackageConfiguration) PackageConfiguration(com.thoughtworks.go.plugin.access.packagematerial.PackageConfiguration) PackageConfigurations(com.thoughtworks.go.plugin.access.packagematerial.PackageConfigurations) Test(org.junit.Test)

Example 24 with PackageConfigurations

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"));
}
Also used : ConfigurationProperty(com.thoughtworks.go.domain.config.ConfigurationProperty) 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) PackageConfiguration(com.thoughtworks.go.plugin.access.packagematerial.PackageConfiguration) PackageConfiguration(com.thoughtworks.go.plugin.access.packagematerial.PackageConfiguration) PackageConfigurations(com.thoughtworks.go.plugin.access.packagematerial.PackageConfigurations) Test(org.junit.Test)

Example 25 with PackageConfigurations

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]"));
}
Also used : Configuration(com.thoughtworks.go.domain.config.Configuration) PluginConfiguration(com.thoughtworks.go.domain.config.PluginConfiguration) PackageConfiguration(com.thoughtworks.go.plugin.access.packagematerial.PackageConfiguration) PackageConfigurations(com.thoughtworks.go.plugin.access.packagematerial.PackageConfigurations) Test(org.junit.Test)

Aggregations

PackageConfigurations (com.thoughtworks.go.plugin.access.packagematerial.PackageConfigurations)31 PackageConfiguration (com.thoughtworks.go.plugin.access.packagematerial.PackageConfiguration)23 Test (org.junit.Test)23 Configuration (com.thoughtworks.go.domain.config.Configuration)14 PluginConfiguration (com.thoughtworks.go.domain.config.PluginConfiguration)13 GoPluginDescriptor (com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor)7 RepositoryConfiguration (com.thoughtworks.go.plugin.api.material.packagerepository.RepositoryConfiguration)6 GoCipher (com.thoughtworks.go.security.GoCipher)6 PackageRepository (com.thoughtworks.go.domain.packagerepository.PackageRepository)4 ConfigurationKey (com.thoughtworks.go.domain.config.ConfigurationKey)3 ConfigurationProperty (com.thoughtworks.go.domain.config.ConfigurationProperty)3 ConfigurationValue (com.thoughtworks.go.domain.config.ConfigurationValue)3 PackageMetadataStore (com.thoughtworks.go.plugin.access.packagematerial.PackageMetadataStore)3 RepositoryMetadataStore (com.thoughtworks.go.plugin.access.packagematerial.RepositoryMetadataStore)3 ValidationResult (com.thoughtworks.go.plugin.api.response.validation.ValidationResult)3 HashMap (java.util.HashMap)3 Before (org.junit.Before)3 ConfigurationHolder (com.thoughtworks.go.config.helper.ConfigurationHolder)2 EncryptedConfigurationValue (com.thoughtworks.go.domain.config.EncryptedConfigurationValue)2 SecureKeyInfoProvider (com.thoughtworks.go.domain.config.SecureKeyInfoProvider)2