use of com.thoughtworks.go.config.materials.PluggableSCMMaterialConfig in project gocd by gocd.
the class SCMConfigXmlLoaderTest method shouldBeAbleToResolveSecureConfigPropertiesForSCMs.
@Test
public void shouldBeAbleToResolveSecureConfigPropertiesForSCMs() throws Exception {
String encryptedValue = new GoCipher().encrypt("secure-two");
String xml = "<cruise schemaVersion='" + GoConstants.CONFIG_SCHEMA_VERSION + "'>\n" + "<scms>\n" + " <scm id='scm-id' name='name'>\n" + " <pluginConfiguration id='plugin-id' version='1.0'/>\n" + " <configuration>\n" + " <property>\n" + " <key>plain</key>\n" + " <value>value</value>\n" + " </property>\n" + " <property>\n" + " <key>secure-one</key>\n" + " <value>secure-value</value>\n" + " </property>\n" + " <property>\n" + " <key>secure-two</key>\n" + " <encryptedValue>" + encryptedValue + "</encryptedValue>\n" + " </property>\n" + " </configuration>\n" + " </scm>\n" + " </scms>" + "<pipelines group=\"group_name\">\n" + " <pipeline name=\"new_name\">\n" + " <materials>\n" + " <scm ref='scm-id' />\n" + " </materials>\n" + " <stage name=\"stage_name\">\n" + " <jobs>\n" + " <job name=\"job_name\">\n" + " <tasks><ant /></tasks>\n" + " </job>\n" + " </jobs>\n" + " </stage>\n" + " </pipeline>\n" + "</pipelines></cruise>";
// meta data of scm
SCMPropertyConfiguration scmConfiguration = new SCMPropertyConfiguration();
scmConfiguration.add(new SCMProperty("plain"));
scmConfiguration.add(new SCMProperty("secure-one").with(SCMConfiguration.SECURE, true));
scmConfiguration.add(new SCMProperty("secure-two").with(SCMConfiguration.SECURE, true));
SCMMetadataStore.getInstance().addMetadataFor("plugin-id", new SCMConfigurations(scmConfiguration), null);
GoConfigHolder goConfigHolder = xmlLoader.loadConfigHolder(xml);
SCM scmConfig = goConfigHolder.config.getSCMs().first();
PipelineConfig pipelineConfig = goConfigHolder.config.pipelineConfigByName(new CaseInsensitiveString("new_name"));
PluggableSCMMaterialConfig pluggableSCMMaterialConfig = (PluggableSCMMaterialConfig) pipelineConfig.materialConfigs().get(0);
assertThat(pluggableSCMMaterialConfig.getSCMConfig(), is(scmConfig));
Configuration configuration = pluggableSCMMaterialConfig.getSCMConfig().getConfiguration();
assertThat(configuration.get(0).getConfigurationValue().getValue(), is("value"));
assertThat(configuration.get(1).getEncryptedValue(), is(new GoCipher().encrypt("secure-value")));
assertThat(configuration.get(2).getEncryptedValue(), is(encryptedValue));
}
use of com.thoughtworks.go.config.materials.PluggableSCMMaterialConfig in project gocd by gocd.
the class ConfigConverterTest method shouldFailToConvertConfigMaterialWhenPluggableScmMaterialWithWhitelist.
@Test
public void shouldFailToConvertConfigMaterialWhenPluggableScmMaterialWithWhitelist() {
SCM myscm = new SCM("scmid", new PluginConfiguration(), new Configuration());
SCMs scms = new SCMs(myscm);
BasicCruiseConfig cruiseConfig = new BasicCruiseConfig();
cruiseConfig.setSCMs(scms);
when(cachedGoConfig.currentConfig()).thenReturn(cruiseConfig);
PluggableSCMMaterialConfig configRepoMaterial = new PluggableSCMMaterialConfig(new CaseInsensitiveString("scmid"), myscm, null, null);
when(context.configMaterial()).thenReturn(configRepoMaterial);
CRConfigMaterial crConfigMaterial = new CRConfigMaterial("example", "dest1", new CRFilter(filter, true));
try {
configConverter.toMaterialConfig(crConfigMaterial, context);
fail("should have thrown");
} catch (ConfigConvertionException ex) {
assertThat(ex.getMessage(), is("Plugable SCMs do not support whitelisting"));
}
}
use of com.thoughtworks.go.config.materials.PluggableSCMMaterialConfig in project gocd by gocd.
the class PipelineGroups method getPluggableSCMMaterialUsageInPipelines.
public Map<String, List<Pair<PipelineConfig, PipelineConfigs>>> getPluggableSCMMaterialUsageInPipelines() {
if (pluggableSCMMaterialToPipelineMap == null) {
synchronized (this) {
if (pluggableSCMMaterialToPipelineMap == null) {
pluggableSCMMaterialToPipelineMap = new HashMap<>();
for (PipelineConfigs pipelineConfigs : this) {
for (PipelineConfig pipelineConfig : pipelineConfigs) {
for (PluggableSCMMaterialConfig pluggableSCMMaterialConfig : pipelineConfig.pluggableSCMMaterialConfigs()) {
String scmId = pluggableSCMMaterialConfig.getScmId();
if (!pluggableSCMMaterialToPipelineMap.containsKey(scmId)) {
pluggableSCMMaterialToPipelineMap.put(scmId, new ArrayList<>());
}
pluggableSCMMaterialToPipelineMap.get(scmId).add(new Pair<>(pipelineConfig, pipelineConfigs));
}
}
}
}
}
}
return pluggableSCMMaterialToPipelineMap;
}
use of com.thoughtworks.go.config.materials.PluggableSCMMaterialConfig in project gocd by gocd.
the class GoConfigGraphWalkerTest method shouldNotWalkSCMMaterialWhileTraversingPluggableSCMMaterial.
@Test
public void shouldNotWalkSCMMaterialWhileTraversingPluggableSCMMaterial() {
SCM scmConfig = mock(SCM.class);
when(scmConfig.getName()).thenReturn("scm");
when(scmConfig.getId()).thenReturn("scm-id");
PluggableSCMMaterialConfig pluggableSCMMaterialConfig = new PluggableSCMMaterialConfig("scm-id");
setField(pluggableSCMMaterialConfig, "scmConfig", scmConfig);
BasicCruiseConfig config = new BasicCruiseConfig();
config.getSCMs().add(scmConfig);
final ConfigSaveValidationContext context = new ConfigSaveValidationContext(config);
new GoConfigGraphWalker(pluggableSCMMaterialConfig).walk(new GoConfigGraphWalker.Handler() {
@Override
public void handle(Validatable validatable, ValidationContext ctx) {
validatable.validate(context);
}
});
verify(scmConfig, never()).validate(any(ValidationContext.class));
}
use of com.thoughtworks.go.config.materials.PluggableSCMMaterialConfig in project gocd by gocd.
the class PipelineConfigTest method shouldGetPluggableSCMMaterialConfigs.
@Test
public void shouldGetPluggableSCMMaterialConfigs() throws Exception {
SvnMaterialConfig svn = svn("svn", false);
PluggableSCMMaterialConfig pluggableSCMMaterialOne = new PluggableSCMMaterialConfig("scm-id-1");
PluggableSCMMaterialConfig pluggableSCMMaterialTwo = new PluggableSCMMaterialConfig("scm-id-2");
PipelineConfig pipelineConfig = PipelineConfigMother.pipelineConfig("p1", new MaterialConfigs(svn, pluggableSCMMaterialOne, pluggableSCMMaterialTwo));
List<PluggableSCMMaterialConfig> pluggableSCMMaterialConfigs = pipelineConfig.pluggableSCMMaterialConfigs();
assertThat(pluggableSCMMaterialConfigs.size(), is(2));
assertThat(pluggableSCMMaterialConfigs, hasItems(pluggableSCMMaterialOne, pluggableSCMMaterialTwo));
}
Aggregations