Search in sources :

Example 6 with SecretResolutionFailureException

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()));
}
Also used : InOrder(org.mockito.InOrder) JobStatusMessage(com.thoughtworks.go.server.messaging.JobStatusMessage) SecretResolutionFailureException(com.thoughtworks.go.plugin.access.exceptions.SecretResolutionFailureException) Test(org.junit.jupiter.api.Test)

Example 7 with SecretResolutionFailureException

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");
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) Configuration(com.thoughtworks.go.domain.config.Configuration) PackageMaterialTestHelper.assertPackageConfiguration(com.thoughtworks.go.server.service.materials.PackageMaterialTestHelper.assertPackageConfiguration) RepositoryConfiguration(com.thoughtworks.go.plugin.api.material.packagerepository.RepositoryConfiguration) SecretResolutionFailureException(com.thoughtworks.go.plugin.access.exceptions.SecretResolutionFailureException) Test(org.junit.jupiter.api.Test)

Example 8 with SecretResolutionFailureException

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");
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) Configuration(com.thoughtworks.go.domain.config.Configuration) PackageMaterialTestHelper.assertPackageConfiguration(com.thoughtworks.go.server.service.materials.PackageMaterialTestHelper.assertPackageConfiguration) RepositoryConfiguration(com.thoughtworks.go.plugin.api.material.packagerepository.RepositoryConfiguration) Username(com.thoughtworks.go.server.domain.Username) EntityConfigUpdateCommand(com.thoughtworks.go.config.commands.EntityConfigUpdateCommand) SecretResolutionFailureException(com.thoughtworks.go.plugin.access.exceptions.SecretResolutionFailureException) Test(org.junit.jupiter.api.Test)

Example 9 with SecretResolutionFailureException

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");
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) Username(com.thoughtworks.go.server.domain.Username) EntityConfigUpdateCommand(com.thoughtworks.go.config.commands.EntityConfigUpdateCommand) SecretResolutionFailureException(com.thoughtworks.go.plugin.access.exceptions.SecretResolutionFailureException) Test(org.junit.jupiter.api.Test)

Example 10 with SecretResolutionFailureException

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");
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) SecretResolutionFailureException(com.thoughtworks.go.plugin.access.exceptions.SecretResolutionFailureException) PackageRepository(com.thoughtworks.go.domain.packagerepository.PackageRepository) Test(org.junit.jupiter.api.Test)

Aggregations

SecretResolutionFailureException (com.thoughtworks.go.plugin.access.exceptions.SecretResolutionFailureException)10 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)6 RulesViolationException (com.thoughtworks.go.server.exceptions.RulesViolationException)5 Test (org.junit.jupiter.api.Test)5 EntityConfigUpdateCommand (com.thoughtworks.go.config.commands.EntityConfigUpdateCommand)2 ClusterProfile (com.thoughtworks.go.config.elastic.ClusterProfile)2 GoConfigInvalidException (com.thoughtworks.go.config.exceptions.GoConfigInvalidException)2 Configuration (com.thoughtworks.go.domain.config.Configuration)2 RepositoryConfiguration (com.thoughtworks.go.plugin.api.material.packagerepository.RepositoryConfiguration)2 Result (com.thoughtworks.go.plugin.api.response.Result)2 ValidationResult (com.thoughtworks.go.plugin.api.response.validation.ValidationResult)2 Username (com.thoughtworks.go.server.domain.Username)2 PackageMaterialTestHelper.assertPackageConfiguration (com.thoughtworks.go.server.service.materials.PackageMaterialTestHelper.assertPackageConfiguration)2 LocalizedOperationResult (com.thoughtworks.go.server.service.result.LocalizedOperationResult)2 ElasticProfile (com.thoughtworks.go.config.elastic.ElasticProfile)1 RecordNotFoundException (com.thoughtworks.go.config.exceptions.RecordNotFoundException)1 AgentInstance (com.thoughtworks.go.domain.AgentInstance)1 JobIdentifier (com.thoughtworks.go.domain.JobIdentifier)1 JobInstance (com.thoughtworks.go.domain.JobInstance)1 PackageRepository (com.thoughtworks.go.domain.packagerepository.PackageRepository)1