use of com.thoughtworks.go.config.materials.perforce.P4MaterialConfig in project gocd by gocd.
the class MagicalGoConfigXmlWriterTest method shouldWriteP4MaterialToXmlPartial.
@Test
public void shouldWriteP4MaterialToXmlPartial() throws Exception {
String encryptedPassword = new GoCipher().encrypt("password");
P4MaterialConfig p4MaterialConfig = com.thoughtworks.go.helper.MaterialConfigsMother.p4MaterialConfig();
p4MaterialConfig.setPassword("password");
p4MaterialConfig.setConfigAttributes(m(P4MaterialConfig.SERVER_AND_PORT, "localhost:1666", P4MaterialConfig.USERNAME, "cruise", P4MaterialConfig.VIEW, "//depot/dir1/... //lumberjack/...", P4MaterialConfig.AUTO_UPDATE, "true"));
assertThat(xmlWriter.toXmlPartial(p4MaterialConfig), is("<p4 port=\"localhost:1666\" username=\"cruise\" encryptedPassword=\"" + encryptedPassword + "\">\n" + " <view><![CDATA[" + "//depot/dir1/... //lumberjack/..." + "]]></view>\n" + "</p4>"));
}
use of com.thoughtworks.go.config.materials.perforce.P4MaterialConfig in project gocd by gocd.
the class DependencyMaterialConfigTest method shouldBeAbleToHaveADependencyAndOneOtherMaterial.
@Test
public void shouldBeAbleToHaveADependencyAndOneOtherMaterial() throws Exception {
NewGoConfigMother mother = new NewGoConfigMother();
mother.addPipeline("pipeline-name", "stage-name", "job-name");
PipelineConfig pipelineConfig = mother.addPipeline("dependent", "stage-name", "job-name", new DependencyMaterialConfig(new CaseInsensitiveString("pipeline-name"), new CaseInsensitiveString("stage-name")));
pipelineConfig.addMaterialConfig(new P4MaterialConfig("localhost:1666", "foo"));
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
CruiseConfig cruiseConfig = mother.cruiseConfig();
writer.write(cruiseConfig, buffer, false);
final ByteArrayInputStream inputStream = new ByteArrayInputStream(buffer.toByteArray());
CruiseConfig config = loader.loadConfigHolder(FileUtil.readToEnd(inputStream)).config;
MaterialConfigs materialConfigs = config.pipelineConfigByName(new CaseInsensitiveString("dependent")).materialConfigs();
assertThat(materialConfigs.get(0), is(instanceOf(DependencyMaterialConfig.class)));
assertThat(materialConfigs.get(1), is(instanceOf(P4MaterialConfig.class)));
}
use of com.thoughtworks.go.config.materials.perforce.P4MaterialConfig in project gocd by gocd.
the class ConfigCipherUpdaterTest method shouldMigrateEncryptedPasswordsThatWereEncryptedWithFlawedCipher.
@Test
public void shouldMigrateEncryptedPasswordsThatWereEncryptedWithFlawedCipher() throws Exception {
String originalConfig = FileUtil.readContentFromFile(originalConfigFile);
assertThat(originalConfig.contains("encryptedPassword=\"" + passwordEncryptedWithFlawedCipher + "\""), is(true));
updater.migrate();
File copyOfOldConfig = new File(systemEnvironment.getConfigDir(), "cipher.original." + timestamp);
assertThat(copyOfOldConfig.exists(), is(true));
assertThat(FileUtil.readContentFromFile(copyOfOldConfig).equals(ConfigCipherUpdater.FLAWED_VALUE), is(true));
String newCipher = FileUtil.readContentFromFile(systemEnvironment.getCipherFile());
assertThat(newCipher.equals(ConfigCipherUpdater.FLAWED_VALUE), is(false));
File editedConfigFile = new File(systemEnvironment.getCruiseConfigFile());
String editedConfig = FileUtil.readContentFromFile(editedConfigFile);
assertThat(editedConfig.contains("encryptedPassword=\"" + passwordEncryptedWithFlawedCipher + "\""), is(false));
String passwordEncryptedWithNewCipher = new GoCipher().encrypt(password);
CruiseConfig config = magicalGoConfigXmlLoader.loadConfigHolder(editedConfig).config;
MaterialConfigs materialConfigs = config.getAllPipelineConfigs().get(0).materialConfigs();
SvnMaterialConfig svnMaterial = materialConfigs.getSvnMaterial();
assertThat(svnMaterial.getPassword(), is(password));
assertThat(svnMaterial.getEncryptedPassword(), is(passwordEncryptedWithNewCipher));
P4MaterialConfig p4Material = materialConfigs.getP4Material();
assertThat(p4Material.getPassword(), is(password));
assertThat(p4Material.getEncryptedPassword(), is(passwordEncryptedWithNewCipher));
TfsMaterialConfig tfsMaterial = materialConfigs.getTfsMaterial();
assertThat(tfsMaterial.getPassword(), is(password));
assertThat(tfsMaterial.getEncryptedPassword(), is(passwordEncryptedWithNewCipher));
}
use of com.thoughtworks.go.config.materials.perforce.P4MaterialConfig in project gocd by gocd.
the class ConfigConverterTest method shouldConvertP4MaterialWhenPlainPassword.
@Test
public void shouldConvertP4MaterialWhenPlainPassword() {
CRP4Material crp4Material = CRP4Material.withPlainPassword("name", "folder", false, false, filter, "server:port", "user", "secret", true, "view");
P4MaterialConfig p4MaterialConfig = (P4MaterialConfig) configConverter.toMaterialConfig(crp4Material, context);
assertThat(p4MaterialConfig.getName().toLower(), is("name"));
assertThat(p4MaterialConfig.getFolder(), is("folder"));
assertThat(p4MaterialConfig.getAutoUpdate(), is(false));
assertThat(p4MaterialConfig.getFilterAsString(), is("filter"));
assertThat(p4MaterialConfig.getUrl(), is("server:port"));
assertThat(p4MaterialConfig.getUserName(), is("user"));
assertThat(p4MaterialConfig.getPassword(), is("secret"));
assertThat(p4MaterialConfig.getUseTickets(), is(true));
assertThat(p4MaterialConfig.getView(), is("view"));
}
use of com.thoughtworks.go.config.materials.perforce.P4MaterialConfig in project gocd by gocd.
the class ParamResolverTest method shouldErrorOutIfCannotResolveParamForP4View.
@Test
public void shouldErrorOutIfCannotResolveParamForP4View() {
P4MaterialConfig p4MaterialConfig = new P4MaterialConfig("server:port", "#");
new ParamResolver(new ParamSubstitutionHandlerFactory(params(param("foo", "pavan"), param("bar", "jj"))), fieldCache).resolve(p4MaterialConfig);
assertThat(p4MaterialConfig.getP4MaterialView().errors().on(P4MaterialConfig.VIEW), is("Error when processing params for '#' used in field 'view', # must be followed by a parameter pattern or escaped by another #"));
}
Aggregations