use of com.thoughtworks.go.server.domain.PipelineScheduleOptions in project gocd by gocd.
the class PipelineTriggerServiceIntegrationTest method shouldScheduleAPipelineWithLatestRevisionOfAssociatedMaterial.
@Test
public void shouldScheduleAPipelineWithLatestRevisionOfAssociatedMaterial() {
assertThat(triggerMonitor.isAlreadyTriggered(pipelineName), is(false));
PipelineScheduleOptions pipelineScheduleOptions = new PipelineScheduleOptions();
pipelineTriggerService.schedule(pipelineName, pipelineScheduleOptions, admin, result);
assertThat(result.isSuccess(), is(true));
assertThat(result.fullMessage(), is(String.format("Request to schedule pipeline %s accepted", pipelineName)));
assertThat(result.httpCode(), is(202));
assertThat(triggerMonitor.isAlreadyTriggered(pipelineName), is(true));
materialUpdateStatusNotifier.onMessage(new MaterialUpdateSuccessfulMessage(svnMaterial, 1));
BuildCause buildCause = pipelineScheduleQueue.toBeScheduled().get(pipelineName);
assertNotNull(buildCause);
assertThat(buildCause.getApprover(), is(CaseInsensitiveString.str(admin.getUsername())));
assertThat(buildCause.getMaterialRevisions().findRevisionFor(pipelineConfig.materialConfigs().first()).getLatestRevisionString(), is("s3"));
assertThat(buildCause.getBuildCauseMessage(), is("Forced by admin1"));
assertTrue(buildCause.getVariables().isEmpty());
}
use of com.thoughtworks.go.server.domain.PipelineScheduleOptions in project gocd by gocd.
the class PipelineTriggerServiceIntegrationTest method shouldNotScheduleAPipelineWithTheJunkEncryptedEnvironmentVariable.
@Test
public void shouldNotScheduleAPipelineWithTheJunkEncryptedEnvironmentVariable() throws InvalidCipherTextException {
pipelineConfig.addEnvironmentVariable(new EnvironmentVariableConfig(new GoCipher(), "SECURE_VAR1", "SECURE_VAL", true));
pipelineConfigService.updatePipelineConfig(admin, pipelineConfig, entityHashingService.md5ForEntity(pipelineConfig), new HttpLocalizedOperationResult());
assertThat(triggerMonitor.isAlreadyTriggered(pipelineName), is(false));
PipelineScheduleOptions pipelineScheduleOptions = new PipelineScheduleOptions();
String overriddenEncryptedValue = "some_junk";
pipelineScheduleOptions.getAllEnvironmentVariables().add(new EnvironmentVariableConfig(new GoCipher(), "SECURE_VAR1", overriddenEncryptedValue));
pipelineTriggerService.schedule(pipelineName, pipelineScheduleOptions, admin, result);
assertThat(result.isSuccess(), is(false));
assertThat(result.fullMessage(), is("Request to schedule pipeline rejected { Encrypted value for variable named 'SECURE_VAR1' is invalid. This usually happens when the cipher text is modified to have an invalid value. }"));
assertThat(result.httpCode(), is(422));
assertThat(triggerMonitor.isAlreadyTriggered(pipelineName), is(false));
}
use of com.thoughtworks.go.server.domain.PipelineScheduleOptions in project gocd by gocd.
the class PipelineTriggerServiceIntegrationTest method shouldReturnErrorWhenAnUnauthorizedUserTriesToScheduleAPipeline.
@Test
public void shouldReturnErrorWhenAnUnauthorizedUserTriesToScheduleAPipeline() throws IOException {
assertThat(triggerMonitor.isAlreadyTriggered(pipelineName), is(false));
PipelineScheduleOptions pipelineScheduleOptions = new PipelineScheduleOptions();
pipelineTriggerService.schedule(pipelineName, pipelineScheduleOptions, new Username("foo"), result);
assertThat(result.isSuccess(), is(false));
assertThat(result.fullMessage(), is(String.format("Failed to trigger pipeline [%s] { User foo does not have permission to schedule %s/%s }", pipelineName, pipelineName, stageName)));
assertThat(result.getServerHealthState().getDescription(), is(String.format("User foo does not have permission to schedule %s/%s", pipelineName, pipelineConfig.first().name())));
assertThat(result.httpCode(), is(401));
assertThat(triggerMonitor.isAlreadyTriggered(pipelineName), is(false));
}
use of com.thoughtworks.go.server.domain.PipelineScheduleOptions in project gocd by gocd.
the class PipelineTriggerServiceIntegrationTest method shouldScheduleAPipelineWithTheProvidedEnvironmentVariables.
@Test
public void shouldScheduleAPipelineWithTheProvidedEnvironmentVariables() throws IOException {
pipelineConfig.addEnvironmentVariable("ENV_VAR1", "VAL1");
pipelineConfig.addEnvironmentVariable("ENV_VAR2", "VAL2");
pipelineConfig.addEnvironmentVariable(new EnvironmentVariableConfig(new GoCipher(), "SECURE_VAR1", "SECURE_VAL", true));
pipelineConfig.addEnvironmentVariable(new EnvironmentVariableConfig(new GoCipher(), "SECURE_VAR2", "SECURE_VAL2", true));
pipelineConfigService.updatePipelineConfig(admin, pipelineConfig, entityHashingService.md5ForEntity(pipelineConfig), new HttpLocalizedOperationResult());
Integer pipelineCounterBefore = pipelineSqlMapDao.getCounterForPipeline(pipelineName);
assertThat(triggerMonitor.isAlreadyTriggered(pipelineName), is(false));
PipelineScheduleOptions pipelineScheduleOptions = new PipelineScheduleOptions();
pipelineScheduleOptions.getAllEnvironmentVariables().add(new EnvironmentVariableConfig(new GoCipher(), "ENV_VAR1", "overridden_value", false));
pipelineScheduleOptions.getAllEnvironmentVariables().add(new EnvironmentVariableConfig(new GoCipher(), "SECURE_VAR1", "overridden_secure_value", true));
pipelineTriggerService.schedule(pipelineName, pipelineScheduleOptions, admin, result);
assertThat(result.isSuccess(), is(true));
assertThat(result.fullMessage(), is(String.format("Request to schedule pipeline %s accepted", pipelineName)));
assertThat(result.httpCode(), is(202));
assertThat(triggerMonitor.isAlreadyTriggered(pipelineName), is(true));
materialUpdateStatusNotifier.onMessage(new MaterialUpdateSuccessfulMessage(svnMaterial, 1));
BuildCause buildCause = pipelineScheduleQueue.toBeScheduled().get(pipelineName);
assertNotNull(buildCause);
assertThat(buildCause.getApprover(), is(CaseInsensitiveString.str(admin.getUsername())));
assertThat(buildCause.getMaterialRevisions().findRevisionFor(pipelineConfig.materialConfigs().first()).getLatestRevisionString(), is("s3"));
assertThat(buildCause.getBuildCauseMessage(), is("Forced by admin1"));
assertThat(buildCause.getVariables().size(), is(2));
EnvironmentVariable plainTextVariable = (EnvironmentVariable) CollectionUtils.find(buildCause.getVariables(), new Predicate() {
@Override
public boolean evaluate(Object o) {
EnvironmentVariable variable = (EnvironmentVariable) o;
return variable.getName().equals("ENV_VAR1");
}
});
EnvironmentVariable secureVariable = (EnvironmentVariable) CollectionUtils.find(buildCause.getVariables(), new Predicate() {
@Override
public boolean evaluate(Object o) {
EnvironmentVariable variable = (EnvironmentVariable) o;
return variable.getName().equals("SECURE_VAR1");
}
});
assertThat(plainTextVariable.getValue(), is("overridden_value"));
assertThat(secureVariable.getValue(), is("overridden_secure_value"));
assertThat(secureVariable.isSecure(), is(true));
scheduleService.autoSchedulePipelinesFromRequestBuffer();
Integer pipelineCounterAfter = pipelineSqlMapDao.getCounterForPipeline(pipelineName);
assertThat(pipelineCounterAfter, is(pipelineCounterBefore + 1));
BuildCause buildCauseOfLatestRun = pipelineSqlMapDao.findBuildCauseOfPipelineByNameAndCounter(pipelineName, pipelineCounterAfter);
assertThat(buildCauseOfLatestRun, is(buildCause));
}
use of com.thoughtworks.go.server.domain.PipelineScheduleOptions in project gocd by gocd.
the class PipelineTriggerServiceIntegrationTest method shouldReturnErrorIfThePipelineBeingScheduledDoesnotExistAndHasMaterialsSetInRequest.
@Test
public void shouldReturnErrorIfThePipelineBeingScheduledDoesnotExistAndHasMaterialsSetInRequest() {
String pipelineName = "does-not-exist";
assertThat(triggerMonitor.isAlreadyTriggered(pipelineName), is(false));
PipelineScheduleOptions pipelineScheduleOptions = new PipelineScheduleOptions();
pipelineScheduleOptions.getMaterials().add(new MaterialForScheduling("non-existant-material", "r1"));
pipelineScheduleOptions.getAllEnvironmentVariables().add(new EnvironmentVariableConfig(new GoCipher(), "ENV_VAR1", "overridden_value", false));
pipelineScheduleOptions.getAllEnvironmentVariables().add(new EnvironmentVariableConfig(new GoCipher(), "SECURE_VAR1", "overridden_secure_value", true));
pipelineTriggerService.schedule(pipelineName, pipelineScheduleOptions, admin, result);
assertThat(result.isSuccess(), is(false));
assertThat(result.fullMessage(), is("Pipeline 'does-not-exist' not found."));
assertThat(result.httpCode(), is(404));
assertThat(triggerMonitor.isAlreadyTriggered(pipelineName), is(false));
}
Aggregations