Search in sources :

Example 76 with GoCipher

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

the class SCMTest method shouldGetConfigAsMap.

@Test
public void shouldGetConfigAsMap() throws Exception {
    PluginConfiguration pluginConfiguration = new PluginConfiguration("test-plugin-id", "13.4");
    GoCipher cipher = new GoCipher();
    List<String> keys = Arrays.asList("Avengers 1", "Avengers 2", "Avengers 3", "Avengers 4");
    List<String> values = Arrays.asList("Iron man", "Hulk", "Thor", "Captain America");
    Configuration configuration = new Configuration(new ConfigurationProperty(new ConfigurationKey(keys.get(0)), new ConfigurationValue(values.get(0))), new ConfigurationProperty(new ConfigurationKey(keys.get(1)), new ConfigurationValue(values.get(1))), new ConfigurationProperty(new ConfigurationKey(keys.get(2)), new ConfigurationValue(values.get(2))), new ConfigurationProperty(new ConfigurationKey(keys.get(3)), new ConfigurationValue(values.get(3)), new EncryptedConfigurationValue(cipher.encrypt(values.get(3))), cipher));
    SCM scm = new SCM("scm-id", pluginConfiguration, configuration);
    Map<String, Map<String, String>> configMap = scm.getConfigAsMap();
    assertThat(configMap.keySet().size(), is(keys.size()));
    assertThat(configMap.values().size(), is(values.size()));
    assertThat(configMap.keySet().containsAll(keys), is(true));
    for (int i = 0; i < keys.size(); i++) {
        assertThat(configMap.get(keys.get(i)).get(SCM.VALUE_KEY), is(values.get(i)));
    }
}
Also used : ConfigurationProperty(com.thoughtworks.go.domain.config.ConfigurationProperty) GoCipher(com.thoughtworks.go.security.GoCipher) Configuration(com.thoughtworks.go.domain.config.Configuration) PluginConfiguration(com.thoughtworks.go.domain.config.PluginConfiguration) SCMConfiguration(com.thoughtworks.go.plugin.access.scm.SCMConfiguration) EncryptedConfigurationValue(com.thoughtworks.go.domain.config.EncryptedConfigurationValue) ConfigurationValue(com.thoughtworks.go.domain.config.ConfigurationValue) EncryptedConfigurationValue(com.thoughtworks.go.domain.config.EncryptedConfigurationValue) ConfigurationKey(com.thoughtworks.go.domain.config.ConfigurationKey) PluginConfiguration(com.thoughtworks.go.domain.config.PluginConfiguration) Test(org.junit.Test)

Example 77 with GoCipher

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

the class EnvironmentVariablesConfigMother method environmentVariables.

public static EnvironmentVariablesConfig environmentVariables() {
    EnvironmentVariablesConfig variables = new EnvironmentVariablesConfig();
    GoCipher goCipher = new GoCipher();
    variables.add(new EnvironmentVariableConfig(goCipher, "MULTIPLE_LINES", "multiplelines", true));
    variables.add(new EnvironmentVariableConfig(goCipher, "COMPLEX", "This has very <complex> data", false));
    return variables;
}
Also used : EnvironmentVariableConfig(com.thoughtworks.go.config.EnvironmentVariableConfig) GoCipher(com.thoughtworks.go.security.GoCipher) EnvironmentVariablesConfig(com.thoughtworks.go.config.EnvironmentVariablesConfig)

Example 78 with GoCipher

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

the class GoConfigMother method configWithPackageRepo.

public static CruiseConfig configWithPackageRepo(String... ids) throws Exception {
    final CruiseConfig config = new BasicCruiseConfig();
    PackageConfigurations configuration = new PackageConfigurations();
    configuration.addConfiguration(new PackageConfiguration("key1"));
    configuration.addConfiguration(new PackageConfiguration("key2").with(PackageConfiguration.SECURE, true));
    RepositoryMetadataStore.getInstance().addMetadataFor("plugin-1", configuration);
    for (String id : ids) {
        PackageRepository packageRepository = new PackageRepository();
        packageRepository.setId(id);
        packageRepository.setName("name" + id);
        packageRepository.setPluginConfiguration(new PluginConfiguration("plugin-1", "1.0.0"));
        packageRepository.setPackages(new Packages(PackageDefinitionMother.create(id + "-pkg-1", packageRepository), PackageDefinitionMother.create(id + "-pkg-2", packageRepository)));
        GoCipher cipher = new GoCipher();
        ConfigurationProperty p1 = new ConfigurationProperty(new ConfigurationKey("key1"), new ConfigurationValue("value1"));
        ConfigurationProperty p2 = new ConfigurationProperty(new ConfigurationKey("key2"), null, new EncryptedConfigurationValue(cipher.encrypt("value2")), cipher);
        packageRepository.setConfiguration(new Configuration(p1, p2));
        config.setPackageRepositories(new PackageRepositories(packageRepository));
    }
    return config;
}
Also used : GoCipher(com.thoughtworks.go.security.GoCipher) PackageConfiguration(com.thoughtworks.go.plugin.access.packagematerial.PackageConfiguration) PackageRepositories(com.thoughtworks.go.domain.packagerepository.PackageRepositories) PackageRepository(com.thoughtworks.go.domain.packagerepository.PackageRepository) Packages(com.thoughtworks.go.domain.packagerepository.Packages) PackageConfiguration(com.thoughtworks.go.plugin.access.packagematerial.PackageConfiguration) PackageConfigurations(com.thoughtworks.go.plugin.access.packagematerial.PackageConfigurations)

Example 79 with GoCipher

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

the class EnvironmentVariableConfigTest method shouldRetainEncryptedVariableWhenNotEdited.

@Test
public void shouldRetainEncryptedVariableWhenNotEdited() throws InvalidCipherTextException {
    GoCipher mockGoCipher = mock(GoCipher.class);
    String plainText = "password";
    String cipherText = "encrypted";
    when(mockGoCipher.encrypt(plainText)).thenReturn(cipherText);
    when(mockGoCipher.decrypt(cipherText)).thenReturn(plainText);
    when(mockGoCipher.encrypt(cipherText)).thenReturn("SHOULD NOT DO THIS");
    EnvironmentVariableConfig environmentVariableConfig = new EnvironmentVariableConfig(mockGoCipher);
    HashMap firstSubmit = getAttributeMap(plainText, "true", "true");
    environmentVariableConfig.setConfigAttributes(firstSubmit);
    HashMap secondSubmit = getAttributeMap(cipherText, "true", "false");
    environmentVariableConfig.setConfigAttributes(secondSubmit);
    assertThat(environmentVariableConfig.getEncryptedValue(), is(cipherText));
    assertThat(environmentVariableConfig.getName(), is("foo"));
    assertThat(environmentVariableConfig.isSecure(), is(true));
    verify(mockGoCipher, never()).encrypt(cipherText);
}
Also used : GoCipher(com.thoughtworks.go.security.GoCipher) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 80 with GoCipher

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

the class EnvironmentVariableConfigTest method shouldGetPlainTextValueFromAnEncryptedValue.

@Test
public void shouldGetPlainTextValueFromAnEncryptedValue() throws InvalidCipherTextException {
    GoCipher mockGoCipher = mock(GoCipher.class);
    String plainText = "password";
    String cipherText = "encrypted";
    when(mockGoCipher.encrypt(plainText)).thenReturn(cipherText);
    when(mockGoCipher.decrypt(cipherText)).thenReturn(plainText);
    EnvironmentVariableConfig environmentVariableConfig = new EnvironmentVariableConfig(mockGoCipher);
    HashMap attrs = getAttributeMap(plainText, "true", "true");
    environmentVariableConfig.setConfigAttributes(attrs);
    assertThat(environmentVariableConfig.getValue(), is(plainText));
    verify(mockGoCipher).decrypt(cipherText);
}
Also used : GoCipher(com.thoughtworks.go.security.GoCipher) HashMap(java.util.HashMap) Test(org.junit.Test)

Aggregations

GoCipher (com.thoughtworks.go.security.GoCipher)149 Test (org.junit.Test)128 UrlArgument (com.thoughtworks.go.util.command.UrlArgument)36 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)16 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)15 HashMap (java.util.HashMap)15 ConfigurationProperty (com.thoughtworks.go.domain.config.ConfigurationProperty)11 EnvironmentVariableConfig (com.thoughtworks.go.config.EnvironmentVariableConfig)10 ConfigurationKey (com.thoughtworks.go.domain.config.ConfigurationKey)10 ConfigurationValue (com.thoughtworks.go.domain.config.ConfigurationValue)10 EncryptedConfigurationValue (com.thoughtworks.go.domain.config.EncryptedConfigurationValue)10 Configuration (com.thoughtworks.go.domain.config.Configuration)9 ConfigSaveValidationContext (com.thoughtworks.go.config.ConfigSaveValidationContext)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 PackageConfigurations (com.thoughtworks.go.plugin.access.packagematerial.PackageConfigurations)6 File (java.io.File)6