Search in sources :

Example 41 with ConfigurationValue

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

the class SecurityAuthConfigCreateCommandTest method shouldInvokePluginValidationsBeforeSave.

@Test
public void shouldInvokePluginValidationsBeforeSave() throws Exception {
    ValidationResult validationResult = new ValidationResult();
    validationResult.addError(new ValidationError("key", "error"));
    when(extension.validateAuthConfig(eq("aws"), Matchers.<Map<String, String>>any())).thenReturn(validationResult);
    SecurityAuthConfig newProfile = new SecurityAuthConfig("foo", "aws", new ConfigurationProperty(new ConfigurationKey("key"), new ConfigurationValue("val")));
    PluginProfileCommand command = new SecurityAuthConfigCreateCommand(mock(GoConfigService.class), newProfile, extension, null, new HttpLocalizedOperationResult());
    BasicCruiseConfig cruiseConfig = new BasicCruiseConfig();
    thrown.expect(PluginProfileNotFoundException.class);
    thrown.expectMessage("Security auth config `foo` does not exist.");
    command.isValid(cruiseConfig);
    command.update(cruiseConfig);
    assertThat(newProfile.first().errors().size(), is(1));
    assertThat(newProfile.first().errors().asString(), is("error"));
}
Also used : ConfigurationProperty(com.thoughtworks.go.domain.config.ConfigurationProperty) SecurityAuthConfig(com.thoughtworks.go.config.SecurityAuthConfig) ConfigurationValue(com.thoughtworks.go.domain.config.ConfigurationValue) HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) ConfigurationKey(com.thoughtworks.go.domain.config.ConfigurationKey) BasicCruiseConfig(com.thoughtworks.go.config.BasicCruiseConfig) ValidationError(com.thoughtworks.go.plugin.api.response.validation.ValidationError) ValidationResult(com.thoughtworks.go.plugin.api.response.validation.ValidationResult) GoConfigService(com.thoughtworks.go.server.service.GoConfigService) Test(org.junit.Test)

Example 42 with ConfigurationValue

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

the class PackageDefinitionTest method shouldMakeConfigurationSecureBasedOnMetadata.

@Test
public void shouldMakeConfigurationSecureBasedOnMetadata() throws Exception {
    /*secure property is set based on metadata*/
    ConfigurationProperty secureProperty = new ConfigurationProperty(new ConfigurationKey("key1"), new ConfigurationValue("value1"), null, new GoCipher());
    ConfigurationProperty nonSecureProperty = new ConfigurationProperty(new ConfigurationKey("key2"), new ConfigurationValue("value2"), null, new GoCipher());
    PackageDefinition packageDefinition = new PackageDefinition("go", "name", new Configuration(secureProperty, nonSecureProperty));
    PackageRepository packageRepository = new PackageRepository();
    packageRepository.setPluginConfiguration(new PluginConfiguration("plugin-id", "1.0"));
    packageDefinition.setRepository(packageRepository);
    PackageConfigurations packageConfigurations = new PackageConfigurations();
    packageConfigurations.addConfiguration(new PackageConfiguration("key1").with(PackageConfiguration.SECURE, true));
    packageConfigurations.addConfiguration(new PackageConfiguration("key2").with(PackageConfiguration.SECURE, false));
    PackageMetadataStore.getInstance().addMetadataFor("plugin-id", packageConfigurations);
    packageDefinition.applyPackagePluginMetadata("plugin-id");
    assertThat(secureProperty.isSecure(), is(true));
    assertThat(nonSecureProperty.isSecure(), is(false));
}
Also used : ConfigurationProperty(com.thoughtworks.go.domain.config.ConfigurationProperty) ConfigurationValue(com.thoughtworks.go.domain.config.ConfigurationValue) EncryptedConfigurationValue(com.thoughtworks.go.domain.config.EncryptedConfigurationValue) ConfigurationKey(com.thoughtworks.go.domain.config.ConfigurationKey) GoCipher(com.thoughtworks.go.security.GoCipher) Configuration(com.thoughtworks.go.domain.config.Configuration) PluginConfiguration(com.thoughtworks.go.domain.config.PluginConfiguration) PackageConfiguration(com.thoughtworks.go.plugin.access.packagematerial.PackageConfiguration) PluginConfiguration(com.thoughtworks.go.domain.config.PluginConfiguration) PackageConfiguration(com.thoughtworks.go.plugin.access.packagematerial.PackageConfiguration) PackageConfigurations(com.thoughtworks.go.plugin.access.packagematerial.PackageConfigurations) Test(org.junit.Test)

Example 43 with ConfigurationValue

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

the class PackageDefinitionTest method shouldNotAddFingerprintFieldErrorWhenPackageDefinitionWithSameFingerprintNotFound.

@Test
public void shouldNotAddFingerprintFieldErrorWhenPackageDefinitionWithSameFingerprintNotFound() throws Exception {
    PackageRepository repository = PackageRepositoryMother.create("repo1");
    PackageDefinition packageDefinition = PackageDefinitionMother.create("1", "pkg1", new Configuration(new ConfigurationProperty(new ConfigurationKey("k1"), new ConfigurationValue("v1"))), repository);
    HashMap<String, Packages> map = new HashMap<>();
    map.put(packageDefinition.getFingerprint(AbstractMaterialConfig.FINGERPRINT_DELIMITER), new Packages(packageDefinition));
    packageDefinition.validateFingerprintUniqueness(map);
    assertThat(packageDefinition.errors().getAllOn(PackageDefinition.ID), is(nullValue()));
}
Also used : ConfigurationProperty(com.thoughtworks.go.domain.config.ConfigurationProperty) ConfigurationValue(com.thoughtworks.go.domain.config.ConfigurationValue) EncryptedConfigurationValue(com.thoughtworks.go.domain.config.EncryptedConfigurationValue) Configuration(com.thoughtworks.go.domain.config.Configuration) PluginConfiguration(com.thoughtworks.go.domain.config.PluginConfiguration) PackageConfiguration(com.thoughtworks.go.plugin.access.packagematerial.PackageConfiguration) ConfigurationKey(com.thoughtworks.go.domain.config.ConfigurationKey) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 44 with ConfigurationValue

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

the class PackageDefinitionTest method shouldClearConfigurationsWhichAreEmptyAndNoErrors.

@Test
public void shouldClearConfigurationsWhichAreEmptyAndNoErrors() throws Exception {
    PackageDefinition packageDefinition = new PackageDefinition();
    packageDefinition.getConfiguration().add(new ConfigurationProperty(new ConfigurationKey("name-one"), new ConfigurationValue()));
    packageDefinition.getConfiguration().add(new ConfigurationProperty(new ConfigurationKey("name-two"), new EncryptedConfigurationValue()));
    packageDefinition.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");
    packageDefinition.getConfiguration().add(configurationProperty);
    packageDefinition.clearEmptyConfigurations();
    assertThat(packageDefinition.getConfiguration().size(), is(1));
    assertThat(packageDefinition.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 45 with ConfigurationValue

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

the class PackageRepositoryTest method shouldMakeConfigurationSecureBasedOnMetadata.

@Test
public void shouldMakeConfigurationSecureBasedOnMetadata() throws Exception {
    GoCipher goCipher = new GoCipher();
    /*secure property is set based on metadata*/
    ConfigurationProperty secureProperty = new ConfigurationProperty(new ConfigurationKey("key1"), new ConfigurationValue("value1"), null, goCipher);
    ConfigurationProperty nonSecureProperty = new ConfigurationProperty(new ConfigurationKey("key2"), new ConfigurationValue("value2"), null, goCipher);
    PackageDefinition packageDefinition = new PackageDefinition("go", "name", new Configuration(secureProperty, nonSecureProperty));
    // meta data of package
    PackageConfigurations packageConfigurations = new PackageConfigurations();
    packageConfigurations.addConfiguration(new PackageConfiguration("key1").with(SECURE, true));
    packageConfigurations.addConfiguration(new PackageConfiguration("key2").with(SECURE, false));
    PackageMetadataStore.getInstance().addMetadataFor("plugin-id", packageConfigurations);
    /*secure property is set based on metadata*/
    ConfigurationProperty secureRepoProperty = new ConfigurationProperty(new ConfigurationKey("key1"), new ConfigurationValue("value1"), null, goCipher);
    ConfigurationProperty nonSecureRepoProperty = new ConfigurationProperty(new ConfigurationKey("key2"), new ConfigurationValue("value2"), null, goCipher);
    PackageRepository packageRepository = createPackageRepository("plugin-id", "version", "id", "name", new Configuration(secureRepoProperty, nonSecureRepoProperty), new Packages(packageDefinition));
    // meta data of repo
    PackageConfigurations repositoryConfiguration = new PackageConfigurations();
    repositoryConfiguration.addConfiguration(new PackageConfiguration("key1").with(SECURE, true));
    repositoryConfiguration.addConfiguration(new PackageConfiguration("key2").with(SECURE, false));
    RepositoryMetadataStore.getInstance().addMetadataFor("plugin-id", repositoryConfiguration);
    packageRepository.applyPackagePluginMetadata();
    // assert package properties
    assertThat(secureProperty.isSecure(), is(true));
    assertThat(secureProperty.getEncryptedConfigurationValue(), is(notNullValue()));
    assertThat(secureProperty.getEncryptedValue(), is(goCipher.encrypt("value1")));
    assertThat(nonSecureProperty.isSecure(), is(false));
    assertThat(nonSecureProperty.getValue(), is("value2"));
    // assert repository properties
    assertThat(secureRepoProperty.isSecure(), is(true));
    assertThat(secureRepoProperty.getEncryptedConfigurationValue(), is(notNullValue()));
    assertThat(secureRepoProperty.getEncryptedValue(), is(goCipher.encrypt("value1")));
    assertThat(nonSecureRepoProperty.isSecure(), is(false));
    assertThat(nonSecureRepoProperty.getValue(), is("value2"));
}
Also used : ConfigurationProperty(com.thoughtworks.go.domain.config.ConfigurationProperty) ConfigurationValue(com.thoughtworks.go.domain.config.ConfigurationValue) EncryptedConfigurationValue(com.thoughtworks.go.domain.config.EncryptedConfigurationValue) GoCipher(com.thoughtworks.go.security.GoCipher) ConfigurationKey(com.thoughtworks.go.domain.config.ConfigurationKey) Configuration(com.thoughtworks.go.domain.config.Configuration) PluginConfiguration(com.thoughtworks.go.domain.config.PluginConfiguration) PackageConfiguration(com.thoughtworks.go.plugin.access.packagematerial.PackageConfiguration) PackageConfiguration(com.thoughtworks.go.plugin.access.packagematerial.PackageConfiguration) PackageConfigurations(com.thoughtworks.go.plugin.access.packagematerial.PackageConfigurations) Test(org.junit.Test)

Aggregations

ConfigurationValue (com.thoughtworks.go.domain.config.ConfigurationValue)56 ConfigurationProperty (com.thoughtworks.go.domain.config.ConfigurationProperty)50 ConfigurationKey (com.thoughtworks.go.domain.config.ConfigurationKey)49 Test (org.junit.Test)47 EncryptedConfigurationValue (com.thoughtworks.go.domain.config.EncryptedConfigurationValue)28 Configuration (com.thoughtworks.go.domain.config.Configuration)20 PluginConfiguration (com.thoughtworks.go.domain.config.PluginConfiguration)14 GoCipher (com.thoughtworks.go.security.GoCipher)10 PackageConfiguration (com.thoughtworks.go.plugin.access.packagematerial.PackageConfiguration)9 PluggableInstanceSettings (com.thoughtworks.go.plugin.domain.common.PluggableInstanceSettings)9 ValidationResult (com.thoughtworks.go.plugin.api.response.validation.ValidationResult)7 Metadata (com.thoughtworks.go.plugin.domain.common.Metadata)7 PluginConfiguration (com.thoughtworks.go.plugin.domain.common.PluginConfiguration)7 ValidationError (com.thoughtworks.go.plugin.api.response.validation.ValidationError)6 ElasticProfile (com.thoughtworks.go.config.elastic.ElasticProfile)5 PluginRoleConfig (com.thoughtworks.go.config.PluginRoleConfig)4 SCMConfiguration (com.thoughtworks.go.plugin.access.scm.SCMConfiguration)4 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)4 SecurityAuthConfig (com.thoughtworks.go.config.SecurityAuthConfig)3 SCM (com.thoughtworks.go.domain.scm.SCM)3