use of com.thoughtworks.go.config.preprocessor.ConfigParamPreprocessor in project gocd by gocd.
the class BasicCruiseConfigTest method shouldEncryptSecurePluggableArtifactConfigPropertiesOfAllPipelinesInConfig.
@Test
public void shouldEncryptSecurePluggableArtifactConfigPropertiesOfAllPipelinesInConfig(ResetCipher resetCipher) throws IOException, CryptoException {
// ancestor => parent => child [fetch pluggable artifact(ancestor), fetch pluggable artifact(parent)]
resetCipher.setupAESCipherFile();
BasicCruiseConfig config = setupPipelines();
BasicCruiseConfig preprocessed = GoConfigMother.deepClone(config);
new ConfigParamPreprocessor().process(preprocessed);
config.encryptSecureProperties(preprocessed);
PipelineConfig ancestor = config.pipelineConfigByName(new CaseInsensitiveString("ancestor"));
PipelineConfig child = config.pipelineConfigByName(new CaseInsensitiveString("child"));
Configuration ancestorPublishArtifactConfig = ancestor.getStage("stage1").jobConfigByConfigName("job1").artifactTypeConfigs().getPluggableArtifactConfigs().get(0).getConfiguration();
GoCipher goCipher = new GoCipher();
assertThat(ancestorPublishArtifactConfig.getProperty("k1").getEncryptedValue(), is(goCipher.encrypt("pub_v1")));
assertThat(ancestorPublishArtifactConfig.getProperty("k1").getConfigValue(), is(nullValue()));
assertThat(ancestorPublishArtifactConfig.getProperty("k1").getValue(), is("pub_v1"));
assertThat(ancestorPublishArtifactConfig.getProperty("k2").getEncryptedValue(), is(nullValue()));
assertThat(ancestorPublishArtifactConfig.getProperty("k2").getConfigValue(), is("pub_v2"));
assertThat(ancestorPublishArtifactConfig.getProperty("k2").getValue(), is("pub_v2"));
assertThat(ancestorPublishArtifactConfig.getProperty("k3").getEncryptedValue(), is(goCipher.encrypt("pub_v3")));
assertThat(ancestorPublishArtifactConfig.getProperty("k3").getConfigValue(), is(nullValue()));
assertThat(ancestorPublishArtifactConfig.getProperty("k3").getValue(), is("pub_v3"));
Configuration childFetchFromAncestorConfig = ((FetchPluggableArtifactTask) child.getStage("stage1").jobConfigByConfigName("job1").tasks().get(0)).getConfiguration();
assertThat(childFetchFromAncestorConfig.getProperty("k1").getEncryptedValue(), is(goCipher.encrypt("fetch_v1")));
assertThat(childFetchFromAncestorConfig.getProperty("k1").getConfigValue(), is(nullValue()));
assertThat(childFetchFromAncestorConfig.getProperty("k1").getValue(), is("fetch_v1"));
assertThat(childFetchFromAncestorConfig.getProperty("k2").getEncryptedValue(), is(nullValue()));
assertThat(childFetchFromAncestorConfig.getProperty("k2").getConfigValue(), is("fetch_v2"));
assertThat(childFetchFromAncestorConfig.getProperty("k2").getValue(), is("fetch_v2"));
assertThat(childFetchFromAncestorConfig.getProperty("k3").getEncryptedValue(), is(goCipher.encrypt("fetch_v3")));
assertThat(childFetchFromAncestorConfig.getProperty("k3").getConfigValue(), is(nullValue()));
assertThat(childFetchFromAncestorConfig.getProperty("k3").getValue(), is("fetch_v3"));
Configuration childFetchFromParentConfig = ((FetchPluggableArtifactTask) child.getStage("stage1").jobConfigByConfigName("job1").tasks().get(1)).getConfiguration();
assertThat(childFetchFromParentConfig.getProperty("k1").getEncryptedValue(), is(goCipher.encrypt("fetch_v1")));
assertThat(childFetchFromParentConfig.getProperty("k1").getConfigValue(), is(nullValue()));
assertThat(childFetchFromParentConfig.getProperty("k1").getValue(), is("fetch_v1"));
assertThat(childFetchFromParentConfig.getProperty("k2").getEncryptedValue(), is(nullValue()));
assertThat(childFetchFromParentConfig.getProperty("k2").getConfigValue(), is("fetch_v2"));
assertThat(childFetchFromParentConfig.getProperty("k2").getValue(), is("fetch_v2"));
assertThat(childFetchFromParentConfig.getProperty("k3").getEncryptedValue(), is(goCipher.encrypt("fetch_v3")));
assertThat(childFetchFromParentConfig.getProperty("k3").getConfigValue(), is(nullValue()));
assertThat(childFetchFromParentConfig.getProperty("k3").getValue(), is("fetch_v3"));
}
use of com.thoughtworks.go.config.preprocessor.ConfigParamPreprocessor in project gocd by gocd.
the class BasicCruiseConfigTest method shouldEncryptElasticAgentProfileConfigProperties.
@Test
public void shouldEncryptElasticAgentProfileConfigProperties(ResetCipher resetCipher) throws IOException, CryptoException {
setEAPluginInfo();
resetCipher.setupAESCipherFile();
BasicCruiseConfig cruiseConfig = new BasicCruiseConfig();
cruiseConfig.getElasticConfig().getClusterProfiles().add(new ClusterProfile("prod-cluster", "ecs"));
ElasticProfile elasticProfile = new ElasticProfile("profile1", "prod-cluster");
elasticProfile.addConfigurations(asList(new ConfigurationProperty(new ConfigurationKey("k1"), new ConfigurationValue("pub_v1")), new ConfigurationProperty(new ConfigurationKey("k2"), new ConfigurationValue("pub_v2")), new ConfigurationProperty(new ConfigurationKey("k3"), new ConfigurationValue("pub_v3"))));
cruiseConfig.getElasticConfig().getProfiles().add(elasticProfile);
BasicCruiseConfig preprocessed = GoConfigMother.deepClone(cruiseConfig);
new ConfigParamPreprocessor().process(preprocessed);
cruiseConfig.encryptSecureProperties(preprocessed);
Configuration properties = cruiseConfig.getElasticConfig().getProfiles().get(0);
GoCipher goCipher = new GoCipher();
assertThat(properties.getProperty("k1").getEncryptedValue(), is(goCipher.encrypt("pub_v1")));
assertThat(properties.getProperty("k1").getConfigValue(), is(nullValue()));
assertThat(properties.getProperty("k1").getValue(), is("pub_v1"));
assertThat(properties.getProperty("k2").getEncryptedValue(), is(nullValue()));
assertThat(properties.getProperty("k2").getConfigValue(), is("pub_v2"));
assertThat(properties.getProperty("k2").getValue(), is("pub_v2"));
assertThat(properties.getProperty("k3").getEncryptedValue(), is(goCipher.encrypt("pub_v3")));
assertThat(properties.getProperty("k3").getConfigValue(), is(nullValue()));
assertThat(properties.getProperty("k3").getValue(), is("pub_v3"));
}
use of com.thoughtworks.go.config.preprocessor.ConfigParamPreprocessor in project gocd by gocd.
the class AbstractMaterialTestController method performParamExpansion.
private void performParamExpansion(ScmMaterialConfig scmMaterialConfig, String pipelineName) {
PipelineConfig pipelineConfig;
// If the pipeline name is provided, find the pipeline and add the params to the new pipeline config object
if (isNotBlank(pipelineName)) {
PipelineConfig existingPipeline = goConfigService.pipelineConfigNamed(new CaseInsensitiveString(pipelineName));
pipelineConfig = new PipelineConfig(existingPipeline.name(), new MaterialConfigs());
GoConfigCloner goConfigCloner = new GoConfigCloner();
pipelineConfig.setParams(goConfigCloner.deepClone(existingPipeline.getParams()));
} else {
// If the pipeline name is not provided, this means that the pipeline is still in creation nd hence no params exist
pipelineConfig = new PipelineConfig(new CaseInsensitiveString(""), new MaterialConfigs());
}
pipelineConfig.addMaterialConfig(scmMaterialConfig);
ConfigParamPreprocessor configParamPreprocessor = new ConfigParamPreprocessor();
configParamPreprocessor.process(pipelineConfig);
}
use of com.thoughtworks.go.config.preprocessor.ConfigParamPreprocessor in project gocd by gocd.
the class BasicCruiseConfigTest method shouldEncryptSecurePluggableArtifactConfigPropertiesOfAllTemplatesInConfig.
@Test
public void shouldEncryptSecurePluggableArtifactConfigPropertiesOfAllTemplatesInConfig(ResetCipher resetCipher) throws IOException, CryptoException {
setArtifactPluginInfo();
resetCipher.setupAESCipherFile();
BasicCruiseConfig cruiseConfig = new BasicCruiseConfig();
cruiseConfig.getArtifactStores().add(new ArtifactStore("store1", "cd.go.s3"));
PipelineConfig pipelineConfig = new GoConfigMother().addPipelineWithTemplate(cruiseConfig, "p1", "t1", "s1", "j1");
cruiseConfig.addPipeline("first", pipelineConfig);
PipelineTemplateConfig templateConfig = cruiseConfig.getTemplates().first();
JobConfig jobConfig = templateConfig.getStages().get(0).getJobs().get(0);
PluggableArtifactConfig artifactConfig = new PluggableArtifactConfig("foo", "store1");
artifactConfig.addConfigurations(asList(new ConfigurationProperty(new ConfigurationKey("k1"), new ConfigurationValue("pub_v1")), new ConfigurationProperty(new ConfigurationKey("k2"), new ConfigurationValue("pub_v2")), new ConfigurationProperty(new ConfigurationKey("k3"), new ConfigurationValue("pub_v3"))));
jobConfig.artifactTypeConfigs().add(artifactConfig);
BasicCruiseConfig preprocessed = GoConfigMother.deepClone(cruiseConfig);
new ConfigParamPreprocessor().process(preprocessed);
cruiseConfig.encryptSecureProperties(preprocessed);
Configuration properties = ((PluggableArtifactConfig) cruiseConfig.getTemplates().get(0).getStages().get(0).getJobs().get(0).artifactTypeConfigs().get(0)).getConfiguration();
GoCipher goCipher = new GoCipher();
assertThat(properties.getProperty("k1").getEncryptedValue(), is(goCipher.encrypt("pub_v1")));
assertThat(properties.getProperty("k1").getConfigValue(), is(nullValue()));
assertThat(properties.getProperty("k1").getValue(), is("pub_v1"));
assertThat(properties.getProperty("k2").getEncryptedValue(), is(nullValue()));
assertThat(properties.getProperty("k2").getConfigValue(), is("pub_v2"));
assertThat(properties.getProperty("k2").getValue(), is("pub_v2"));
assertThat(properties.getProperty("k3").getEncryptedValue(), is(goCipher.encrypt("pub_v3")));
assertThat(properties.getProperty("k3").getConfigValue(), is(nullValue()));
assertThat(properties.getProperty("k3").getValue(), is("pub_v3"));
}
use of com.thoughtworks.go.config.preprocessor.ConfigParamPreprocessor in project gocd by gocd.
the class BasicCruiseConfigTest method shouldEncryptSecureRoleConfigProperties.
@Test
public void shouldEncryptSecureRoleConfigProperties(ResetCipher resetCipher) throws IOException, CryptoException {
setAuthorizationPluginInfo();
resetCipher.setupAESCipherFile();
BasicCruiseConfig cruiseConfig = new BasicCruiseConfig();
cruiseConfig.server().security().securityAuthConfigs().add(new SecurityAuthConfig("auth1", "cd.go.github"));
PluginRoleConfig pluginRole = new PluginRoleConfig("role1", "auth1");
pluginRole.addConfigurations(asList(new ConfigurationProperty(new ConfigurationKey("k1"), new ConfigurationValue("pub_v1")), new ConfigurationProperty(new ConfigurationKey("k2"), new ConfigurationValue("pub_v2")), new ConfigurationProperty(new ConfigurationKey("k3"), new ConfigurationValue("pub_v3"))));
cruiseConfig.server().security().getRoles().add(pluginRole);
BasicCruiseConfig preprocessed = GoConfigMother.deepClone(cruiseConfig);
new ConfigParamPreprocessor().process(preprocessed);
cruiseConfig.encryptSecureProperties(preprocessed);
Configuration properties = cruiseConfig.server().security().getRoles().getPluginRoleConfigs().get(0);
GoCipher goCipher = new GoCipher();
assertThat(properties.getProperty("k1").getEncryptedValue(), is(goCipher.encrypt("pub_v1")));
assertThat(properties.getProperty("k1").getConfigValue(), is(nullValue()));
assertThat(properties.getProperty("k1").getValue(), is("pub_v1"));
assertThat(properties.getProperty("k2").getEncryptedValue(), is(nullValue()));
assertThat(properties.getProperty("k2").getConfigValue(), is("pub_v2"));
assertThat(properties.getProperty("k2").getValue(), is("pub_v2"));
assertThat(properties.getProperty("k3").getEncryptedValue(), is(goCipher.encrypt("pub_v3")));
assertThat(properties.getProperty("k3").getConfigValue(), is(nullValue()));
assertThat(properties.getProperty("k3").getValue(), is("pub_v3"));
}
Aggregations