Search in sources :

Example 66 with ConfigurationKey

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

the class PluginSettingsTest method shouldPassValidationIfEncryptedVariablesAreEncryptedWithTheCorrectCipher.

@Test
public void shouldPassValidationIfEncryptedVariablesAreEncryptedWithTheCorrectCipher() throws CryptoException {
    final PluginInfo pluginInfo = mock(PluginInfo.class);
    String secureKey = "supposedly-secure-key";
    when(pluginInfo.isSecure(secureKey)).thenReturn(true);
    PluginSettings pluginSettings = new PluginSettings(PLUGIN_ID);
    pluginSettings.addConfigurations(pluginInfo, Arrays.asList(new ConfigurationProperty(new ConfigurationKey(secureKey), new EncryptedConfigurationValue(new GoCipher().encrypt("secure")))));
    pluginSettings.validateTree();
    assertThat(pluginSettings.hasErrors(), is(false));
}
Also used : ConfigurationProperty(com.thoughtworks.go.domain.config.ConfigurationProperty) EncryptedConfigurationValue(com.thoughtworks.go.domain.config.EncryptedConfigurationValue) ConfigurationKey(com.thoughtworks.go.domain.config.ConfigurationKey) GoCipher(com.thoughtworks.go.security.GoCipher) ElasticAgentPluginInfo(com.thoughtworks.go.plugin.domain.elastic.ElasticAgentPluginInfo) PluginInfo(com.thoughtworks.go.plugin.domain.common.PluginInfo) ConfigRepoPluginInfo(com.thoughtworks.go.plugin.domain.configrepo.ConfigRepoPluginInfo) Test(org.junit.jupiter.api.Test)

Example 67 with ConfigurationKey

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

the class ElasticAgentPluginServiceTest method shouldPassAlongAllClusterProfilesBelongingToThePluginWhileGettingPluginStatusReport.

@Test
void shouldPassAlongAllClusterProfilesBelongingToThePluginWhileGettingPluginStatusReport() {
    final Capabilities capabilities = new Capabilities(true);
    final GoPluginDescriptor descriptor = GoPluginDescriptor.builder().id("cd.go.example.plugin").build();
    elasticAgentMetadataStore.setPluginInfo(new ElasticAgentPluginInfo(descriptor, null, null, null, null, capabilities));
    ClusterProfiles allClusterProfiles = new ClusterProfiles();
    ClusterProfile cluster1 = new ClusterProfile("id1", "cd.go.example.plugin", new ConfigurationProperty(new ConfigurationKey("key1"), new ConfigurationValue("value1")));
    ClusterProfile cluster2 = new ClusterProfile("id2", "cd.go.example.plugin2", new ConfigurationProperty(new ConfigurationKey("key2"), new ConfigurationValue("value2")));
    allClusterProfiles.add(cluster1);
    allClusterProfiles.add(cluster2);
    when(clusterProfilesService.getPluginProfiles()).thenReturn(allClusterProfiles);
    when(registry.getPluginStatusReport("cd.go.example.plugin", asList(cluster1.getConfigurationAsMap(true)))).thenReturn("<div>This is a plugin status report snippet.</div>");
    final String pluginStatusReport = service.getPluginStatusReport("cd.go.example.plugin");
    assertThat(pluginStatusReport).isEqualTo("<div>This is a plugin status report snippet.</div>");
}
Also used : ConfigurationProperty(com.thoughtworks.go.domain.config.ConfigurationProperty) ConfigurationValue(com.thoughtworks.go.domain.config.ConfigurationValue) ElasticAgentPluginInfo(com.thoughtworks.go.plugin.domain.elastic.ElasticAgentPluginInfo) ConfigurationKey(com.thoughtworks.go.domain.config.ConfigurationKey) Capabilities(com.thoughtworks.go.plugin.domain.elastic.Capabilities) GoPluginDescriptor(com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor) ClusterProfiles(com.thoughtworks.go.config.elastic.ClusterProfiles) ClusterProfile(com.thoughtworks.go.config.elastic.ClusterProfile) Test(org.junit.jupiter.api.Test)

Example 68 with ConfigurationKey

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

the class ClusterProfilesChangedPluginNotifierTest method setUp.

@BeforeEach
void setUp() {
    pluginId = "plugin-id";
    when(goConfigService.getElasticConfig()).thenReturn(new ElasticConfig());
    properties = new ArrayList<>();
    properties.add(new ConfigurationProperty(new ConfigurationKey("key1"), new ConfigurationValue("value1")));
    oldClusterProfile = new ClusterProfile("profile1", pluginId, properties);
    newClusterProfile = new ClusterProfile("profile1", pluginId, properties);
    notifier = new ClusterProfilesChangedPluginNotifier(goConfigService, registry, secretParamResolver, serverHealthService);
}
Also used : ConfigurationProperty(com.thoughtworks.go.domain.config.ConfigurationProperty) ConfigurationValue(com.thoughtworks.go.domain.config.ConfigurationValue) ElasticConfig(com.thoughtworks.go.config.elastic.ElasticConfig) ConfigurationKey(com.thoughtworks.go.domain.config.ConfigurationKey) ClusterProfile(com.thoughtworks.go.config.elastic.ClusterProfile) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 69 with ConfigurationKey

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

the class PluginServiceTest method validatePluginSettingsFor_shouldCheckIfSecureValuesSetByUserAreValid.

@Test
public void validatePluginSettingsFor_shouldCheckIfSecureValuesSetByUserAreValid() {
    String secureKey = "secure-key";
    setUpElasticPluginForTheTest(true);
    PluginSettings pluginSettings = new PluginSettings(elasticAgentPluginId);
    final PluginInfo pluginInfo = mock(PluginInfo.class);
    when(pluginInfo.isSecure(secureKey)).thenReturn(true);
    pluginSettings.addConfigurations(pluginInfo, Arrays.asList(new ConfigurationProperty(new ConfigurationKey(secureKey), new EncryptedConfigurationValue("value_encrypted_by_a_different_cipher"))));
    pluginService.validatePluginSettings(pluginSettings);
    assertThat(pluginSettings.hasErrors(), is(true));
    List<String> allErrorsOnProperty = pluginSettings.getPluginSettingsProperties().get(0).errors().getAll();
    assertThat(allErrorsOnProperty.size(), is(1));
    assertTrue(allErrorsOnProperty.contains("Encrypted value for property with key 'secure-key' is invalid. This usually happens when the cipher text is modified to have an invalid value."));
    verify(elasticAgentExtension, never()).validatePluginSettings(eq(elasticAgentPluginId), any(PluginSettingsConfiguration.class));
}
Also used : ConfigurationProperty(com.thoughtworks.go.domain.config.ConfigurationProperty) EncryptedConfigurationValue(com.thoughtworks.go.domain.config.EncryptedConfigurationValue) ConfigurationKey(com.thoughtworks.go.domain.config.ConfigurationKey) PluginSettings(com.thoughtworks.go.server.domain.PluginSettings) SCMPluginInfo(com.thoughtworks.go.plugin.domain.scm.SCMPluginInfo) AuthorizationPluginInfo(com.thoughtworks.go.plugin.domain.authorization.AuthorizationPluginInfo) ElasticAgentPluginInfo(com.thoughtworks.go.plugin.domain.elastic.ElasticAgentPluginInfo) NotificationPluginInfo(com.thoughtworks.go.plugin.domain.notification.NotificationPluginInfo) PluginSettingsConfiguration(com.thoughtworks.go.plugin.access.common.settings.PluginSettingsConfiguration) Test(org.junit.jupiter.api.Test)

Example 70 with ConfigurationKey

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

the class RoleConfigurationValidatorTest method shouldAddErrorsInAbsenceOfPlugin.

@Test
public void shouldAddErrorsInAbsenceOfPlugin() throws Exception {
    ConfigurationProperty property = new ConfigurationProperty(new ConfigurationKey("username"), new ConfigurationValue("view"));
    PluginRoleConfig roleConfig = new PluginRoleConfig("admin", "auth_id", property);
    when(extension.validateRoleConfiguration("pluginId", Collections.singletonMap("username", "view"))).thenThrow(new RecordNotFoundException("not found"));
    validator.validate(roleConfig, "pluginId");
    assertTrue(roleConfig.hasErrors());
    assertThat(roleConfig.errors().get("pluginRole").get(0), is("Unable to validate `pluginRole` configuration, missing plugin: pluginId"));
}
Also used : ConfigurationProperty(com.thoughtworks.go.domain.config.ConfigurationProperty) ConfigurationValue(com.thoughtworks.go.domain.config.ConfigurationValue) RecordNotFoundException(com.thoughtworks.go.config.exceptions.RecordNotFoundException) ConfigurationKey(com.thoughtworks.go.domain.config.ConfigurationKey) PluginRoleConfig(com.thoughtworks.go.config.PluginRoleConfig) 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