Search in sources :

Example 71 with GoCipher

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

the class TfsMaterialTest method shouldGetLongDescriptionForMaterial.

@Test
public void shouldGetLongDescriptionForMaterial() {
    TfsMaterial material = new TfsMaterial(new GoCipher(), new UrlArgument("http://url/"), "user", "domain", "password", "$project/path/");
    assertThat(material.getLongDescription(), is("URL: http://url/, Username: user, Domain: domain, ProjectPath: $project/path/"));
}
Also used : UrlArgument(com.thoughtworks.go.util.command.UrlArgument) GoCipher(com.thoughtworks.go.security.GoCipher) Test(org.junit.Test)

Example 72 with GoCipher

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

the class TfsMaterialTest method shouldReturnUrlForCommandLine_asUrl_IfSet.

@Test
public void shouldReturnUrlForCommandLine_asUrl_IfSet() {
    TfsMaterial tfsMaterial = new TfsMaterial(new GoCipher(), new UrlArgument("http://foo:bar@my-url.com"), "loser", DOMAIN, "foo_bar_baz", "/dev/null");
    assertThat(tfsMaterial.getUrl(), is("http://foo:bar@my-url.com"));
    tfsMaterial = new TfsMaterial(new GoCipher(), null, "loser", DOMAIN, "foo_bar_baz", "/dev/null");
    assertThat(tfsMaterial.getUrl(), is(nullValue()));
}
Also used : UrlArgument(com.thoughtworks.go.util.command.UrlArgument) GoCipher(com.thoughtworks.go.security.GoCipher) Test(org.junit.Test)

Example 73 with GoCipher

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

the class TfsMaterialTest method shouldDecryptTfsPassword.

@Test
public void shouldDecryptTfsPassword() throws Exception {
    GoCipher mockGoCipher = mock(GoCipher.class);
    when(mockGoCipher.decrypt("encrypted")).thenReturn("password");
    TfsMaterial tfsMaterial = new TfsMaterial(mockGoCipher, new UrlArgument("/foo"), "username", DOMAIN, null, "");
    ReflectionUtil.setField(tfsMaterial, "encryptedPassword", "encrypted");
    tfsMaterial.ensureEncrypted();
    assertThat(tfsMaterial.getPassword(), is("password"));
}
Also used : UrlArgument(com.thoughtworks.go.util.command.UrlArgument) GoCipher(com.thoughtworks.go.security.GoCipher) Test(org.junit.Test)

Example 74 with GoCipher

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

the class TfsMaterialTest method shouldGetAttributesWithoutSecureFields.

@Test
public void shouldGetAttributesWithoutSecureFields() {
    TfsMaterial material = new TfsMaterial(new GoCipher(), new UrlArgument("http://username:password@tfsrepo.com"), "username", "domain", "password", "$project/path/");
    Map<String, Object> attributes = material.getAttributes(false);
    assertThat(attributes.get("type"), is("tfs"));
    Map<String, Object> configuration = (Map<String, Object>) attributes.get("tfs-configuration");
    assertThat(configuration.get("url"), is("http://username:******@tfsrepo.com"));
    assertThat(configuration.get("domain"), is("domain"));
    assertThat(configuration.get("username"), is("username"));
    assertThat(configuration.get("password"), is(nullValue()));
    assertThat(configuration.get("project-path"), is("$project/path/"));
}
Also used : UrlArgument(com.thoughtworks.go.util.command.UrlArgument) GoCipher(com.thoughtworks.go.security.GoCipher) Map(java.util.Map) Test(org.junit.Test)

Example 75 with GoCipher

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

the class TfsMaterialTest method shouldErrorOutIfEncryptionFails.

@Test
public void shouldErrorOutIfEncryptionFails() throws Exception {
    GoCipher mockGoCipher = mock(GoCipher.class);
    when(mockGoCipher.encrypt("password")).thenThrow(new InvalidCipherTextException("exception"));
    try {
        new TfsMaterial(mockGoCipher, new UrlArgument("/foo"), "username", DOMAIN, "password", "");
        fail("Should have thrown up");
    } catch (Exception e) {
        assertThat(e.getMessage(), is("Password encryption failed. Please verify your cipher key."));
    }
}
Also used : UrlArgument(com.thoughtworks.go.util.command.UrlArgument) InvalidCipherTextException(org.bouncycastle.crypto.InvalidCipherTextException) GoCipher(com.thoughtworks.go.security.GoCipher) InvalidCipherTextException(org.bouncycastle.crypto.InvalidCipherTextException) Test(org.junit.Test)

Aggregations

GoCipher (com.thoughtworks.go.security.GoCipher)143 Test (org.junit.Test)122 UrlArgument (com.thoughtworks.go.util.command.UrlArgument)36 HashMap (java.util.HashMap)15 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)14 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)12 Matchers.containsString (org.hamcrest.Matchers.containsString)12 ConfigSaveValidationContext (com.thoughtworks.go.config.ConfigSaveValidationContext)9 Configuration (com.thoughtworks.go.domain.config.Configuration)9 ConfigurationProperty (com.thoughtworks.go.domain.config.ConfigurationProperty)9 BaseConfig (com.thoughtworks.go.config.server.security.ldap.BaseConfig)8 BasesConfig (com.thoughtworks.go.config.server.security.ldap.BasesConfig)8 ConfigurationKey (com.thoughtworks.go.domain.config.ConfigurationKey)8 ConfigurationValue (com.thoughtworks.go.domain.config.ConfigurationValue)8 EncryptedConfigurationValue (com.thoughtworks.go.domain.config.EncryptedConfigurationValue)8 SvnMaterialConfig (com.thoughtworks.go.config.materials.svn.SvnMaterialConfig)7 TfsMaterialConfig (com.thoughtworks.go.config.materials.tfs.TfsMaterialConfig)7 PluginConfiguration (com.thoughtworks.go.domain.config.PluginConfiguration)7 PackageConfiguration (com.thoughtworks.go.plugin.access.packagematerial.PackageConfiguration)7 Map (java.util.Map)7