Search in sources :

Example 36 with Metadata

use of com.thoughtworks.go.plugin.domain.common.Metadata in project gocd by gocd.

the class PluggableArtifactConfigTest method shouldIgnoreEncryptionOfSecurePropertyIfStoreIdIsNull.

@Test
public void shouldIgnoreEncryptionOfSecurePropertyIfStoreIdIsNull() {
    GoCipher goCipher = new GoCipher();
    ArrayList<PluginConfiguration> pluginConfigurations = new ArrayList<>();
    pluginConfigurations.add(new PluginConfiguration("key1", new Metadata(true, true)));
    pluginConfigurations.add(new PluginConfiguration("key2", new Metadata(true, false)));
    when(artifactPluginInfo.getArtifactConfigSettings()).thenReturn(new PluggableInstanceSettings(pluginConfigurations));
    ConfigurationProperty secureProperty = new ConfigurationProperty(new ConfigurationKey("key1"), new ConfigurationValue("value1"), null, goCipher);
    ConfigurationProperty nonSecureProperty = new ConfigurationProperty(new ConfigurationKey("key2"), new ConfigurationValue("value2"), null, goCipher);
    PluggableArtifactConfig pluggableArtifactConfig = new PluggableArtifactConfig("id", null, secureProperty, nonSecureProperty);
    BasicCruiseConfig cruiseConfig = GoConfigMother.defaultCruiseConfig();
    cruiseConfig.getArtifactStores().add(new ArtifactStore("store-id", "cd.go.s3"));
    pluggableArtifactConfig.encryptSecureProperties(cruiseConfig, pluggableArtifactConfig);
    assertThat(secureProperty.isSecure(), is(false));
    assertThat(secureProperty.getValue(), is("value1"));
    assertThat(nonSecureProperty.isSecure(), is(false));
    assertThat(nonSecureProperty.getValue(), is("value2"));
}
Also used : PluggableInstanceSettings(com.thoughtworks.go.plugin.domain.common.PluggableInstanceSettings) GoCipher(com.thoughtworks.go.security.GoCipher) ArrayList(java.util.ArrayList) Metadata(com.thoughtworks.go.plugin.domain.common.Metadata) PluginConfiguration(com.thoughtworks.go.plugin.domain.common.PluginConfiguration) Test(org.junit.jupiter.api.Test)

Example 37 with Metadata

use of com.thoughtworks.go.plugin.domain.common.Metadata in project gocd by gocd.

the class PluggableArtifactConfigTest method shouldNotEncryptConfigPropertiesWhenSpecifiedAsParameters.

@Test
public void shouldNotEncryptConfigPropertiesWhenSpecifiedAsParameters() throws CryptoException {
    GoCipher goCipher = new GoCipher();
    ArrayList<PluginConfiguration> pluginConfigurations = new ArrayList<>();
    pluginConfigurations.add(new PluginConfiguration("key1", new Metadata(true, true)));
    pluginConfigurations.add(new PluginConfiguration("key2", new Metadata(true, false)));
    when(artifactPluginInfo.getArtifactConfigSettings()).thenReturn(new PluggableInstanceSettings(pluginConfigurations));
    ConfigurationProperty secureProperty = new ConfigurationProperty(new ConfigurationKey("key1"), new ConfigurationValue("#{value1}"), null, goCipher);
    ConfigurationProperty nonSecureProperty = new ConfigurationProperty(new ConfigurationKey("key2"), new ConfigurationValue("value2"), null, goCipher);
    PluggableArtifactConfig pluggableArtifactConfig = new PluggableArtifactConfig("id", "store-id", secureProperty, nonSecureProperty);
    BasicCruiseConfig cruiseConfig = GoConfigMother.defaultCruiseConfig();
    cruiseConfig.getArtifactStores().add(new ArtifactStore("store-id", "cd.go.s3"));
    pluggableArtifactConfig.encryptSecureProperties(cruiseConfig, pluggableArtifactConfig);
    assertThat(secureProperty.isSecure(), is(false));
    assertThat(secureProperty.getEncryptedConfigurationValue(), is(nullValue()));
    assertThat(secureProperty.getValue(), is("#{value1}"));
    assertThat(nonSecureProperty.isSecure(), is(false));
    assertThat(nonSecureProperty.getValue(), is("value2"));
}
Also used : PluggableInstanceSettings(com.thoughtworks.go.plugin.domain.common.PluggableInstanceSettings) GoCipher(com.thoughtworks.go.security.GoCipher) ArrayList(java.util.ArrayList) Metadata(com.thoughtworks.go.plugin.domain.common.Metadata) PluginConfiguration(com.thoughtworks.go.plugin.domain.common.PluginConfiguration) Test(org.junit.jupiter.api.Test)

Example 38 with Metadata

use of com.thoughtworks.go.plugin.domain.common.Metadata in project gocd by gocd.

the class PluggableArtifactConfigTest method addConfigurations_shouldSetUserSpecifiedConfigurationAsIs.

@Test
public void addConfigurations_shouldSetUserSpecifiedConfigurationAsIs() throws CryptoException {
    ArrayList<PluginConfiguration> pluginConfigurations = new ArrayList<>();
    pluginConfigurations.add(new PluginConfiguration("secure_property1", new Metadata(true, true)));
    pluginConfigurations.add(new PluginConfiguration("secure_property2", new Metadata(true, true)));
    pluginConfigurations.add(new PluginConfiguration("plain", new Metadata(true, false)));
    when(artifactPluginInfo.getArtifactConfigSettings()).thenReturn(new PluggableInstanceSettings(pluginConfigurations));
    PluggableArtifactConfig pluggableArtifactConfig = new PluggableArtifactConfig("id", "storeId");
    ArrayList<ConfigurationProperty> configurationProperties = new ArrayList<>();
    configurationProperties.add(new ConfigurationProperty(new ConfigurationKey("plain"), new ConfigurationValue("plain")));
    configurationProperties.add(new ConfigurationProperty(new ConfigurationKey("secure_property1"), new ConfigurationValue("password")));
    configurationProperties.add(new ConfigurationProperty(new ConfigurationKey("secure_property2"), new EncryptedConfigurationValue(new GoCipher().encrypt("secret"))));
    BasicCruiseConfig cruiseConfig = GoConfigMother.defaultCruiseConfig();
    cruiseConfig.getArtifactStores().add(new ArtifactStore("storeId", "cd.go.s3"));
    pluggableArtifactConfig.addConfigurations(configurationProperties);
    assertThat(pluggableArtifactConfig.getConfiguration(), is(configurationProperties));
}
Also used : GoCipher(com.thoughtworks.go.security.GoCipher) ArrayList(java.util.ArrayList) Metadata(com.thoughtworks.go.plugin.domain.common.Metadata) PluggableInstanceSettings(com.thoughtworks.go.plugin.domain.common.PluggableInstanceSettings) PluginConfiguration(com.thoughtworks.go.plugin.domain.common.PluginConfiguration) Test(org.junit.jupiter.api.Test)

Example 39 with Metadata

use of com.thoughtworks.go.plugin.domain.common.Metadata in project gocd by gocd.

the class PluggableArtifactConfigTest method shouldHandleEncryptionOfConfigProperties.

@Test
public void shouldHandleEncryptionOfConfigProperties() throws CryptoException {
    GoCipher goCipher = new GoCipher();
    ArrayList<PluginConfiguration> pluginConfigurations = new ArrayList<>();
    pluginConfigurations.add(new PluginConfiguration("key1", new Metadata(true, true)));
    pluginConfigurations.add(new PluginConfiguration("key2", new Metadata(true, false)));
    when(artifactPluginInfo.getArtifactConfigSettings()).thenReturn(new PluggableInstanceSettings(pluginConfigurations));
    ConfigurationProperty secureProperty = new ConfigurationProperty(new ConfigurationKey("key1"), new ConfigurationValue("value1"), null, goCipher);
    ConfigurationProperty nonSecureProperty = new ConfigurationProperty(new ConfigurationKey("key2"), new ConfigurationValue("value2"), null, goCipher);
    PluggableArtifactConfig pluggableArtifactConfig = new PluggableArtifactConfig("id", "store-id", secureProperty, nonSecureProperty);
    BasicCruiseConfig cruiseConfig = GoConfigMother.defaultCruiseConfig();
    cruiseConfig.getArtifactStores().add(new ArtifactStore("store-id", "cd.go.s3"));
    pluggableArtifactConfig.encryptSecureProperties(cruiseConfig, pluggableArtifactConfig);
    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"));
}
Also used : PluggableInstanceSettings(com.thoughtworks.go.plugin.domain.common.PluggableInstanceSettings) GoCipher(com.thoughtworks.go.security.GoCipher) ArrayList(java.util.ArrayList) Metadata(com.thoughtworks.go.plugin.domain.common.Metadata) PluginConfiguration(com.thoughtworks.go.plugin.domain.common.PluginConfiguration) Test(org.junit.jupiter.api.Test)

Example 40 with Metadata

use of com.thoughtworks.go.plugin.domain.common.Metadata in project gocd by gocd.

the class ConfigRepoPluginInfoBuilderTest method shouldBuildPluginInfo.

@Test
public void shouldBuildPluginInfo() throws Exception {
    GoPluginDescriptor descriptor = GoPluginDescriptor.builder().id("plugin1").build();
    when(extension.getPluginSettingsView("plugin1")).thenReturn("some-html");
    when(extension.getCapabilities("plugin1")).thenReturn(new Capabilities(true, true, true, true));
    ConfigRepoPluginInfo pluginInfo = new ConfigRepoPluginInfoBuilder(extension).pluginInfoFor(descriptor);
    List<PluginConfiguration> pluginConfigurations = Arrays.asList(new PluginConfiguration("username", new Metadata(true, false)), new PluginConfiguration("password", new Metadata(true, true)));
    PluginView pluginView = new PluginView("some-html");
    assertThat(pluginInfo.getDescriptor(), is(descriptor));
    assertThat(pluginInfo.getExtensionName(), is("configrepo"));
    assertThat(pluginInfo.getPluginSettings(), is(new PluggableInstanceSettings(pluginConfigurations, pluginView)));
    assertThat(pluginInfo.getCapabilities(), is(new Capabilities(true, true, true, true)));
}
Also used : PluggableInstanceSettings(com.thoughtworks.go.plugin.domain.common.PluggableInstanceSettings) Capabilities(com.thoughtworks.go.plugin.domain.configrepo.Capabilities) Metadata(com.thoughtworks.go.plugin.domain.common.Metadata) PluginConfiguration(com.thoughtworks.go.plugin.domain.common.PluginConfiguration) PluginView(com.thoughtworks.go.plugin.domain.common.PluginView) GoPluginDescriptor(com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor) ConfigRepoPluginInfo(com.thoughtworks.go.plugin.domain.configrepo.ConfigRepoPluginInfo) Test(org.junit.jupiter.api.Test)

Aggregations

Metadata (com.thoughtworks.go.plugin.domain.common.Metadata)51 PluginConfiguration (com.thoughtworks.go.plugin.domain.common.PluginConfiguration)51 PluggableInstanceSettings (com.thoughtworks.go.plugin.domain.common.PluggableInstanceSettings)33 Test (org.junit.jupiter.api.Test)33 GoCipher (com.thoughtworks.go.security.GoCipher)13 ArrayList (java.util.ArrayList)13 PluginDescriptor (com.thoughtworks.go.plugin.api.info.PluginDescriptor)11 ConfigurationKey (com.thoughtworks.go.domain.config.ConfigurationKey)10 ConfigurationProperty (com.thoughtworks.go.domain.config.ConfigurationProperty)10 ConfigurationValue (com.thoughtworks.go.domain.config.ConfigurationValue)10 EncryptedConfigurationValue (com.thoughtworks.go.domain.config.EncryptedConfigurationValue)9 Test (org.junit.Test)9 AgentMetadata (com.thoughtworks.go.plugin.access.elastic.models.AgentMetadata)8 ArtifactPluginInfo (com.thoughtworks.go.plugin.domain.artifact.ArtifactPluginInfo)8 Capabilities (com.thoughtworks.go.plugin.domain.artifact.Capabilities)8 GoPluginDescriptor (com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor)8 GoPluginApiRequest (com.thoughtworks.go.plugin.api.request.GoPluginApiRequest)6 AuthorizationPluginInfo (com.thoughtworks.go.plugin.domain.authorization.AuthorizationPluginInfo)5 ElasticAgentPluginInfo (com.thoughtworks.go.plugin.domain.elastic.ElasticAgentPluginInfo)5 PluginView (com.thoughtworks.go.plugin.domain.common.PluginView)3