Search in sources :

Example 16 with Metadata

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

the class BasicCruiseConfigTest method setAuthorizationPluginInfo.

private void setAuthorizationPluginInfo() {
    PluginDescriptor pluginDescriptor = mock(PluginDescriptor.class);
    PluginConfiguration k1 = new PluginConfiguration("k1", new Metadata(false, true));
    PluginConfiguration k2 = new PluginConfiguration("k2", new Metadata(false, false));
    PluginConfiguration k3 = new PluginConfiguration("k3", new Metadata(false, true));
    PluggableInstanceSettings authConfigSettins = new PluggableInstanceSettings(asList(k1, k2, k3));
    PluggableInstanceSettings roleConfigSettings = new PluggableInstanceSettings(asList(k1, k2, k3));
    com.thoughtworks.go.plugin.domain.authorization.Capabilities capabilities = new com.thoughtworks.go.plugin.domain.authorization.Capabilities(SupportedAuthType.Web, true, true, true);
    AuthorizationPluginInfo artifactPluginInfo = new AuthorizationPluginInfo(pluginDescriptor, authConfigSettins, roleConfigSettings, null, capabilities);
    when(pluginDescriptor.id()).thenReturn("cd.go.github");
    AuthorizationMetadataStore.instance().setPluginInfo(artifactPluginInfo);
}
Also used : Metadata(com.thoughtworks.go.plugin.domain.common.Metadata) AuthorizationPluginInfo(com.thoughtworks.go.plugin.domain.authorization.AuthorizationPluginInfo) PluginDescriptor(com.thoughtworks.go.plugin.api.info.PluginDescriptor) PluggableInstanceSettings(com.thoughtworks.go.plugin.domain.common.PluggableInstanceSettings) Capabilities(com.thoughtworks.go.plugin.domain.artifact.Capabilities) PluginConfiguration(com.thoughtworks.go.plugin.domain.common.PluginConfiguration)

Example 17 with Metadata

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

the class PluggableArtifactConfigTest method shouldIgnoreEncryptionOfSecurePropertyForInvalidParamSpecification.

@Test
public void shouldIgnoreEncryptionOfSecurePropertyForInvalidParamSpecification() {
    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", "#{#{invalid}}", 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 18 with Metadata

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

the class PluggableArtifactConfigTest method shouldIgnoreEncryptionOfSecurePropertyForNonExistentParam.

@Test
public void shouldIgnoreEncryptionOfSecurePropertyForNonExistentParam() {
    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 pluggableArtifactConfig1 = new PluggableArtifactConfig("id", "#{non-existent-param}", secureProperty, nonSecureProperty);
    BasicCruiseConfig cruiseConfig = GoConfigMother.defaultCruiseConfig();
    cruiseConfig.getArtifactStores().add(new ArtifactStore("store-id", "cd.go.s3"));
    pluggableArtifactConfig1.encryptSecureProperties(cruiseConfig, pluggableArtifactConfig1);
    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 19 with Metadata

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

the class ArtifactTypeConfigsTest method setConfigAttributes_shouldSetExternalArtifactWithPlainTextValuesIfPluginIdIsProvided.

@Test
public void setConfigAttributes_shouldSetExternalArtifactWithPlainTextValuesIfPluginIdIsProvided() {
    ArtifactPluginInfo artifactPluginInfo = mock(ArtifactPluginInfo.class);
    PluginDescriptor pluginDescriptor = mock(PluginDescriptor.class);
    when(artifactPluginInfo.getDescriptor()).thenReturn(pluginDescriptor);
    when(pluginDescriptor.id()).thenReturn("cd.go.artifact.foo");
    PluginConfiguration image = new PluginConfiguration("Image", new Metadata(true, true));
    PluginConfiguration tag = new PluginConfiguration("Tag", new Metadata(true, false));
    ArrayList<PluginConfiguration> pluginMetadata = new ArrayList<>();
    pluginMetadata.add(image);
    pluginMetadata.add(tag);
    when(artifactPluginInfo.getArtifactConfigSettings()).thenReturn(new PluggableInstanceSettings(pluginMetadata));
    ArtifactMetadataStore.instance().setPluginInfo(artifactPluginInfo);
    HashMap<Object, Object> configurationMap1 = new HashMap<>();
    configurationMap1.put("Image", "gocd/gocd-server");
    configurationMap1.put("Tag", "v18.6.0");
    HashMap<String, Object> artifactPlan1 = new HashMap<>();
    artifactPlan1.put("artifactTypeValue", "Pluggable Artifact");
    artifactPlan1.put("id", "artifactId");
    artifactPlan1.put("storeId", "storeId");
    artifactPlan1.put("pluginId", "cd.go.artifact.foo");
    artifactPlan1.put("configuration", configurationMap1);
    List<Map> artifactPlansList = new ArrayList<>();
    artifactPlansList.add(artifactPlan1);
    ArtifactTypeConfigs artifactTypeConfigs = new ArtifactTypeConfigs();
    artifactTypeConfigs.setConfigAttributes(artifactPlansList);
    assertThat(artifactTypeConfigs.size(), is(1));
    PluggableArtifactConfig artifactConfig = (PluggableArtifactConfig) artifactTypeConfigs.get(0);
    assertThat(artifactConfig.getArtifactType(), is(ArtifactType.external));
    assertThat(artifactConfig.getId(), is("artifactId"));
    assertThat(artifactConfig.getStoreId(), is("storeId"));
    assertThat(artifactConfig.getConfiguration().getProperty("Image").isSecure(), is(false));
}
Also used : HashMap(java.util.HashMap) Metadata(com.thoughtworks.go.plugin.domain.common.Metadata) ArrayList(java.util.ArrayList) ArtifactPluginInfo(com.thoughtworks.go.plugin.domain.artifact.ArtifactPluginInfo) PluginDescriptor(com.thoughtworks.go.plugin.api.info.PluginDescriptor) PluggableInstanceSettings(com.thoughtworks.go.plugin.domain.common.PluggableInstanceSettings) PluginConfiguration(com.thoughtworks.go.plugin.domain.common.PluginConfiguration) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.jupiter.api.Test)

Example 20 with Metadata

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

the class PluggableArtifactConfigTest method shouldIgnoreEncryptionOfSecurePropertyIfParamsIsUndefined.

@Test
public void shouldIgnoreEncryptionOfSecurePropertyIfParamsIsUndefined() {
    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 secureProperty1 = new ConfigurationProperty(new ConfigurationKey("key1"), new ConfigurationValue("value1"), null, goCipher);
    ConfigurationProperty secureProperty2 = new ConfigurationProperty(new ConfigurationKey("key1"), new ConfigurationValue("value1"), null, goCipher);
    ConfigurationProperty nonSecureProperty1 = new ConfigurationProperty(new ConfigurationKey("key2"), new ConfigurationValue("value2"), null, goCipher);
    ConfigurationProperty nonSecureProperty2 = new ConfigurationProperty(new ConfigurationKey("key2"), new ConfigurationValue("value2"), null, goCipher);
    PluggableArtifactConfig pluggableArtifactConfig1 = new PluggableArtifactConfig("id", "#{storeId}", secureProperty1, nonSecureProperty1);
    PluggableArtifactConfig pluggableArtifactConfig2 = new PluggableArtifactConfig("id", "#{storeId}", secureProperty2, nonSecureProperty2);
    BasicCruiseConfig cruiseConfig = GoConfigMother.defaultCruiseConfig();
    cruiseConfig.getArtifactStores().add(new ArtifactStore("store-id", "cd.go.s3"));
    pluggableArtifactConfig1.encryptSecureProperties(cruiseConfig, pluggableArtifactConfig1);
    pluggableArtifactConfig2.encryptSecureProperties(cruiseConfig, pluggableArtifactConfig2);
    assertThat(secureProperty1.isSecure(), is(false));
    assertThat(secureProperty1.getValue(), is("value1"));
    assertThat(nonSecureProperty1.isSecure(), is(false));
    assertThat(nonSecureProperty1.getValue(), is("value2"));
    assertThat(secureProperty2.isSecure(), is(false));
    assertThat(secureProperty2.getValue(), is("value1"));
    assertThat(nonSecureProperty2.isSecure(), is(false));
    assertThat(nonSecureProperty2.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)

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