Search in sources :

Example 16 with UrlArgument

use of com.thoughtworks.go.util.command.UrlArgument in project gocd by gocd.

the class SvnMaterialConfigTest method shouldThrowErrorsIfBothPasswordAndEncryptedPasswordAreProvided.

@Test
public void shouldThrowErrorsIfBothPasswordAndEncryptedPasswordAreProvided() {
    SvnMaterialConfig svnMaterialConfig = new SvnMaterialConfig(new UrlArgument("foo/bar"), "password", "encryptedPassword", new GoCipher(), null, false, "folder");
    svnMaterialConfig.validate(new ConfigSaveValidationContext(null));
    assertThat(svnMaterialConfig.errors().on("password"), is("You may only specify `password` or `encrypted_password`, not both!"));
    assertThat(svnMaterialConfig.errors().on("encryptedPassword"), is("You may only specify `password` or `encrypted_password`, not both!"));
}
Also used : UrlArgument(com.thoughtworks.go.util.command.UrlArgument) GoCipher(com.thoughtworks.go.security.GoCipher) ConfigSaveValidationContext(com.thoughtworks.go.config.ConfigSaveValidationContext) Test(org.junit.Test)

Example 17 with UrlArgument

use of com.thoughtworks.go.util.command.UrlArgument in project gocd by gocd.

the class SvnMaterialConfigTest method shouldValidateWhetherTheEncryptedPasswordIsCorrect.

@Test
public void shouldValidateWhetherTheEncryptedPasswordIsCorrect() {
    SvnMaterialConfig svnMaterialConfig = new SvnMaterialConfig(new UrlArgument("foo/bar"), "", "encryptedPassword", new GoCipher(), null, false, "folder");
    svnMaterialConfig.validate(new ConfigSaveValidationContext(null));
    assertThat(svnMaterialConfig.errors().on("encryptedPassword"), is("Encrypted password value for svn material with url 'foo/bar' is invalid. This usually happens when the cipher text is modified to have an invalid value."));
}
Also used : UrlArgument(com.thoughtworks.go.util.command.UrlArgument) GoCipher(com.thoughtworks.go.security.GoCipher) ConfigSaveValidationContext(com.thoughtworks.go.config.ConfigSaveValidationContext) Test(org.junit.Test)

Example 18 with UrlArgument

use of com.thoughtworks.go.util.command.UrlArgument in project gocd by gocd.

the class MaterialConfigsMother method tfsMaterialConfig.

public static TfsMaterialConfig tfsMaterialConfig() {
    Filter filter = new Filter(new IgnoredFiles("**/*.html"), new IgnoredFiles("**/foobar/"));
    TfsMaterialConfig tfsMaterialConfig = new TfsMaterialConfig(new GoCipher(), new UrlArgument("http://10.4.4.101:8080/tfs/Sample"), "loser", "some_domain", "passwd", "walk_this_path");
    tfsMaterialConfig.setFilter(filter);
    tfsMaterialConfig.setName(new CaseInsensitiveString("tfs-material"));
    tfsMaterialConfig.setFolder("dest-folder");
    return tfsMaterialConfig;
}
Also used : HgUrlArgument(com.thoughtworks.go.util.command.HgUrlArgument) UrlArgument(com.thoughtworks.go.util.command.UrlArgument) GoCipher(com.thoughtworks.go.security.GoCipher) TfsMaterialConfig(com.thoughtworks.go.config.materials.tfs.TfsMaterialConfig) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString)

Example 19 with UrlArgument

use of com.thoughtworks.go.util.command.UrlArgument in project gocd by gocd.

the class ConfigConverter method toScmMaterialConfig.

private ScmMaterialConfig toScmMaterialConfig(CRScmMaterial crScmMaterial) {
    String materialName = crScmMaterial.getName();
    if (crScmMaterial instanceof CRGitMaterial) {
        CRGitMaterial git = (CRGitMaterial) crScmMaterial;
        String gitBranch = git.getBranch();
        if (StringUtils.isBlank(gitBranch))
            gitBranch = GitMaterialConfig.DEFAULT_BRANCH;
        GitMaterialConfig gitConfig = new GitMaterialConfig(git.getUrl(), gitBranch, git.shallowClone());
        setCommonMaterialMembers(gitConfig, crScmMaterial);
        setCommonScmMaterialMembers(gitConfig, git);
        return gitConfig;
    } else if (crScmMaterial instanceof CRHgMaterial) {
        CRHgMaterial hg = (CRHgMaterial) crScmMaterial;
        return new HgMaterialConfig(new HgUrlArgument(hg.getUrl()), hg.isAutoUpdate(), toFilter(crScmMaterial), false, hg.getDirectory(), toMaterialName(materialName));
    } else if (crScmMaterial instanceof CRP4Material) {
        CRP4Material crp4Material = (CRP4Material) crScmMaterial;
        P4MaterialConfig p4MaterialConfig = new P4MaterialConfig(crp4Material.getServerAndPort(), crp4Material.getView(), cipher);
        if (crp4Material.getEncryptedPassword() != null) {
            p4MaterialConfig.setEncryptedPassword(crp4Material.getEncryptedPassword());
        } else {
            p4MaterialConfig.setPassword(crp4Material.getPassword());
        }
        p4MaterialConfig.setUserName(crp4Material.getUserName());
        p4MaterialConfig.setUseTickets(crp4Material.getUseTickets());
        setCommonMaterialMembers(p4MaterialConfig, crScmMaterial);
        setCommonScmMaterialMembers(p4MaterialConfig, crp4Material);
        return p4MaterialConfig;
    } else if (crScmMaterial instanceof CRSvnMaterial) {
        CRSvnMaterial crSvnMaterial = (CRSvnMaterial) crScmMaterial;
        SvnMaterialConfig svnMaterialConfig = new SvnMaterialConfig(crSvnMaterial.getUrl(), crSvnMaterial.getUserName(), crSvnMaterial.isCheckExternals(), cipher);
        if (crSvnMaterial.getEncryptedPassword() != null) {
            svnMaterialConfig.setEncryptedPassword(crSvnMaterial.getEncryptedPassword());
        } else {
            svnMaterialConfig.setPassword(crSvnMaterial.getPassword());
        }
        setCommonMaterialMembers(svnMaterialConfig, crScmMaterial);
        setCommonScmMaterialMembers(svnMaterialConfig, crSvnMaterial);
        return svnMaterialConfig;
    } else if (crScmMaterial instanceof CRTfsMaterial) {
        CRTfsMaterial crTfsMaterial = (CRTfsMaterial) crScmMaterial;
        TfsMaterialConfig tfsMaterialConfig = new TfsMaterialConfig(cipher, new UrlArgument(crTfsMaterial.getUrl()), crTfsMaterial.getUserName(), crTfsMaterial.getDomain(), crTfsMaterial.getProjectPath());
        if (crTfsMaterial.getEncryptedPassword() != null) {
            tfsMaterialConfig.setEncryptedPassword(crTfsMaterial.getEncryptedPassword());
        } else {
            tfsMaterialConfig.setPassword(crTfsMaterial.getPassword());
        }
        setCommonMaterialMembers(tfsMaterialConfig, crTfsMaterial);
        setCommonScmMaterialMembers(tfsMaterialConfig, crTfsMaterial);
        return tfsMaterialConfig;
    } else
        throw new ConfigConvertionException(String.format("unknown scm material type '%s'", crScmMaterial));
}
Also used : HgUrlArgument(com.thoughtworks.go.util.command.HgUrlArgument) HgMaterialConfig(com.thoughtworks.go.config.materials.mercurial.HgMaterialConfig) HgUrlArgument(com.thoughtworks.go.util.command.HgUrlArgument) UrlArgument(com.thoughtworks.go.util.command.UrlArgument) GitMaterialConfig(com.thoughtworks.go.config.materials.git.GitMaterialConfig) P4MaterialConfig(com.thoughtworks.go.config.materials.perforce.P4MaterialConfig) TfsMaterialConfig(com.thoughtworks.go.config.materials.tfs.TfsMaterialConfig) SvnMaterialConfig(com.thoughtworks.go.config.materials.svn.SvnMaterialConfig)

Example 20 with UrlArgument

use of com.thoughtworks.go.util.command.UrlArgument in project gocd by gocd.

the class GitPostCommitHookImplementerTest method shouldReturnListOfMaterialMatchingThePayloadURL.

@Test
public void shouldReturnListOfMaterialMatchingThePayloadURL() throws Exception {
    GitMaterial material1 = mock(GitMaterial.class);
    when(material1.getUrlArgument()).thenReturn(new UrlArgument("https://other_repo.local.git"));
    GitMaterial material2 = mock(GitMaterial.class);
    when(material2.getUrlArgument()).thenReturn(new UrlArgument("https://other_repo.local.git"));
    GitMaterial material3 = mock(GitMaterial.class);
    when(material3.getUrlArgument()).thenReturn(new UrlArgument("https://machine.local.git"));
    GitMaterial material4 = mock(GitMaterial.class);
    when(material4.getUrlArgument()).thenReturn(new UrlArgument("https://machine.local.git"));
    Set<Material> materials = new HashSet<>(Arrays.asList(material1, material2, material3, material4));
    HashMap params = new HashMap();
    params.put(GitPostCommitHookImplementer.REPO_URL_PARAM_KEY, "https://machine.local.git");
    Set<Material> actual = implementer.prune(materials, params);
    assertThat(actual.size(), is(2));
    assertThat(actual, hasItem(material3));
    assertThat(actual, hasItem(material4));
    verify(material1).getUrlArgument();
    verify(material2).getUrlArgument();
    verify(material3).getUrlArgument();
    verify(material4).getUrlArgument();
}
Also used : UrlArgument(com.thoughtworks.go.util.command.UrlArgument) GitMaterial(com.thoughtworks.go.config.materials.git.GitMaterial) GitMaterial(com.thoughtworks.go.config.materials.git.GitMaterial) SvnMaterial(com.thoughtworks.go.config.materials.svn.SvnMaterial) Material(com.thoughtworks.go.domain.materials.Material) Test(org.junit.Test)

Aggregations

UrlArgument (com.thoughtworks.go.util.command.UrlArgument)58 Test (org.junit.Test)44 GoCipher (com.thoughtworks.go.security.GoCipher)37 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)9 ConfigSaveValidationContext (com.thoughtworks.go.config.ConfigSaveValidationContext)7 TfsMaterialConfig (com.thoughtworks.go.config.materials.tfs.TfsMaterialConfig)7 GitMaterialConfig (com.thoughtworks.go.config.materials.git.GitMaterialConfig)5 SvnMaterialConfig (com.thoughtworks.go.config.materials.svn.SvnMaterialConfig)5 Material (com.thoughtworks.go.domain.materials.Material)5 Map (java.util.Map)5 GitMaterial (com.thoughtworks.go.config.materials.git.GitMaterial)4 HgMaterialConfig (com.thoughtworks.go.config.materials.mercurial.HgMaterialConfig)4 P4MaterialConfig (com.thoughtworks.go.config.materials.perforce.P4MaterialConfig)4 SvnMaterial (com.thoughtworks.go.config.materials.svn.SvnMaterial)4 TfsMaterial (com.thoughtworks.go.config.materials.tfs.TfsMaterial)4 HgUrlArgument (com.thoughtworks.go.util.command.HgUrlArgument)4 InvalidCipherTextException (org.bouncycastle.crypto.InvalidCipherTextException)4 MaterialConfigs (com.thoughtworks.go.config.materials.MaterialConfigs)3 PackageMaterialConfig (com.thoughtworks.go.config.materials.PackageMaterialConfig)3 PluggableSCMMaterialConfig (com.thoughtworks.go.config.materials.PluggableSCMMaterialConfig)3