Search in sources :

Example 1 with P4MaterialConfig

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>"));
}
Also used : GoCipher(com.thoughtworks.go.security.GoCipher) P4MaterialConfig(com.thoughtworks.go.config.materials.perforce.P4MaterialConfig) Test(org.junit.Test)

Example 2 with P4MaterialConfig

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)));
}
Also used : MaterialConfigs(com.thoughtworks.go.config.materials.MaterialConfigs) NewGoConfigMother(com.thoughtworks.go.domain.materials.dependency.NewGoConfigMother) P4MaterialConfig(com.thoughtworks.go.config.materials.perforce.P4MaterialConfig) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DependencyMaterialConfig(com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig) Test(org.junit.Test)

Example 3 with P4MaterialConfig

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));
}
Also used : MaterialConfigs(com.thoughtworks.go.config.materials.MaterialConfigs) GoCipher(com.thoughtworks.go.security.GoCipher) P4MaterialConfig(com.thoughtworks.go.config.materials.perforce.P4MaterialConfig) TfsMaterialConfig(com.thoughtworks.go.config.materials.tfs.TfsMaterialConfig) SvnMaterialConfig(com.thoughtworks.go.config.materials.svn.SvnMaterialConfig) File(java.io.File) Test(org.junit.Test)

Example 4 with P4MaterialConfig

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"));
}
Also used : P4MaterialConfig(com.thoughtworks.go.config.materials.perforce.P4MaterialConfig) Test(org.junit.Test)

Example 5 with P4MaterialConfig

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 #"));
}
Also used : P4MaterialConfig(com.thoughtworks.go.config.materials.perforce.P4MaterialConfig) Test(org.junit.Test)

Aggregations

P4MaterialConfig (com.thoughtworks.go.config.materials.perforce.P4MaterialConfig)29 Test (org.junit.Test)22 SvnMaterialConfig (com.thoughtworks.go.config.materials.svn.SvnMaterialConfig)13 GitMaterialConfig (com.thoughtworks.go.config.materials.git.GitMaterialConfig)8 HgMaterialConfig (com.thoughtworks.go.config.materials.mercurial.HgMaterialConfig)8 DependencyMaterialConfig (com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig)7 TfsMaterialConfig (com.thoughtworks.go.config.materials.tfs.TfsMaterialConfig)7 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)4 MaterialConfigs (com.thoughtworks.go.config.materials.MaterialConfigs)4 MaterialConfig (com.thoughtworks.go.domain.materials.MaterialConfig)4 GoCipher (com.thoughtworks.go.security.GoCipher)4 Matchers.containsString (org.hamcrest.Matchers.containsString)4 PipelineConfig (com.thoughtworks.go.config.PipelineConfig)3 PackageMaterialConfig (com.thoughtworks.go.config.materials.PackageMaterialConfig)3 PluggableSCMMaterialConfig (com.thoughtworks.go.config.materials.PluggableSCMMaterialConfig)3 ScmMaterialConfig (com.thoughtworks.go.config.materials.ScmMaterialConfig)2 MaterialConfigsMother.filteredHgMaterialConfig (com.thoughtworks.go.helper.MaterialConfigsMother.filteredHgMaterialConfig)2 UrlArgument (com.thoughtworks.go.util.command.UrlArgument)2 Date (java.util.Date)2 Filter (com.thoughtworks.go.config.materials.Filter)1