use of com.thoughtworks.go.plugin.domain.common.PluginConfiguration in project gocd by gocd.
the class FetchPluggableArtifactTaskTest method encryptSecureProperties_shouldEncryptSecureProperties.
@Test
void encryptSecureProperties_shouldEncryptSecureProperties() 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.getFetchArtifactSettings()).thenReturn(new PluggableInstanceSettings(pluginConfigurations));
PipelineConfig pipelineConfig = PipelineConfigMother.createPipelineConfig("pipeline", "stage", "job");
PluggableArtifactConfig pluggableArtifactConfig = new PluggableArtifactConfig("s3", "aws");
pipelineConfig.getStage("stage").jobConfigByConfigName("job").artifactTypeConfigs().add(pluggableArtifactConfig);
BasicCruiseConfig cruiseConfig = GoConfigMother.defaultCruiseConfig();
cruiseConfig.addPipelineWithoutValidation("foo", pipelineConfig);
cruiseConfig.getArtifactStores().add(new ArtifactStore("aws", artifactPluginInfo.getDescriptor().id()));
FetchPluggableArtifactTask task = new FetchPluggableArtifactTask(new CaseInsensitiveString("pipeline"), new CaseInsensitiveString("stage"), new CaseInsensitiveString("job"), "s3");
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"))));
ArrayList<ConfigurationProperty> expectedConfigurationProperties = new ArrayList<>();
expectedConfigurationProperties.add(new ConfigurationProperty(new ConfigurationKey("plain"), new ConfigurationValue("plain")));
expectedConfigurationProperties.add(new ConfigurationProperty(new ConfigurationKey("secure_property1"), new EncryptedConfigurationValue(new GoCipher().encrypt("password"))));
expectedConfigurationProperties.add(new ConfigurationProperty(new ConfigurationKey("secure_property2"), new EncryptedConfigurationValue(new GoCipher().encrypt("secret"))));
task.addConfigurations(configurationProperties);
task.encryptSecureProperties(cruiseConfig, pipelineConfig, task);
assertThat(task.getConfiguration().size()).isEqualTo(3);
assertThat(task.getConfiguration()).isEqualTo(expectedConfigurationProperties);
}
use of com.thoughtworks.go.plugin.domain.common.PluginConfiguration in project gocd by gocd.
the class FetchPluggableArtifactTaskTest method encryptSecureProperties_shouldEncryptSecurePropertiesIfTheConfigIdentifersAreParams.
@Test
void encryptSecureProperties_shouldEncryptSecurePropertiesIfTheConfigIdentifersAreParams() 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.getFetchArtifactSettings()).thenReturn(new PluggableInstanceSettings(pluginConfigurations));
PipelineConfig pipelineConfig = PipelineConfigMother.createPipelineConfig("pipeline", "stage", "job");
PluggableArtifactConfig pluggableArtifactConfig = new PluggableArtifactConfig("s3", "aws");
pipelineConfig.getStage("stage").jobConfigByConfigName("job").artifactTypeConfigs().add(pluggableArtifactConfig);
BasicCruiseConfig cruiseConfig = GoConfigMother.defaultCruiseConfig();
cruiseConfig.addPipelineWithoutValidation("foo", pipelineConfig);
cruiseConfig.getArtifactStores().add(new ArtifactStore("aws", artifactPluginInfo.getDescriptor().id()));
FetchPluggableArtifactTask task = new FetchPluggableArtifactTask(new CaseInsensitiveString("#{pipeline}"), new CaseInsensitiveString("#{stage}"), new CaseInsensitiveString("#{job}"), "#{artifactId}");
FetchPluggableArtifactTask preprocessedTask = new FetchPluggableArtifactTask(new CaseInsensitiveString("pipeline"), new CaseInsensitiveString("stage"), new CaseInsensitiveString("job"), "s3");
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"))));
ArrayList<ConfigurationProperty> expectedConfigurationProperties = new ArrayList<>();
expectedConfigurationProperties.add(new ConfigurationProperty(new ConfigurationKey("plain"), new ConfigurationValue("plain")));
expectedConfigurationProperties.add(new ConfigurationProperty(new ConfigurationKey("secure_property1"), new EncryptedConfigurationValue(new GoCipher().encrypt("password"))));
expectedConfigurationProperties.add(new ConfigurationProperty(new ConfigurationKey("secure_property2"), new EncryptedConfigurationValue(new GoCipher().encrypt("secret"))));
task.addConfigurations(configurationProperties);
PipelineConfig pipelineWhichHasTheFetchTask = PipelineConfigMother.createPipelineConfigWithStage("p2", "anotherStage");
pipelineWhichHasTheFetchTask.first().getJobs().first().addTask(task);
pipelineWhichHasTheFetchTask.setParams(new ParamsConfig(new ParamConfig("pipeline", "pipeline"), new ParamConfig("stage", "stage"), new ParamConfig("job", "job"), new ParamConfig("artifactId", "s3")));
task.encryptSecureProperties(cruiseConfig, pipelineWhichHasTheFetchTask, preprocessedTask);
assertThat(task.getConfiguration().size()).isEqualTo(3);
assertThat(task.getConfiguration()).isEqualTo(expectedConfigurationProperties);
}
use of com.thoughtworks.go.plugin.domain.common.PluginConfiguration in project gocd by gocd.
the class PluggableArtifactConfigTest method shouldHandleEncryptionOfConfigPropertiesIfStoreIdIsAValidParam.
@Test
public void shouldHandleEncryptionOfConfigPropertiesIfStoreIdIsAValidParam() throws Exception {
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", "#{storeId}", secureProperty, nonSecureProperty);
PluggableArtifactConfig preprocessedPluggableArtifactConfig = new PluggableArtifactConfig("id", "store-id", secureProperty, nonSecureProperty);
BasicCruiseConfig cruiseConfig = GoConfigMother.defaultCruiseConfig();
cruiseConfig.getArtifactStores().add(new ArtifactStore("store-id", "cd.go.s3"));
pluggableArtifactConfig.encryptSecureProperties(cruiseConfig, preprocessedPluggableArtifactConfig);
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"));
}
use of com.thoughtworks.go.plugin.domain.common.PluginConfiguration 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"));
}
use of com.thoughtworks.go.plugin.domain.common.PluginConfiguration 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"));
}
Aggregations