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