use of com.thoughtworks.go.config.pluggabletask.PluggableTask in project gocd by gocd.
the class MagicalGoConfigXmlLoaderTest method shouldBeAbleToResolveSecureConfigPropertiesForPluggableTasks.
@Test
public void shouldBeAbleToResolveSecureConfigPropertiesForPluggableTasks() throws Exception {
String encryptedValue = new GoCipher().encrypt("password");
String configString = "<cruise schemaVersion='" + CONFIG_SCHEMA_VERSION + "'>\n" + " <pipelines>" + "<pipeline name='pipeline1'>" + " <materials>" + " <svn url='svnurl' username='admin' password='%s'/>" + " </materials>" + " <stage name='mingle'>" + " <jobs>" + " <job name='do-something'><tasks>" + " <task>" + " <pluginConfiguration id='plugin-id-1' version='1.0'/>" + " <configuration>" + " <property><key>username</key><value>godev</value></property>" + " <property><key>password</key><value>password</value></property>" + " </configuration>" + " </task> </tasks>" + " </job>" + " </jobs>" + " </stage>" + "</pipeline></pipelines>" + "</cruise>";
// meta data of package
PluggableTaskConfigStore.store().setPreferenceFor("plugin-id-1", new TaskPreference(new com.thoughtworks.go.plugin.api.task.Task() {
@Override
public TaskConfig config() {
TaskConfig taskConfig = new TaskConfig();
taskConfig.addProperty("username").with(Property.SECURE, false);
taskConfig.addProperty("password").with(Property.SECURE, true);
return taskConfig;
}
@Override
public TaskExecutor executor() {
return null;
}
@Override
public TaskView view() {
return null;
}
@Override
public ValidationResult validate(TaskConfig configuration) {
return null;
}
}));
GoConfigHolder goConfigHolder = xmlLoader.loadConfigHolder(configString);
PipelineConfig pipelineConfig = goConfigHolder.config.pipelineConfigByName(new CaseInsensitiveString("pipeline1"));
PluggableTask task = (PluggableTask) pipelineConfig.getStage("mingle").getJobs().getJob(new CaseInsensitiveString("do-something")).getTasks().first();
assertFalse(task.getConfiguration().getProperty("username").isSecure());
assertTrue(task.getConfiguration().getProperty("password").isSecure());
}
use of com.thoughtworks.go.config.pluggabletask.PluggableTask in project gocd by gocd.
the class GoConfigMigrationIntegrationTest method shouldAllowPluggableTaskConfiguration_asPartOfMigration70.
@Test
public void shouldAllowPluggableTaskConfiguration_asPartOfMigration70() throws Exception {
String configString = "<cruise schemaVersion='70'> <pipelines>" + "<pipeline name='pipeline1'>" + " <materials>" + " <svn url='svnurl' username='admin' password='%s'/>" + " </materials>" + " <stage name='mingle'>" + " <jobs>" + " <job name='do-something'><tasks>" + " <task name='run-curl'>" + " <pluginConfiguration id='plugin-id' version='1.0' />" + " <configuration>" + " <property><key>url</key><value>http://fake-yum-repo</value></property>" + " <property><key>username</key><value>godev</value></property>" + " <property><key>password</key><value>password</value></property>" + " </configuration>" + " </task> </tasks>" + " </job>" + " </jobs>" + " </stage>" + "</pipeline></pipelines>" + "</cruise>";
CruiseConfig cruiseConfig = loadConfigFileWithContent(configString);
PipelineConfig pipelineConfig = cruiseConfig.getAllPipelineConfigs().get(0);
JobConfig jobConfig = pipelineConfig.getFirstStageConfig().getJobs().get(0);
Tasks tasks = jobConfig.getTasks();
assertThat(tasks.size(), is(1));
assertThat(tasks.get(0) instanceof PluggableTask, is(true));
}
use of com.thoughtworks.go.config.pluggabletask.PluggableTask in project gocd by gocd.
the class PluggableTaskBuilderCreatorTest method setup.
@Before
public void setup() throws Exception {
pluggableTask = new PluggableTask(new PluginConfiguration("test-plugin-id", "13.4"), new Configuration());
pluggableTaskBuilderCreator = new PluggableTaskBuilderCreator(mock(TaskExtension.class));
execTaskBuilder = new ExecTaskBuilder();
builderFactory = mock(BuilderFactory.class);
resolver = mock(UpstreamPipelineResolver.class);
}
use of com.thoughtworks.go.config.pluggabletask.PluggableTask in project gocd by gocd.
the class PluggableTaskServiceTest method isValidShouldMapPluginValidationErrorsToPluggableTaskForMissingConfigurations.
@Test
public void isValidShouldMapPluginValidationErrorsToPluggableTaskForMissingConfigurations() {
PluginConfiguration pluginConfiguration = new PluginConfiguration("plugin_id", "version");
ValidationResult validationResult = new ValidationResult();
validationResult.addError(new ValidationError("source", "source is mandatory"));
PluggableTask pluggableTask = mock(PluggableTask.class);
when(pluggableTask.isValid()).thenReturn(true);
when(pluggableTask.getPluginConfiguration()).thenReturn(pluginConfiguration);
when(pluggableTask.getConfiguration()).thenReturn(new Configuration());
when(taskExtension.validate(any(String.class), any(TaskConfig.class))).thenReturn(validationResult);
assertFalse(pluggableTaskService.isValid(pluggableTask));
verify(pluggableTask).addError("source", "source is mandatory");
}
use of com.thoughtworks.go.config.pluggabletask.PluggableTask in project gocd by gocd.
the class PluggableTaskServiceTest method shouldValidateMandatoryFields.
@Test
public void shouldValidateMandatoryFields() {
Configuration configuration = new Configuration(ConfigurationPropertyMother.create("KEY1"));
PluggableTask modifiedTask = new PluggableTask(new PluginConfiguration(pluginId, "1"), configuration);
ValidationResult validationResult = new ValidationResult();
when(taskExtension.validate(eq(modifiedTask.getPluginConfiguration().getId()), any(TaskConfig.class))).thenReturn(validationResult);
when(localizer.localize("MANDATORY_CONFIGURATION_FIELD")).thenReturn("MANDATORY_CONFIGURATION_FIELD");
pluggableTaskService.validate(modifiedTask);
final List<ValidationError> validationErrors = validationResult.getErrors();
assertFalse(validationErrors.isEmpty());
final ValidationError validationError = validationErrors.stream().filter(new Predicate<ValidationError>() {
@Override
public boolean test(ValidationError item) {
return ((ValidationError) item).getKey().equals("KEY1");
}
}).findFirst().orElse(null);
assertNotNull(validationError);
assertThat(validationError.getMessage(), is("MANDATORY_CONFIGURATION_FIELD"));
}
Aggregations