use of com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult in project gocd by gocd.
the class ScheduleServiceSecurityTest method shouldCancelStageGivenValidPipelineAndStageName.
@Test
public void shouldCancelStageGivenValidPipelineAndStageName() throws Exception {
configHelper.addSecurityWithAdminConfig();
Username user = UserHelper.getUserName();
configHelper.setOperatePermissionForGroup("defaultGroup", user.getUsername().toString());
Pipeline pipeline = fixture.createPipelineWithFirstStagePassedAndSecondStageRunning();
HttpLocalizedOperationResult operationResult = new HttpLocalizedOperationResult();
Stage stageForCancellation = pipeline.getStages().byName(fixture.ftStage);
Stage resultStage = scheduleService.cancelAndTriggerRelevantStages(pipeline.getName(), stageForCancellation.getName(), user, operationResult);
assertThat(resultStage, is(not(nullValue())));
assertThat(operationResult.isSuccessful(), is(true));
assertThat(operationResult.httpCode(), is(SC_OK));
}
use of com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult in project gocd by gocd.
the class ScheduleServiceSecurityTest method shouldReturnAppropriateHttpResultIfUserDoesNotHaveOperatePermission.
@Test
public void shouldReturnAppropriateHttpResultIfUserDoesNotHaveOperatePermission() throws Exception {
configHelper.addSecurityWithAdminConfig();
configHelper.setOperatePermissionForGroup("defaultGroup", "jez");
Pipeline pipeline = fixture.createPipelineWithFirstStagePassedAndSecondStageRunning();
Username anonymous = new Username(new CaseInsensitiveString("anonymous"));
HttpLocalizedOperationResult operationResult = new HttpLocalizedOperationResult();
Stage resultStage = scheduleService.cancelAndTriggerRelevantStages(pipeline.getStages().byName(fixture.ftStage).getId(), anonymous, operationResult);
assertThat(resultStage, is(nullValue()));
assertThat(operationResult.isSuccessful(), is(false));
assertThat(operationResult.httpCode(), is(SC_UNAUTHORIZED));
}
use of com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult in project gocd by gocd.
the class PipelineStagesFeedServiceIntegrationTest method shouldReturnTheCorrectLocalizedMessage.
@Test
public void shouldReturnTheCorrectLocalizedMessage() {
FeedResolver feedResolver = new PipelineStagesFeedService(stageService, securityService).feedResolverFor("cruise");
HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
feedResolver.feed(new Username(new CaseInsensitiveString("evil_hacker")), result);
assertThat(result.message(localizer), is("User 'evil_hacker' does not have view permission on pipeline 'cruise'"));
}
use of com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult in project gocd by gocd.
the class UserServiceIntegrationTest method modifyRoles_shouldNotModifyRolesWhenActionIsNoChange.
@Test
public void modifyRoles_shouldNotModifyRolesWhenActionIsNoChange() throws Exception {
addUser(new User("user-1"));
// add it first
userService.modifyRolesAndUserAdminPrivileges(Arrays.asList("user-1"), new TriStateSelection(Admin.GO_SYSTEM_ADMIN, TriStateSelection.Action.nochange), Arrays.asList(new TriStateSelection("dev", TriStateSelection.Action.add)), new HttpLocalizedOperationResult());
// no change
userService.modifyRolesAndUserAdminPrivileges(Arrays.asList("user-1"), new TriStateSelection(Admin.GO_SYSTEM_ADMIN, TriStateSelection.Action.nochange), Arrays.asList(new TriStateSelection("dev", TriStateSelection.Action.nochange)), new HttpLocalizedOperationResult());
CruiseConfig cruiseConfig = goConfigDao.load();
assertThat(cruiseConfig.server().security().getRoles().findByName(new CaseInsensitiveString("dev")).hasMember(new CaseInsensitiveString("user-1")), is(true));
}
use of com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult in project gocd by gocd.
the class PackageDefinitionServiceIntegrationTest method shouldReturnTheExactLocalizeMessageIfItFailsToCreatePackageDefinition.
@Test
public void shouldReturnTheExactLocalizeMessageIfItFailsToCreatePackageDefinition() throws Exception {
String packageUuid = "random-uuid";
String packageName = "prettyjson";
Configuration configuration = new Configuration();
configuration.add(new ConfigurationProperty(new ConfigurationKey("PACKAGE_ID"), new ConfigurationValue("prettyjson")));
PackageDefinition packageDefinition = new PackageDefinition(packageUuid, packageName, configuration);
HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
HttpLocalizedOperationResult expectedResult = new HttpLocalizedOperationResult();
String repositoryId = "Id";
expectedResult.unprocessableEntity(LocalizedMessage.string("PACKAGE_REPOSITORY_NOT_FOUND", repositoryId));
assertNull(service.find(packageUuid));
service.createPackage(packageDefinition, repositoryId, user, result);
assertThat(result, is(expectedResult));
assertNull(service.find(packageUuid));
}
Aggregations