Search in sources :

Example 31 with GoCipher

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();
}
Also used : GoCipher(com.thoughtworks.go.security.GoCipher) SCMConfiguration(com.thoughtworks.go.plugin.access.scm.SCMConfiguration) Test(org.junit.jupiter.api.Test)

Example 32 with GoCipher

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);
}
Also used : GoCipher(com.thoughtworks.go.security.GoCipher) HashMap(java.util.HashMap) Test(org.junit.jupiter.api.Test)

Example 33 with GoCipher

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();
}
Also used : GoCipher(com.thoughtworks.go.security.GoCipher) Test(org.junit.jupiter.api.Test)

Example 34 with GoCipher

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();
}
Also used : GoCipher(com.thoughtworks.go.security.GoCipher) Test(org.junit.jupiter.api.Test)

Example 35 with GoCipher

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;
}
Also used : GoCipher(com.thoughtworks.go.security.GoCipher)

Aggregations

GoCipher (com.thoughtworks.go.security.GoCipher)196 Test (org.junit.jupiter.api.Test)117 Test (org.junit.Test)57 UrlArgument (com.thoughtworks.go.util.command.UrlArgument)30 ArrayList (java.util.ArrayList)23 PluginConfiguration (com.thoughtworks.go.plugin.domain.common.PluginConfiguration)22 ConfigurationProperty (com.thoughtworks.go.domain.config.ConfigurationProperty)21 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)19 HashMap (java.util.HashMap)19 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)17 ConfigurationKey (com.thoughtworks.go.domain.config.ConfigurationKey)13 Metadata (com.thoughtworks.go.plugin.domain.common.Metadata)13 PluggableInstanceSettings (com.thoughtworks.go.plugin.domain.common.PluggableInstanceSettings)13 ConfigurationValue (com.thoughtworks.go.domain.config.ConfigurationValue)11 EnvironmentVariableConfig (com.thoughtworks.go.config.EnvironmentVariableConfig)10 SvnMaterialConfig (com.thoughtworks.go.config.materials.svn.SvnMaterialConfig)10 File (java.io.File)9 ConfigSaveValidationContext (com.thoughtworks.go.config.ConfigSaveValidationContext)8 TfsMaterialConfig (com.thoughtworks.go.config.materials.tfs.TfsMaterialConfig)8 Configuration (com.thoughtworks.go.domain.config.Configuration)8