Search in sources :

Example 16 with EncryptedConfigurationValue

use of com.thoughtworks.go.domain.config.EncryptedConfigurationValue 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 17 with EncryptedConfigurationValue

use of com.thoughtworks.go.domain.config.EncryptedConfigurationValue 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)

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