Search in sources :

Example 11 with ConfigurationKey

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

the class PluginRoleConfigTest method shouldNotEncryptSecurePluginProperties_WhenPluginInfosIsAbsent.

@Test
public void shouldNotEncryptSecurePluginProperties_WhenPluginInfosIsAbsent() throws CryptoException {
    String authConfigId = "auth_config_id";
    String pluginId = "cd.go.github";
    BasicCruiseConfig basicCruiseConfig = new BasicCruiseConfig();
    basicCruiseConfig.server().security().securityAuthConfigs().add(new SecurityAuthConfig(authConfigId, pluginId));
    PluginRoleConfig role = new PluginRoleConfig("admin", authConfigId);
    role.addConfigurations(asList(new ConfigurationProperty(new ConfigurationKey("k1"), new ConfigurationValue("pub_v1")), new ConfigurationProperty(new ConfigurationKey("k2"), new ConfigurationValue("pub_v2")), new ConfigurationProperty(new ConfigurationKey("k3"), new ConfigurationValue("pub_v3"))));
    assertThat(role.getProperty("k1").getEncryptedValue(), is(nullValue()));
    assertThat(role.getProperty("k1").getConfigValue(), is("pub_v1"));
    assertThat(role.getProperty("k1").getValue(), is("pub_v1"));
    assertThat(role.getProperty("k2").getEncryptedValue(), is(nullValue()));
    assertThat(role.getProperty("k2").getConfigValue(), is("pub_v2"));
    assertThat(role.getProperty("k2").getValue(), is("pub_v2"));
    assertThat(role.getProperty("k3").getEncryptedValue(), is(nullValue()));
    assertThat(role.getProperty("k3").getConfigValue(), is("pub_v3"));
    assertThat(role.getProperty("k3").getValue(), is("pub_v3"));
    role.encryptSecureProperties(basicCruiseConfig);
    assertThat(role.getProperty("k1").getEncryptedValue(), is(nullValue()));
    assertThat(role.getProperty("k1").getConfigValue(), is("pub_v1"));
    assertThat(role.getProperty("k1").getValue(), is("pub_v1"));
    assertThat(role.getProperty("k2").getEncryptedValue(), is(nullValue()));
    assertThat(role.getProperty("k2").getConfigValue(), is("pub_v2"));
    assertThat(role.getProperty("k2").getValue(), is("pub_v2"));
    assertThat(role.getProperty("k3").getEncryptedValue(), is(nullValue()));
    assertThat(role.getProperty("k3").getConfigValue(), is("pub_v3"));
    assertThat(role.getProperty("k3").getValue(), is("pub_v3"));
}
Also used : ConfigurationProperty(com.thoughtworks.go.domain.config.ConfigurationProperty) ConfigurationValue(com.thoughtworks.go.domain.config.ConfigurationValue) ConfigurationKey(com.thoughtworks.go.domain.config.ConfigurationKey) Test(org.junit.jupiter.api.Test)

Example 12 with ConfigurationKey

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

the class PluginRoleConfigTest method shouldNotEncryptSecurePluginProperties_WhenReferencedAuthConfigDoesNotExists.

@Test
public void shouldNotEncryptSecurePluginProperties_WhenReferencedAuthConfigDoesNotExists() throws CryptoException {
    setAuthorizationPluginInfo();
    String authConfigId = "auth_config_id";
    BasicCruiseConfig basicCruiseConfig = new BasicCruiseConfig();
    PluginRoleConfig role = new PluginRoleConfig("admin", authConfigId);
    role.addConfigurations(asList(new ConfigurationProperty(new ConfigurationKey("k1"), new ConfigurationValue("pub_v1")), new ConfigurationProperty(new ConfigurationKey("k2"), new ConfigurationValue("pub_v2")), new ConfigurationProperty(new ConfigurationKey("k3"), new ConfigurationValue("pub_v3"))));
    assertThat(role.getProperty("k1").getEncryptedValue(), is(nullValue()));
    assertThat(role.getProperty("k1").getConfigValue(), is("pub_v1"));
    assertThat(role.getProperty("k1").getValue(), is("pub_v1"));
    assertThat(role.getProperty("k2").getEncryptedValue(), is(nullValue()));
    assertThat(role.getProperty("k2").getConfigValue(), is("pub_v2"));
    assertThat(role.getProperty("k2").getValue(), is("pub_v2"));
    assertThat(role.getProperty("k3").getEncryptedValue(), is(nullValue()));
    assertThat(role.getProperty("k3").getConfigValue(), is("pub_v3"));
    assertThat(role.getProperty("k3").getValue(), is("pub_v3"));
    role.encryptSecureProperties(basicCruiseConfig);
    assertThat(role.getProperty("k1").getEncryptedValue(), is(nullValue()));
    assertThat(role.getProperty("k1").getConfigValue(), is("pub_v1"));
    assertThat(role.getProperty("k1").getValue(), is("pub_v1"));
    assertThat(role.getProperty("k2").getEncryptedValue(), is(nullValue()));
    assertThat(role.getProperty("k2").getConfigValue(), is("pub_v2"));
    assertThat(role.getProperty("k2").getValue(), is("pub_v2"));
    assertThat(role.getProperty("k3").getEncryptedValue(), is(nullValue()));
    assertThat(role.getProperty("k3").getConfigValue(), is("pub_v3"));
    assertThat(role.getProperty("k3").getValue(), is("pub_v3"));
}
Also used : ConfigurationProperty(com.thoughtworks.go.domain.config.ConfigurationProperty) ConfigurationValue(com.thoughtworks.go.domain.config.ConfigurationValue) ConfigurationKey(com.thoughtworks.go.domain.config.ConfigurationKey) Test(org.junit.jupiter.api.Test)

Example 13 with ConfigurationKey

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

the class ElasticProfileTest method postConstruct_shouldIgnoreEncryptionIfPluginInfoIsNotDefined.

@Test
public void postConstruct_shouldIgnoreEncryptionIfPluginInfoIsNotDefined() {
    ElasticProfile profile = new ElasticProfile("id", "prod-cluster", new ConfigurationProperty(new ConfigurationKey("password"), new ConfigurationValue("pass")));
    // profile.encryptSecureConfigurations();
    assertThat(profile.size(), is(1));
    assertFalse(profile.first().isSecure());
}
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) Test(org.junit.jupiter.api.Test)

Example 14 with ConfigurationKey

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

the class ElasticProfileTest method shouldEncryptSecureConfigurations.

@Test
public void shouldEncryptSecureConfigurations() {
    PluggableInstanceSettings profileSettings = new PluggableInstanceSettings(Arrays.asList(new PluginConfiguration("password", new Metadata(true, true))));
    ElasticAgentPluginInfo pluginInfo = new ElasticAgentPluginInfo(pluginDescriptor(pluginId), profileSettings, profileSettings, null, null, null);
    store.setPluginInfo(pluginInfo);
    ElasticProfile profile = new ElasticProfile("id", clusterProfileId, new ConfigurationProperty(new ConfigurationKey("password"), new ConfigurationValue("pass")));
    profile.encryptSecureProperties(config);
    assertThat(profile.size(), is(1));
    assertTrue(profile.first().isSecure());
}
Also used : ConfigurationProperty(com.thoughtworks.go.domain.config.ConfigurationProperty) ConfigurationValue(com.thoughtworks.go.domain.config.ConfigurationValue) EncryptedConfigurationValue(com.thoughtworks.go.domain.config.EncryptedConfigurationValue) ElasticAgentPluginInfo(com.thoughtworks.go.plugin.domain.elastic.ElasticAgentPluginInfo) PluggableInstanceSettings(com.thoughtworks.go.plugin.domain.common.PluggableInstanceSettings) ConfigurationKey(com.thoughtworks.go.domain.config.ConfigurationKey) Metadata(com.thoughtworks.go.plugin.domain.common.Metadata) PluginConfiguration(com.thoughtworks.go.plugin.domain.common.PluginConfiguration) Test(org.junit.jupiter.api.Test)

Example 15 with ConfigurationKey

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

the class ElasticProfileTest method addConfigurations_shouldAddConfigurationsWithValue.

@Test
public void addConfigurations_shouldAddConfigurationsWithValue() throws Exception {
    ConfigurationProperty property = new ConfigurationProperty(new ConfigurationKey("username"), new ConfigurationValue("some_name"));
    ElasticProfile profile = new ElasticProfile("id", "prod-cluster");
    profile.addConfigurations(Arrays.asList(property));
    assertThat(profile.size(), is(1));
    assertThat(profile, contains(new ConfigurationProperty(new ConfigurationKey("username"), new ConfigurationValue("some_name"))));
}
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) Test(org.junit.jupiter.api.Test)

Aggregations

ConfigurationKey (com.thoughtworks.go.domain.config.ConfigurationKey)71 ConfigurationProperty (com.thoughtworks.go.domain.config.ConfigurationProperty)71 ConfigurationValue (com.thoughtworks.go.domain.config.ConfigurationValue)65 Test (org.junit.jupiter.api.Test)49 EncryptedConfigurationValue (com.thoughtworks.go.domain.config.EncryptedConfigurationValue)29 PluginConfiguration (com.thoughtworks.go.plugin.domain.common.PluginConfiguration)13 GoCipher (com.thoughtworks.go.security.GoCipher)13 ElasticProfile (com.thoughtworks.go.config.elastic.ElasticProfile)12 PluggableInstanceSettings (com.thoughtworks.go.plugin.domain.common.PluggableInstanceSettings)12 ClusterProfile (com.thoughtworks.go.config.elastic.ClusterProfile)11 Metadata (com.thoughtworks.go.plugin.domain.common.Metadata)10 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)9 ArrayList (java.util.ArrayList)9 Configuration (com.thoughtworks.go.domain.config.Configuration)8 ElasticAgentPluginInfo (com.thoughtworks.go.plugin.domain.elastic.ElasticAgentPluginInfo)8 Test (org.junit.Test)7 ValidationError (com.thoughtworks.go.plugin.api.response.validation.ValidationError)5 ValidationResult (com.thoughtworks.go.plugin.api.response.validation.ValidationResult)5 BasicCruiseConfig (com.thoughtworks.go.config.BasicCruiseConfig)4 PluginRoleConfig (com.thoughtworks.go.config.PluginRoleConfig)4