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)));
}
}
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;
}
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;
}
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);
}
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);
}
Aggregations