Search in sources :

Example 81 with GoCipher

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

the class SvnMaterialTest method shouldNotDecryptSvnPasswordIfPasswordIsNotNull.

@Test
public void shouldNotDecryptSvnPasswordIfPasswordIsNotNull() throws Exception {
    GoCipher mockGoCipher = mock(GoCipher.class);
    when(mockGoCipher.encrypt("password")).thenReturn("encrypted");
    when(mockGoCipher.decrypt("encrypted")).thenReturn("password");
    SvnMaterial material = new SvnMaterial("/foo", "username", "password", false, mockGoCipher);
    material.ensureEncrypted();
    when(mockGoCipher.encrypt("new_password")).thenReturn("new_encrypted");
    material.setPassword("new_password");
    when(mockGoCipher.decrypt("new_encrypted")).thenReturn("new_password");
    assertThat(material.getPassword(), is("new_password"));
}
Also used : GoCipher(com.thoughtworks.go.security.GoCipher) SvnMaterial(com.thoughtworks.go.config.materials.svn.SvnMaterial) Test(org.junit.Test)

Example 82 with GoCipher

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

the class SvnMaterialTest method shouldErrorOutIfEncryptionFails.

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

Example 83 with GoCipher

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

the class SvnMaterialTest method shouldEncryptSvnPasswordAndMarkPasswordAsNull.

@Test
public void shouldEncryptSvnPasswordAndMarkPasswordAsNull() throws Exception {
    GoCipher mockGoCipher = mock(GoCipher.class);
    when(mockGoCipher.encrypt("password")).thenReturn("encrypted");
    SvnMaterial material = new SvnMaterial("/foo", "username", "password", false, mockGoCipher);
    material.ensureEncrypted();
    assertThat(material.getPassword(), is(nullValue()));
    assertThat(material.getEncryptedPassword(), is("encrypted"));
}
Also used : GoCipher(com.thoughtworks.go.security.GoCipher) SvnMaterial(com.thoughtworks.go.config.materials.svn.SvnMaterial) Test(org.junit.Test)

Example 84 with GoCipher

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

the class PackageRepositoryTest method shouldSetConfigAttributesAsAvailable.

@Test
public void shouldSetConfigAttributesAsAvailable() throws Exception {
    //metadata setup
    PackageConfigurations repositoryConfiguration = new PackageConfigurations();
    repositoryConfiguration.add(new PackageConfiguration("url"));
    repositoryConfiguration.add(new PackageConfiguration("username"));
    repositoryConfiguration.add(new PackageConfiguration("password").with(SECURE, true));
    repositoryConfiguration.add(new PackageConfiguration("secureKeyNotChanged").with(SECURE, true));
    RepositoryMetadataStore.getInstance().addMetadataFor("yum", repositoryConfiguration);
    String name = "go-server";
    String repoId = "repo-id";
    String pluginId = "yum";
    ConfigurationHolder url = new ConfigurationHolder("url", "http://test.com");
    ConfigurationHolder username = new ConfigurationHolder("username", "user");
    String oldEncryptedValue = "oldEncryptedValue";
    ConfigurationHolder password = new ConfigurationHolder("password", "pass", oldEncryptedValue, true, "1");
    ConfigurationHolder secureKeyNotChanged = new ConfigurationHolder("secureKeyNotChanged", "pass", oldEncryptedValue, true, "0");
    Map attributes = createPackageRepositoryConfiguration(name, pluginId, repoId, url, username, password, secureKeyNotChanged);
    PackageRepository packageRepository = new PackageRepository();
    Packages packages = new Packages();
    packageRepository.setPackages(packages);
    packageRepository.setConfigAttributes(attributes);
    assertThat(packageRepository.getName(), is(name));
    assertThat(packageRepository.getId(), is(repoId));
    assertThat(packageRepository.getPluginConfiguration().getId(), is(pluginId));
    assertThat(packageRepository.getConfiguration().get(0).getConfigurationKey().getName(), is(url.name));
    assertThat(packageRepository.getConfiguration().get(0).getConfigurationValue().getValue(), is(url.value));
    assertThat(packageRepository.getConfiguration().get(1).getConfigurationKey().getName(), is(username.name));
    assertThat(packageRepository.getConfiguration().get(1).getConfigurationValue().getValue(), is(username.value));
    assertThat(packageRepository.getConfiguration().get(2).getConfigurationKey().getName(), is(password.name));
    assertThat(packageRepository.getConfiguration().get(2).getEncryptedValue(), is(new GoCipher().encrypt(password.value)));
    assertThat(packageRepository.getConfiguration().get(2).getConfigurationValue(), is(nullValue()));
    assertThat(packageRepository.getConfiguration().get(3).getConfigurationKey().getName(), is(secureKeyNotChanged.name));
    assertThat(packageRepository.getConfiguration().get(3).getEncryptedValue(), is(oldEncryptedValue));
    assertThat(packageRepository.getConfiguration().get(3).getConfigurationValue(), is(nullValue()));
    assertSame(packageRepository.getPackages(), packages);
}
Also used : GoCipher(com.thoughtworks.go.security.GoCipher) ConfigurationHolder(com.thoughtworks.go.config.helper.ConfigurationHolder) PackageConfiguration(com.thoughtworks.go.plugin.access.packagematerial.PackageConfiguration) HashMap(java.util.HashMap) Map(java.util.Map) PackageConfigurations(com.thoughtworks.go.plugin.access.packagematerial.PackageConfigurations) Test(org.junit.Test)

Example 85 with GoCipher

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

the class PackageRepositoryTest method shouldMakeConfigurationSecureBasedOnMetadata.

@Test
public void shouldMakeConfigurationSecureBasedOnMetadata() throws Exception {
    GoCipher goCipher = new GoCipher();
    /*secure property is set based on metadata*/
    ConfigurationProperty secureProperty = new ConfigurationProperty(new ConfigurationKey("key1"), new ConfigurationValue("value1"), null, goCipher);
    ConfigurationProperty nonSecureProperty = new ConfigurationProperty(new ConfigurationKey("key2"), new ConfigurationValue("value2"), null, goCipher);
    PackageDefinition packageDefinition = new PackageDefinition("go", "name", new Configuration(secureProperty, nonSecureProperty));
    //meta data of package
    PackageConfigurations packageConfigurations = new PackageConfigurations();
    packageConfigurations.addConfiguration(new PackageConfiguration("key1").with(SECURE, true));
    packageConfigurations.addConfiguration(new PackageConfiguration("key2").with(SECURE, false));
    PackageMetadataStore.getInstance().addMetadataFor("plugin-id", packageConfigurations);
    /*secure property is set based on metadata*/
    ConfigurationProperty secureRepoProperty = new ConfigurationProperty(new ConfigurationKey("key1"), new ConfigurationValue("value1"), null, goCipher);
    ConfigurationProperty nonSecureRepoProperty = new ConfigurationProperty(new ConfigurationKey("key2"), new ConfigurationValue("value2"), null, goCipher);
    PackageRepository packageRepository = createPackageRepository("plugin-id", "version", "id", "name", new Configuration(secureRepoProperty, nonSecureRepoProperty), new Packages(packageDefinition));
    //meta data of repo
    PackageConfigurations repositoryConfiguration = new PackageConfigurations();
    repositoryConfiguration.addConfiguration(new PackageConfiguration("key1").with(SECURE, true));
    repositoryConfiguration.addConfiguration(new PackageConfiguration("key2").with(SECURE, false));
    RepositoryMetadataStore.getInstance().addMetadataFor("plugin-id", repositoryConfiguration);
    packageRepository.applyPackagePluginMetadata();
    //assert package properties
    assertThat(secureProperty.isSecure(), is(true));
    assertThat(secureProperty.getEncryptedConfigurationValue(), is(notNullValue()));
    assertThat(secureProperty.getEncryptedValue(), is(goCipher.encrypt("value1")));
    assertThat(nonSecureProperty.isSecure(), is(false));
    assertThat(nonSecureProperty.getValue(), is("value2"));
    //assert repository properties
    assertThat(secureRepoProperty.isSecure(), is(true));
    assertThat(secureRepoProperty.getEncryptedConfigurationValue(), is(notNullValue()));
    assertThat(secureRepoProperty.getEncryptedValue(), is(goCipher.encrypt("value1")));
    assertThat(nonSecureRepoProperty.isSecure(), is(false));
    assertThat(nonSecureRepoProperty.getValue(), is("value2"));
}
Also used : ConfigurationProperty(com.thoughtworks.go.domain.config.ConfigurationProperty) ConfigurationValue(com.thoughtworks.go.domain.config.ConfigurationValue) EncryptedConfigurationValue(com.thoughtworks.go.domain.config.EncryptedConfigurationValue) GoCipher(com.thoughtworks.go.security.GoCipher) ConfigurationKey(com.thoughtworks.go.domain.config.ConfigurationKey) Configuration(com.thoughtworks.go.domain.config.Configuration) PluginConfiguration(com.thoughtworks.go.domain.config.PluginConfiguration) PackageConfiguration(com.thoughtworks.go.plugin.access.packagematerial.PackageConfiguration) PackageConfiguration(com.thoughtworks.go.plugin.access.packagematerial.PackageConfiguration) PackageConfigurations(com.thoughtworks.go.plugin.access.packagematerial.PackageConfigurations) 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