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