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