Search in sources :

Example 11 with EncryptedConfigurationValue

use of com.thoughtworks.go.domain.config.EncryptedConfigurationValue in project gocd by gocd.

the class PackageRepositoryTest method shouldClearConfigurationsWhichAreEmptyAndNoErrors.

@Test
public void shouldClearConfigurationsWhichAreEmptyAndNoErrors() throws Exception {
    PackageRepository packageRepository = new PackageRepository();
    packageRepository.getConfiguration().add(new ConfigurationProperty(new ConfigurationKey("name-one"), new ConfigurationValue()));
    packageRepository.getConfiguration().add(new ConfigurationProperty(new ConfigurationKey("name-two"), new EncryptedConfigurationValue()));
    packageRepository.getConfiguration().add(new ConfigurationProperty(new ConfigurationKey("name-three"), null, new EncryptedConfigurationValue(), null));
    ConfigurationProperty configurationProperty = new ConfigurationProperty(new ConfigurationKey("name-four"), null, new EncryptedConfigurationValue(), null);
    configurationProperty.addErrorAgainstConfigurationValue("error");
    packageRepository.getConfiguration().add(configurationProperty);
    packageRepository.clearEmptyConfigurations();
    assertThat(packageRepository.getConfiguration().size(), is(1));
    assertThat(packageRepository.getConfiguration().get(0).getConfigurationKey().getName(), is("name-four"));
}
Also used : ConfigurationProperty(com.thoughtworks.go.domain.config.ConfigurationProperty) EncryptedConfigurationValue(com.thoughtworks.go.domain.config.EncryptedConfigurationValue) ConfigurationValue(com.thoughtworks.go.domain.config.ConfigurationValue) EncryptedConfigurationValue(com.thoughtworks.go.domain.config.EncryptedConfigurationValue) ConfigurationKey(com.thoughtworks.go.domain.config.ConfigurationKey) Test(org.junit.Test)

Example 12 with EncryptedConfigurationValue

use of com.thoughtworks.go.domain.config.EncryptedConfigurationValue in project gocd by gocd.

the class ConfigurationPropertyBuilder method create.

public ConfigurationProperty create(String key, String value, String encryptedValue, Boolean isSecure) {
    ConfigurationProperty configurationProperty = new ConfigurationProperty();
    configurationProperty.setConfigurationKey(new ConfigurationKey(key));
    if (isNotBlank(value) && isNotBlank(encryptedValue)) {
        configurationProperty.addError("configurationValue", "You may only specify `value` or `encrypted_value`, not both!");
        configurationProperty.addError("encryptedValue", "You may only specify `value` or `encrypted_value`, not both!");
        configurationProperty.setConfigurationValue(new ConfigurationValue(value));
        configurationProperty.setEncryptedValue(new EncryptedConfigurationValue(encryptedValue));
        return configurationProperty;
    }
    if (isSecure) {
        if (isNotBlank(encryptedValue)) {
            configurationProperty.setEncryptedValue(new EncryptedConfigurationValue(encryptedValue));
        }
        if (isNotBlank(value)) {
            configurationProperty.setEncryptedValue(new EncryptedConfigurationValue(encrypt(value)));
        }
    } else {
        if (isNotBlank(encryptedValue)) {
            configurationProperty.addError("encryptedValue", "encrypted_value cannot be specified to a unsecured property.");
            configurationProperty.setEncryptedValue(new EncryptedConfigurationValue(encryptedValue));
        }
        if (value != null) {
            configurationProperty.setConfigurationValue(new ConfigurationValue(value));
        }
    }
    if (isNotBlank(configurationProperty.getEncryptedValue())) {
        configurationProperty.setEncryptedValue(new EncryptedConfigurationValue(configurationProperty.getEncryptedValue()));
    }
    return configurationProperty;
}
Also used : ConfigurationProperty(com.thoughtworks.go.domain.config.ConfigurationProperty) EncryptedConfigurationValue(com.thoughtworks.go.domain.config.EncryptedConfigurationValue) ConfigurationValue(com.thoughtworks.go.domain.config.ConfigurationValue) EncryptedConfigurationValue(com.thoughtworks.go.domain.config.EncryptedConfigurationValue) ConfigurationKey(com.thoughtworks.go.domain.config.ConfigurationKey)

Example 13 with EncryptedConfigurationValue

use of com.thoughtworks.go.domain.config.EncryptedConfigurationValue in project gocd by gocd.

the class FetchPluggableArtifactTaskTest method encryptSecureProperties_shouldEncryptSecureProperties.

@Test
void encryptSecureProperties_shouldEncryptSecureProperties() throws CryptoException {
    ArrayList<PluginConfiguration> pluginConfigurations = new ArrayList<>();
    pluginConfigurations.add(new PluginConfiguration("secure_property1", new Metadata(true, true)));
    pluginConfigurations.add(new PluginConfiguration("secure_property2", new Metadata(true, true)));
    pluginConfigurations.add(new PluginConfiguration("plain", new Metadata(true, false)));
    when(artifactPluginInfo.getFetchArtifactSettings()).thenReturn(new PluggableInstanceSettings(pluginConfigurations));
    PipelineConfig pipelineConfig = PipelineConfigMother.createPipelineConfig("pipeline", "stage", "job");
    PluggableArtifactConfig pluggableArtifactConfig = new PluggableArtifactConfig("s3", "aws");
    pipelineConfig.getStage("stage").jobConfigByConfigName("job").artifactTypeConfigs().add(pluggableArtifactConfig);
    BasicCruiseConfig cruiseConfig = GoConfigMother.defaultCruiseConfig();
    cruiseConfig.addPipelineWithoutValidation("foo", pipelineConfig);
    cruiseConfig.getArtifactStores().add(new ArtifactStore("aws", artifactPluginInfo.getDescriptor().id()));
    FetchPluggableArtifactTask task = new FetchPluggableArtifactTask(new CaseInsensitiveString("pipeline"), new CaseInsensitiveString("stage"), new CaseInsensitiveString("job"), "s3");
    ArrayList<ConfigurationProperty> configurationProperties = new ArrayList<>();
    configurationProperties.add(new ConfigurationProperty(new ConfigurationKey("plain"), new ConfigurationValue("plain")));
    configurationProperties.add(new ConfigurationProperty(new ConfigurationKey("secure_property1"), new ConfigurationValue("password")));
    configurationProperties.add(new ConfigurationProperty(new ConfigurationKey("secure_property2"), new EncryptedConfigurationValue(new GoCipher().encrypt("secret"))));
    ArrayList<ConfigurationProperty> expectedConfigurationProperties = new ArrayList<>();
    expectedConfigurationProperties.add(new ConfigurationProperty(new ConfigurationKey("plain"), new ConfigurationValue("plain")));
    expectedConfigurationProperties.add(new ConfigurationProperty(new ConfigurationKey("secure_property1"), new EncryptedConfigurationValue(new GoCipher().encrypt("password"))));
    expectedConfigurationProperties.add(new ConfigurationProperty(new ConfigurationKey("secure_property2"), new EncryptedConfigurationValue(new GoCipher().encrypt("secret"))));
    task.addConfigurations(configurationProperties);
    task.encryptSecureProperties(cruiseConfig, pipelineConfig, task);
    assertThat(task.getConfiguration().size()).isEqualTo(3);
    assertThat(task.getConfiguration()).isEqualTo(expectedConfigurationProperties);
}
Also used : ConfigurationProperty(com.thoughtworks.go.domain.config.ConfigurationProperty) GoCipher(com.thoughtworks.go.security.GoCipher) ArrayList(java.util.ArrayList) Metadata(com.thoughtworks.go.plugin.domain.common.Metadata) EncryptedConfigurationValue(com.thoughtworks.go.domain.config.EncryptedConfigurationValue) ConfigurationValue(com.thoughtworks.go.domain.config.ConfigurationValue) EncryptedConfigurationValue(com.thoughtworks.go.domain.config.EncryptedConfigurationValue) PluggableInstanceSettings(com.thoughtworks.go.plugin.domain.common.PluggableInstanceSettings) ConfigurationKey(com.thoughtworks.go.domain.config.ConfigurationKey) PluginConfiguration(com.thoughtworks.go.plugin.domain.common.PluginConfiguration) Test(org.junit.jupiter.api.Test)

Example 14 with EncryptedConfigurationValue

use of com.thoughtworks.go.domain.config.EncryptedConfigurationValue in project gocd by gocd.

the class FetchPluggableArtifactTaskTest method encryptSecureProperties_shouldEncryptSecurePropertiesIfTheConfigIdentifersAreParams.

@Test
void encryptSecureProperties_shouldEncryptSecurePropertiesIfTheConfigIdentifersAreParams() throws CryptoException {
    ArrayList<PluginConfiguration> pluginConfigurations = new ArrayList<>();
    pluginConfigurations.add(new PluginConfiguration("secure_property1", new Metadata(true, true)));
    pluginConfigurations.add(new PluginConfiguration("secure_property2", new Metadata(true, true)));
    pluginConfigurations.add(new PluginConfiguration("plain", new Metadata(true, false)));
    when(artifactPluginInfo.getFetchArtifactSettings()).thenReturn(new PluggableInstanceSettings(pluginConfigurations));
    PipelineConfig pipelineConfig = PipelineConfigMother.createPipelineConfig("pipeline", "stage", "job");
    PluggableArtifactConfig pluggableArtifactConfig = new PluggableArtifactConfig("s3", "aws");
    pipelineConfig.getStage("stage").jobConfigByConfigName("job").artifactTypeConfigs().add(pluggableArtifactConfig);
    BasicCruiseConfig cruiseConfig = GoConfigMother.defaultCruiseConfig();
    cruiseConfig.addPipelineWithoutValidation("foo", pipelineConfig);
    cruiseConfig.getArtifactStores().add(new ArtifactStore("aws", artifactPluginInfo.getDescriptor().id()));
    FetchPluggableArtifactTask task = new FetchPluggableArtifactTask(new CaseInsensitiveString("#{pipeline}"), new CaseInsensitiveString("#{stage}"), new CaseInsensitiveString("#{job}"), "#{artifactId}");
    FetchPluggableArtifactTask preprocessedTask = new FetchPluggableArtifactTask(new CaseInsensitiveString("pipeline"), new CaseInsensitiveString("stage"), new CaseInsensitiveString("job"), "s3");
    ArrayList<ConfigurationProperty> configurationProperties = new ArrayList<>();
    configurationProperties.add(new ConfigurationProperty(new ConfigurationKey("plain"), new ConfigurationValue("plain")));
    configurationProperties.add(new ConfigurationProperty(new ConfigurationKey("secure_property1"), new ConfigurationValue("password")));
    configurationProperties.add(new ConfigurationProperty(new ConfigurationKey("secure_property2"), new EncryptedConfigurationValue(new GoCipher().encrypt("secret"))));
    ArrayList<ConfigurationProperty> expectedConfigurationProperties = new ArrayList<>();
    expectedConfigurationProperties.add(new ConfigurationProperty(new ConfigurationKey("plain"), new ConfigurationValue("plain")));
    expectedConfigurationProperties.add(new ConfigurationProperty(new ConfigurationKey("secure_property1"), new EncryptedConfigurationValue(new GoCipher().encrypt("password"))));
    expectedConfigurationProperties.add(new ConfigurationProperty(new ConfigurationKey("secure_property2"), new EncryptedConfigurationValue(new GoCipher().encrypt("secret"))));
    task.addConfigurations(configurationProperties);
    PipelineConfig pipelineWhichHasTheFetchTask = PipelineConfigMother.createPipelineConfigWithStage("p2", "anotherStage");
    pipelineWhichHasTheFetchTask.first().getJobs().first().addTask(task);
    pipelineWhichHasTheFetchTask.setParams(new ParamsConfig(new ParamConfig("pipeline", "pipeline"), new ParamConfig("stage", "stage"), new ParamConfig("job", "job"), new ParamConfig("artifactId", "s3")));
    task.encryptSecureProperties(cruiseConfig, pipelineWhichHasTheFetchTask, preprocessedTask);
    assertThat(task.getConfiguration().size()).isEqualTo(3);
    assertThat(task.getConfiguration()).isEqualTo(expectedConfigurationProperties);
}
Also used : ConfigurationProperty(com.thoughtworks.go.domain.config.ConfigurationProperty) GoCipher(com.thoughtworks.go.security.GoCipher) ArrayList(java.util.ArrayList) Metadata(com.thoughtworks.go.plugin.domain.common.Metadata) EncryptedConfigurationValue(com.thoughtworks.go.domain.config.EncryptedConfigurationValue) ConfigurationValue(com.thoughtworks.go.domain.config.ConfigurationValue) EncryptedConfigurationValue(com.thoughtworks.go.domain.config.EncryptedConfigurationValue) PluggableInstanceSettings(com.thoughtworks.go.plugin.domain.common.PluggableInstanceSettings) ConfigurationKey(com.thoughtworks.go.domain.config.ConfigurationKey) PluginConfiguration(com.thoughtworks.go.plugin.domain.common.PluginConfiguration) Test(org.junit.jupiter.api.Test)

Example 15 with EncryptedConfigurationValue

use of com.thoughtworks.go.domain.config.EncryptedConfigurationValue in project gocd by gocd.

the class SecurityAuthConfigTest method addConfigurations_shouldAddConfigurationsWithEncryptedValue.

@Test
public void addConfigurations_shouldAddConfigurationsWithEncryptedValue() throws Exception {
    ConfigurationProperty property = new ConfigurationProperty(new ConfigurationKey("username"), new EncryptedConfigurationValue("some_name"));
    SecurityAuthConfig authConfig = new SecurityAuthConfig("id", "plugin_id");
    authConfig.addConfigurations(Arrays.asList(property));
    assertThat(authConfig.size(), is(1));
    assertThat(authConfig, contains(new ConfigurationProperty(new ConfigurationKey("username"), new EncryptedConfigurationValue("some_name"))));
}
Also used : ConfigurationProperty(com.thoughtworks.go.domain.config.ConfigurationProperty) EncryptedConfigurationValue(com.thoughtworks.go.domain.config.EncryptedConfigurationValue) ConfigurationKey(com.thoughtworks.go.domain.config.ConfigurationKey) Test(org.junit.jupiter.api.Test)

Aggregations

EncryptedConfigurationValue (com.thoughtworks.go.domain.config.EncryptedConfigurationValue)17 ConfigurationKey (com.thoughtworks.go.domain.config.ConfigurationKey)15 ConfigurationProperty (com.thoughtworks.go.domain.config.ConfigurationProperty)15 ConfigurationValue (com.thoughtworks.go.domain.config.ConfigurationValue)11 Test (org.junit.jupiter.api.Test)11 GoCipher (com.thoughtworks.go.security.GoCipher)7 ArrayList (java.util.ArrayList)5 Metadata (com.thoughtworks.go.plugin.domain.common.Metadata)4 PluggableInstanceSettings (com.thoughtworks.go.plugin.domain.common.PluggableInstanceSettings)4 PluginConfiguration (com.thoughtworks.go.plugin.domain.common.PluginConfiguration)4 ConfigRepoPluginInfo (com.thoughtworks.go.plugin.domain.configrepo.ConfigRepoPluginInfo)4 ElasticAgentPluginInfo (com.thoughtworks.go.plugin.domain.elastic.ElasticAgentPluginInfo)3 Map (java.util.Map)3 Test (org.junit.Test)3 Configuration (com.thoughtworks.go.domain.config.Configuration)2 PluginSettingsConfiguration (com.thoughtworks.go.plugin.access.common.settings.PluginSettingsConfiguration)2 PluginInfo (com.thoughtworks.go.plugin.domain.common.PluginInfo)2 Capabilities (com.thoughtworks.go.plugin.domain.configrepo.Capabilities)2 PluginConfiguration (com.thoughtworks.go.domain.config.PluginConfiguration)1 AuthorizationPluginInfo (com.thoughtworks.go.plugin.domain.authorization.AuthorizationPluginInfo)1