use of com.thoughtworks.go.security.GoCipher in project gocd by gocd.
the class SCMTest method shouldNotUpdateSecurePropertyWhenPluginIsMissing.
@Test
void shouldNotUpdateSecurePropertyWhenPluginIsMissing() {
GoCipher goCipher = new GoCipher();
ConfigurationProperty secureProperty = new ConfigurationProperty(new ConfigurationKey("key1"), null, new EncryptedConfigurationValue("value"), goCipher);
ConfigurationProperty nonSecureProperty = new ConfigurationProperty(new ConfigurationKey("key2"), new ConfigurationValue("value1"), null, goCipher);
SCM scm = SCMMother.create("scm-id", "scm-name", "plugin-id", "version", new Configuration(secureProperty, nonSecureProperty));
scm.applyPluginMetadata();
assertThat(secureProperty.getEncryptedConfigurationValue()).isNotNull();
assertThat(secureProperty.getConfigurationValue()).isNull();
assertThat(nonSecureProperty.getConfigurationValue()).isNotNull();
assertThat(nonSecureProperty.getEncryptedConfigurationValue()).isNull();
}
use of com.thoughtworks.go.security.GoCipher in project gocd by gocd.
the class ConfigurationPropertyTest method shouldSetConfigAttributesForSecurePropertyWhenUserChangesIt.
@Test
void shouldSetConfigAttributesForSecurePropertyWhenUserChangesIt() throws Exception {
ConfigurationProperty configurationProperty = new ConfigurationProperty();
HashMap attributes = new HashMap();
HashMap keyMap = new HashMap();
final String secureKey = "fooKey";
keyMap.put("name", secureKey);
attributes.put(ConfigurationProperty.CONFIGURATION_KEY, keyMap);
HashMap valueMap = new HashMap();
valueMap.put("value", "fooValue");
attributes.put(ConfigurationProperty.CONFIGURATION_VALUE, valueMap);
attributes.put(ConfigurationProperty.IS_CHANGED, "0");
configurationProperty.setConfigAttributes(attributes, new SecureKeyInfoProvider() {
@Override
public boolean isSecure(String key) {
return secureKey.equals(key);
}
});
String encryptedValue = new GoCipher().encrypt("fooValue");
assertThat(configurationProperty.getConfigurationKey().getName()).isEqualTo(secureKey);
assertThat(configurationProperty.getConfigurationValue()).isNull();
assertThat(configurationProperty.getEncryptedValue()).isEqualTo(encryptedValue);
}
use of com.thoughtworks.go.security.GoCipher in project gocd by gocd.
the class ConfigurationPropertyTest method shouldGetEncryptValueWhenConstructedAsSecure.
@Test
void shouldGetEncryptValueWhenConstructedAsSecure() throws CryptoException {
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()).isTrue();
assertThat(property.getEncryptedValue()).isEqualTo(encryptedText);
assertThat(property.getConfigurationKey().getName()).isEqualTo("secureKey");
assertThat(property.getConfigurationValue()).isNull();
}
use of com.thoughtworks.go.security.GoCipher in project gocd by gocd.
the class ConfigurationPropertyTest method shouldFailValidationIfAPropertyDoesNotHaveValue.
@Test
void shouldFailValidationIfAPropertyDoesNotHaveValue() {
ConfigurationProperty property = new ConfigurationProperty(new ConfigurationKey("secureKey"), null, new EncryptedConfigurationValue("invalid-encrypted-value"), new GoCipher());
property.validate(ConfigSaveValidationContext.forChain(property));
assertThat(property.errors().isEmpty()).isFalse();
assertThat(property.errors().getAllOn(ConfigurationProperty.ENCRYPTED_VALUE).contains("Encrypted value for property with key 'secureKey' is invalid. This usually happens when the cipher text is modified to have an invalid value.")).isTrue();
}
use of com.thoughtworks.go.security.GoCipher in project gocd by gocd.
the class SCMConfigXmlWriterTest method getConfigurationProperty.
private ConfigurationProperty getConfigurationProperty(String key, boolean isSecure, String value) {
ConfigurationProperty property = new ConfigurationProperty(new ConfigurationKey(key), new ConfigurationValue(value), null, new GoCipher());
property.handleSecureValueConfiguration(isSecure);
return property;
}
Aggregations