use of com.thoughtworks.go.plugin.access.exceptions.SecretResolutionFailureException in project gocd by gocd.
the class BuildAssignmentServiceTest method shouldFailTheJobWhenSecretResolutionErrorOccursForElasticConfiguration.
@Test
void shouldFailTheJobWhenSecretResolutionErrorOccursForElasticConfiguration() throws IOException, IllegalArtifactLocationException {
PipelineConfig pipelineWithElasticJob = PipelineConfigMother.pipelineWithElasticJob(elasticProfileId1);
JobPlan jobPlan = new InstanceFactory().createJobPlan(pipelineWithElasticJob.first().getJobs().first(), schedulingContext);
jobPlans.add(jobPlan);
JobInstance jobInstance = mock(JobInstance.class);
doThrow(new SecretResolutionFailureException("some secret resolution related failure message")).when(elasticAgentPluginService).shouldAssignWork(elasticAgentInstance.elasticAgentMetadata(), null, jobPlan.getElasticProfile(), jobPlan.getClusterProfile(), jobPlan.getIdentifier());
when(jobInstance.getState()).thenReturn(JobState.Scheduled);
when(jobInstanceService.buildById(anyLong())).thenReturn(jobInstance);
buildAssignmentService.onTimer();
assertThatCode(() -> {
JobPlan matchingJob = buildAssignmentService.findMatchingJob(elasticAgentInstance);
assertThat(matchingJob).isNull();
assertThat(buildAssignmentService.jobPlans()).containsExactly(jobPlan);
}).doesNotThrowAnyException();
InOrder inOrder = inOrder(jobInstanceService, scheduleService, consoleService, jobStatusTopic);
inOrder.verify(jobInstanceService).buildById(jobPlan.getJobId());
inOrder.verify(consoleService).appendToConsoleLog(jobPlan.getIdentifier(), "\nThis job was failed by GoCD. This job is configured to run on an elastic agent, there were errors while resolving secrets for the the associated elastic configurations.\nReasons: some secret resolution related failure message");
inOrder.verify(scheduleService).failJob(jobInstance);
inOrder.verify(jobStatusTopic).post(new JobStatusMessage(jobPlan.getIdentifier(), JobState.Scheduled, elasticAgentInstance.getUuid()));
}
use of com.thoughtworks.go.plugin.access.exceptions.SecretResolutionFailureException in project gocd by gocd.
the class PackageDefinitionServiceTest method shouldSetResultAsUnprocessableEntityIfSecretResolutionFailsForCheckConnection.
@Test
void shouldSetResultAsUnprocessableEntityIfSecretResolutionFailsForCheckConnection() {
PackageDefinition packageDefinition = PackageDefinitionMother.create("1", "name", new Configuration(), packageRepository);
HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
doThrow(new SecretResolutionFailureException("some secret resolution failure")).when(secretParamResolver).resolve(packageDefinition);
service.checkConnection(packageDefinition, result);
assertThat(result.isSuccessful()).isFalse();
assertThat(result.httpCode()).isEqualTo(HttpStatus.SC_UNPROCESSABLE_ENTITY);
assertThat(result.message()).isEqualTo("Package check Failed. Reason(s): some secret resolution failure");
}
use of com.thoughtworks.go.plugin.access.exceptions.SecretResolutionFailureException in project gocd by gocd.
the class PackageDefinitionServiceTest method shouldSetResultAsUnprocessableEntityIfSecretResolutionFailsForUpdate.
@Test
void shouldSetResultAsUnprocessableEntityIfSecretResolutionFailsForUpdate() {
PackageDefinition packageDefinition = PackageDefinitionMother.create("1", "name", new Configuration(), packageRepository);
HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
doThrow(new SecretResolutionFailureException("some secret resolution message")).when(goConfigService).updateConfig(any(EntityConfigUpdateCommand.class), any(Username.class));
service.createPackage(packageDefinition, packageRepository.getId(), new Username("user"), result);
assertThat(result.isSuccessful()).isFalse();
assertThat(result.httpCode()).isEqualTo(HttpStatus.SC_UNPROCESSABLE_ENTITY);
assertThat(result.message()).isEqualTo("Save failed. some secret resolution message");
}
use of com.thoughtworks.go.plugin.access.exceptions.SecretResolutionFailureException in project gocd by gocd.
the class PackageRepositoryServiceTest method shouldSetResultAsUnprocessableEntityIfSecretResolutionFailsForUpdate.
@Test
void shouldSetResultAsUnprocessableEntityIfSecretResolutionFailsForUpdate() {
HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
doThrow(new SecretResolutionFailureException("some secret resolution message")).when(goConfigService).updateConfig(any(EntityConfigUpdateCommand.class), any(Username.class));
service.createPackageRepository(packageRepository("some-plugin"), new Username("user"), result);
assertThat(result.isSuccessful()).isFalse();
assertThat(result.httpCode()).isEqualTo(HttpStatus.SC_UNPROCESSABLE_ENTITY);
assertThat(result.message()).isEqualTo("Save failed. some secret resolution message");
}
use of com.thoughtworks.go.plugin.access.exceptions.SecretResolutionFailureException in project gocd by gocd.
the class PackageRepositoryServiceTest method shouldSetResultAsUnprocessableEntityIfSecretResolutionFailsForCheckConnection.
@Test
void shouldSetResultAsUnprocessableEntityIfSecretResolutionFailsForCheckConnection() {
HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
doThrow(new SecretResolutionFailureException("some secret resolution message")).when(secretParamResolver).resolve(any(PackageRepository.class));
service.checkConnection(packageRepository("some-plugin"), result);
assertThat(result.isSuccessful()).isFalse();
assertThat(result.httpCode()).isEqualTo(HttpStatus.SC_UNPROCESSABLE_ENTITY);
assertThat(result.message()).isEqualTo("Could not connect to package repository. Reason(s): some secret resolution message");
}
Aggregations