Search in sources :

Example 21 with GoCipher

use of com.thoughtworks.go.security.GoCipher in project gocd by gocd.

the class TfsMaterialConfigUpdateTest method shouldErrorOutIfDecryptionFails.

@Test
public void shouldErrorOutIfDecryptionFails() throws InvalidCipherTextException {
    GoCipher mockGoCipher = mock(GoCipher.class);
    String fakeCipherText = "fake cipher text";
    when(mockGoCipher.decrypt(fakeCipherText)).thenThrow(new InvalidCipherTextException("exception"));
    TfsMaterialConfig materialConfig = new TfsMaterialConfig(mockGoCipher, new UrlArgument("http://10.4.4.101:8080/tfs/Sample"), "loser", "CORPORATE", "passwd", "walk_this_path");
    ReflectionUtil.setField(materialConfig, "encryptedPassword", fakeCipherText);
    try {
        materialConfig.getPassword();
        fail("Should have thrown up");
    } catch (Exception e) {
        assertThat(e.getMessage(), is("Could not decrypt the password to get the real password"));
    }
}
Also used : UrlArgument(com.thoughtworks.go.util.command.UrlArgument) InvalidCipherTextException(org.bouncycastle.crypto.InvalidCipherTextException) GoCipher(com.thoughtworks.go.security.GoCipher) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) InvalidCipherTextException(org.bouncycastle.crypto.InvalidCipherTextException) Test(org.junit.Test)

Example 22 with GoCipher

use of com.thoughtworks.go.security.GoCipher in project gocd by gocd.

the class TfsMaterialConfigUpdateTest method shouldValidateWhetherTheEncryptedPasswordIsCorrect.

@Test
public void shouldValidateWhetherTheEncryptedPasswordIsCorrect() {
    TfsMaterialConfig materialConfig = new TfsMaterialConfig(new UrlArgument("foo/bar"), "", "encryptedPassword", new GoCipher());
    materialConfig.validate(new ConfigSaveValidationContext(null));
    assertThat(materialConfig.errors().on("encryptedPassword"), is("Encrypted password value for TFS 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 23 with GoCipher

use of com.thoughtworks.go.security.GoCipher in project gocd by gocd.

the class TfsMaterialConfigUpdateTest method shouldThrowErrorsIfBothPasswordAndEncryptedPasswordAreProvided.

@Test
public void shouldThrowErrorsIfBothPasswordAndEncryptedPasswordAreProvided() {
    TfsMaterialConfig materialConfig = new TfsMaterialConfig(new UrlArgument("foo/bar"), "password", "encryptedPassword", new GoCipher());
    materialConfig.validate(new ConfigSaveValidationContext(null));
    assertThat(materialConfig.errors().on("password"), is("You may only specify `password` or `encrypted_password`, not both!"));
    assertThat(materialConfig.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 24 with GoCipher

use of com.thoughtworks.go.security.GoCipher in project gocd by gocd.

the class TfsMaterialConfigUpdateTest method shouldSetConfigAttributes.

@Test
public void shouldSetConfigAttributes() {
    TfsMaterialConfig tfsMaterialConfig = new TfsMaterialConfig(new GoCipher(), new UrlArgument("http://10.4.4.101:8080/tfs/Sample"), "loser", "some_domain", "passwd", "walk_this_path");
    Map<String, String> map = new HashMap<>();
    map.put(ScmMaterialConfig.URL, "http://foo:8080/tfs/HelloWorld");
    map.put(ScmMaterialConfig.USERNAME, "boozer");
    map.put(ScmMaterialConfig.PASSWORD, "secret");
    map.put(ScmMaterialConfig.FOLDER, "folder");
    map.put(ScmMaterialConfig.AUTO_UPDATE, "0");
    map.put(ScmMaterialConfig.FILTER, "/root,/**/*.help");
    map.put(AbstractMaterialConfig.MATERIAL_NAME, "my-tfs-material-name");
    map.put(TfsMaterialConfig.PROJECT_PATH, "/useless/project");
    map.put(TfsMaterialConfig.DOMAIN, "CORPORATE");
    tfsMaterialConfig.setConfigAttributes(map);
    TfsMaterialConfig newTfsMaterialConfig = new TfsMaterialConfig(new GoCipher(), new UrlArgument("http://foo:8080/tfs/HelloWorld"), "boozer", "CORPORATE", "secret", "/useless/project");
    newTfsMaterialConfig.setName(new CaseInsensitiveString("my-tfs-material-name"));
    newTfsMaterialConfig.setFolder("folder");
    assertThat(tfsMaterialConfig, is(newTfsMaterialConfig));
    assertThat(tfsMaterialConfig.getPassword(), is("passwd"));
    assertThat(tfsMaterialConfig.isAutoUpdate(), is(false));
    assertThat(tfsMaterialConfig.getDomain(), is("CORPORATE"));
    assertThat(tfsMaterialConfig.getName(), is(new CaseInsensitiveString("my-tfs-material-name")));
    assertThat(tfsMaterialConfig.filter(), is(new Filter(new IgnoredFiles("/root"), new IgnoredFiles("/**/*.help"))));
}
Also used : UrlArgument(com.thoughtworks.go.util.command.UrlArgument) GoCipher(com.thoughtworks.go.security.GoCipher) HashMap(java.util.HashMap) Filter(com.thoughtworks.go.config.materials.Filter) IgnoredFiles(com.thoughtworks.go.config.materials.IgnoredFiles) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Test(org.junit.Test)

Example 25 with GoCipher

use of com.thoughtworks.go.security.GoCipher in project gocd by gocd.

the class TfsMaterialConfigUpdateTest method validate_shouldEnsureDestFilePathIsValid.

@Test
public void validate_shouldEnsureDestFilePathIsValid() {
    TfsMaterialConfig tfsMaterialConfig = new TfsMaterialConfig(new GoCipher(), new UrlArgument("http://10.4.4.101:8080/tfs/Sample"), "loser", "CORPORATE", "passwd", "walk_this_path");
    tfsMaterialConfig.setConfigAttributes(Collections.singletonMap(ScmMaterialConfig.FOLDER, "../a"));
    tfsMaterialConfig.validate(new ConfigSaveValidationContext(null));
    assertThat(tfsMaterialConfig.errors().on(TfsMaterialConfig.FOLDER), is("Dest folder '../a' is not valid. It must be a sub-directory of the working folder."));
}
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)

Aggregations

GoCipher (com.thoughtworks.go.security.GoCipher)196 Test (org.junit.jupiter.api.Test)117 Test (org.junit.Test)57 UrlArgument (com.thoughtworks.go.util.command.UrlArgument)30 ArrayList (java.util.ArrayList)23 PluginConfiguration (com.thoughtworks.go.plugin.domain.common.PluginConfiguration)22 ConfigurationProperty (com.thoughtworks.go.domain.config.ConfigurationProperty)21 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)19 HashMap (java.util.HashMap)19 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)17 ConfigurationKey (com.thoughtworks.go.domain.config.ConfigurationKey)13 Metadata (com.thoughtworks.go.plugin.domain.common.Metadata)13 PluggableInstanceSettings (com.thoughtworks.go.plugin.domain.common.PluggableInstanceSettings)13 ConfigurationValue (com.thoughtworks.go.domain.config.ConfigurationValue)11 EnvironmentVariableConfig (com.thoughtworks.go.config.EnvironmentVariableConfig)10 SvnMaterialConfig (com.thoughtworks.go.config.materials.svn.SvnMaterialConfig)10 File (java.io.File)9 ConfigSaveValidationContext (com.thoughtworks.go.config.ConfigSaveValidationContext)8 TfsMaterialConfig (com.thoughtworks.go.config.materials.tfs.TfsMaterialConfig)8 Configuration (com.thoughtworks.go.domain.config.Configuration)8