use of com.thoughtworks.go.domain.config.ConfigurationKey in project gocd by gocd.
the class ElasticProfileTest method postConstruct_shouldEncryptSecureConfigurations.
@Test
public void postConstruct_shouldEncryptSecureConfigurations() {
PluggableInstanceSettings profileSettings = new PluggableInstanceSettings(Arrays.asList(new PluginConfiguration("password", new Metadata(true, true))));
ElasticAgentPluginInfo pluginInfo = new ElasticAgentPluginInfo(pluginDescriptor("plugin_id"), profileSettings, null, null, null);
store.setPluginInfo(pluginInfo);
ElasticProfile profile = new ElasticProfile("id", "plugin_id", new ConfigurationProperty(new ConfigurationKey("password"), new ConfigurationValue("pass")));
profile.encryptSecureConfigurations();
assertThat(profile.size(), is(1));
assertTrue(profile.first().isSecure());
}
use of com.thoughtworks.go.domain.config.ConfigurationKey in project gocd by gocd.
the class ElasticProfileTest method addConfiguration_shouldEncryptASecureVariable.
@Test
public void addConfiguration_shouldEncryptASecureVariable() throws Exception {
PluggableInstanceSettings profileSettings = new PluggableInstanceSettings(Arrays.asList(new PluginConfiguration("password", new Metadata(true, true))));
ElasticAgentPluginInfo pluginInfo = new ElasticAgentPluginInfo(pluginDescriptor("plugin_id"), profileSettings, null, null, null);
store.setPluginInfo(pluginInfo);
ElasticProfile profile = new ElasticProfile("id", "plugin_id");
profile.addConfigurations(Arrays.asList(new ConfigurationProperty(new ConfigurationKey("password"), new ConfigurationValue("pass"))));
assertThat(profile.size(), is(1));
assertTrue(profile.first().isSecure());
}
use of com.thoughtworks.go.domain.config.ConfigurationKey in project gocd by gocd.
the class ErrorCollectorTest method shouldCollectErrorsWithLabel.
@Test
public void shouldCollectErrorsWithLabel() throws Exception {
PackageRepository packageRepository = new PackageRepository();
packageRepository.addError("name", "name is mandatory field");
packageRepository.getConfiguration().add(new ConfigurationProperty(new ConfigurationKey("name"), new ConfigurationValue("value")));
packageRepository.getConfiguration().get(0).getConfigurationKey().addError("name", "url is mandatory field");
HashMap<String, List<String>> errorsMap = new HashMap<>();
ErrorCollector.collectFieldErrors(errorsMap, "package_repository", packageRepository);
List<String> nameErrors = new ArrayList<>();
nameErrors.add("name is mandatory field");
assertThat(errorsMap.get("package_repository[name]"), is(nameErrors));
List<String> urlErrors = new ArrayList<>();
urlErrors.add("url is mandatory field");
assertThat(errorsMap.get("package_repository[configuration][0][configurationKey][name]"), is(urlErrors));
}
use of com.thoughtworks.go.domain.config.ConfigurationKey in project gocd by gocd.
the class JobInstanceSqlMapDaoTest method shouldSaveJobAgentMetadata.
@Test
public void shouldSaveJobAgentMetadata() {
JobInstance instance = jobInstanceDao.save(stageId, new JobInstance(JOB_NAME));
instance.setIdentifier(new JobIdentifier(savedPipeline, savedStage, instance));
ElasticProfile elasticProfile = new ElasticProfile("foo", "cd.go.elastic-agent:docker", Arrays.asList(new ConfigurationProperty(new ConfigurationKey("key"), new ConfigurationValue("value"))));
JobPlan plan = new DefaultJobPlan(new Resources("something"), new ArrayList<>(), new ArrayList<>(), instance.getId(), instance.getIdentifier(), null, new EnvironmentVariables(), new EnvironmentVariables(), elasticProfile);
jobInstanceDao.save(instance.getId(), plan);
JobPlan retrieved = jobInstanceDao.loadPlan(plan.getJobId());
assertThat(retrieved.getElasticProfile(), is(elasticProfile));
}
use of com.thoughtworks.go.domain.config.ConfigurationKey in project gocd by gocd.
the class PluggableTaskTest method testConfigAsMap.
@Test
public void testConfigAsMap() throws Exception {
PluginConfiguration pluginConfiguration = new PluginConfiguration("test-plugin-id", "13.4");
GoCipher cipher = new GoCipher();
List<String> keys = Arrays.asList("Avengers 1", "Avengers 2", "Avengers 3", "Avengers 4");
List<String> values = Arrays.asList("Iron man", "Hulk", "Thor", "Captain America");
Configuration configuration = new Configuration(new ConfigurationProperty(new ConfigurationKey(keys.get(0)), new ConfigurationValue(values.get(0))), new ConfigurationProperty(new ConfigurationKey(keys.get(1)), new ConfigurationValue(values.get(1))), new ConfigurationProperty(new ConfigurationKey(keys.get(2)), new ConfigurationValue(values.get(2))), new ConfigurationProperty(new ConfigurationKey(keys.get(3)), null, new EncryptedConfigurationValue(cipher.encrypt(values.get(3))), cipher));
PluggableTask task = new PluggableTask(pluginConfiguration, configuration);
Map<String, Map<String, String>> configMap = task.configAsMap();
assertThat(configMap.keySet().size(), is(keys.size()));
assertThat(configMap.values().size(), is(values.size()));
assertThat(configMap.keySet().containsAll(keys), is(true));
for (int i = 0; i < keys.size(); i++) {
assertThat(configMap.get(keys.get(i)).get(PluggableTask.VALUE_KEY), is(values.get(i)));
}
}
Aggregations