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