use of com.thoughtworks.go.security.GoCipher in project gocd by gocd.
the class ConfigurationPropertyTest method shouldGetEncryptValueWhenConstructedAsSecure.
@Test
public void shouldGetEncryptValueWhenConstructedAsSecure() throws InvalidCipherTextException {
GoCipher goCipher = mock(GoCipher.class);
String encryptedText = "encryptedValue";
when(goCipher.encrypt("secureValue")).thenReturn(encryptedText);
ConfigurationProperty property = new ConfigurationProperty(new ConfigurationKey("secureKey"), new ConfigurationValue("secureValue"), new EncryptedConfigurationValue("old-encrypted-text"), goCipher);
property.handleSecureValueConfiguration(true);
assertThat(property.isSecure(), is(true));
assertThat(property.getEncryptedValue(), is(encryptedText));
assertThat(property.getConfigurationKey().getName(), is("secureKey"));
assertThat(property.getConfigurationValue(), is(nullValue()));
}
use of com.thoughtworks.go.security.GoCipher in project gocd by gocd.
the class TfsMaterialConfigUpdateTest method shouldDecryptTfsPassword.
@Test
public void shouldDecryptTfsPassword() throws Exception {
GoCipher mockGoCipher = mock(GoCipher.class);
when(mockGoCipher.decrypt("encrypted")).thenReturn("password");
TfsMaterialConfig materialConfig = new TfsMaterialConfig(mockGoCipher, new UrlArgument("http://10.4.4.101:8080/tfs/Sample"), "loser", "CORPORATE", "secret", "walk_this_path");
ReflectionUtil.setField(materialConfig, "encryptedPassword", "encrypted");
materialConfig.ensureEncrypted();
assertThat(materialConfig.getPassword(), is("password"));
}
use of com.thoughtworks.go.security.GoCipher in project gocd by gocd.
the class TfsMaterialConfigUpdateTest method shouldEncryptTfsPasswordAndMarkPasswordAsNull.
@Test
public void shouldEncryptTfsPasswordAndMarkPasswordAsNull() throws Exception {
GoCipher mockGoCipher = mock(GoCipher.class);
when(mockGoCipher.encrypt("password")).thenReturn("encrypted");
TfsMaterialConfig materialConfig = new TfsMaterialConfig(mockGoCipher, new UrlArgument("http://10.4.4.101:8080/tfs/Sample"), "loser", "CORPORATE", "password", "walk_this_path");
materialConfig.ensureEncrypted();
assertThat(materialConfig.getPassword(), is(nullValue()));
assertThat(materialConfig.getEncryptedPassword(), is("encrypted"));
}
use of com.thoughtworks.go.security.GoCipher in project gocd by gocd.
the class TfsMaterialConfigUpdateTest method shouldErrorOutIfDecryptionFails.
@Test
public void shouldErrorOutIfDecryptionFails() throws InvalidCipherTextException {
GoCipher mockGoCipher = mock(GoCipher.class);
String fakeCipherText = "fake cipher text";
when(mockGoCipher.decrypt(fakeCipherText)).thenThrow(new InvalidCipherTextException("exception"));
TfsMaterialConfig materialConfig = new TfsMaterialConfig(mockGoCipher, new UrlArgument("http://10.4.4.101:8080/tfs/Sample"), "loser", "CORPORATE", "passwd", "walk_this_path");
ReflectionUtil.setField(materialConfig, "encryptedPassword", fakeCipherText);
try {
materialConfig.getPassword();
fail("Should have thrown up");
} catch (Exception e) {
assertThat(e.getMessage(), is("Could not decrypt the password to get the real password"));
}
}
use of com.thoughtworks.go.security.GoCipher in project gocd by gocd.
the class TfsMaterialConfigUpdateTest method shouldValidateWhetherTheEncryptedPasswordIsCorrect.
@Test
public void shouldValidateWhetherTheEncryptedPasswordIsCorrect() {
TfsMaterialConfig materialConfig = new TfsMaterialConfig(new UrlArgument("foo/bar"), "", "encryptedPassword", new GoCipher());
materialConfig.validate(new ConfigSaveValidationContext(null));
assertThat(materialConfig.errors().on("encryptedPassword"), is("Encrypted password value for TFS material with url 'foo/bar' is invalid. This usually happens when the cipher text is modified to have an invalid value."));
}
Aggregations