use of com.thoughtworks.go.server.exceptions.RulesViolationException in project gocd by gocd.
the class ClusterProfilesServiceTest method shouldSetResultAsUnprocessableEntityWhenRulesAreViolated.
@Test
void shouldSetResultAsUnprocessableEntityWhenRulesAreViolated() {
clusterProfile.addNewConfigurationWithValue("key", "{{SECRET:[config_id][key]}}", false);
doThrow(new RulesViolationException("some rules violation message")).when(secretParamResolver).resolve(clusterProfile);
HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
clusterProfilesService.update(clusterProfile, new Username("Bob"), result);
assertThat(result.httpCode()).isEqualTo(422);
assertThat(result.message()).isEqualTo("Validations failed for clusterProfile 'prod_cluster'. Error(s): [some rules violation message]. Please correct and resubmit.");
}
use of com.thoughtworks.go.server.exceptions.RulesViolationException in project gocd by gocd.
the class PackageDefinitionServiceTest method shouldSetResultAsUnprocessableEntityIfRulesViolationForUpdate.
@Test
void shouldSetResultAsUnprocessableEntityIfRulesViolationForUpdate() {
PackageDefinition packageDefinition = PackageDefinitionMother.create("1", "name", new Configuration(), packageRepository);
HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
doThrow(new RulesViolationException("some rule violation 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 rule violation message");
}
use of com.thoughtworks.go.server.exceptions.RulesViolationException in project gocd by gocd.
the class RulesService method validateSecretConfigReferences.
public boolean validateSecretConfigReferences(ScmMaterial scmMaterial) {
List<CaseInsensitiveString> pipelines = goConfigService.pipelinesWithMaterial(scmMaterial.getFingerprint());
Map<CaseInsensitiveString, StringBuilder> pipelinesWithErrors = new HashMap<>();
pipelines.forEach(pipelineName -> {
MaterialConfig materialConfig = goConfigService.findPipelineByName(pipelineName).materialConfigs().getByMaterialFingerPrint(scmMaterial.getFingerprint());
PipelineConfigs group = goConfigService.findGroupByPipeline(pipelineName);
ScmMaterialConfig scmMaterialConfig = (ScmMaterialConfig) materialConfig;
SecretParams secretParams = SecretParams.parse(scmMaterialConfig.getPassword());
secretParams.forEach(secretParam -> {
String secretConfigId = secretParam.getSecretConfigId();
SecretConfig secretConfig = goConfigService.getSecretConfigById(secretConfigId);
if (secretConfig == null) {
addError(pipelinesWithErrors, pipelineName, format("Pipeline '%s' is referring to none-existent secret config '%s'.", pipelineName, secretConfigId));
} else if (!secretConfig.canRefer(group.getClass(), group.getGroup())) {
addError(pipelinesWithErrors, pipelineName, format("Pipeline '%s' does not have permission to refer to secrets using secret config '%s'", pipelineName, secretConfigId));
}
});
});
if (!pipelinesWithErrors.isEmpty()) {
LOGGER.debug("[Material Update] Failure: {}", errorString(pipelinesWithErrors));
}
if (pipelines.size() == pipelinesWithErrors.size()) {
throw new RulesViolationException(errorString(pipelinesWithErrors));
}
return true;
}
use of com.thoughtworks.go.server.exceptions.RulesViolationException in project gocd by gocd.
the class PackageRepositoryServiceTest method shouldSetResultAsUnprocessableEntityIfRulesViolationForUpdate.
@Test
void shouldSetResultAsUnprocessableEntityIfRulesViolationForUpdate() {
HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
doThrow(new RulesViolationException("some rule violation 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 rule violation message");
}
Aggregations