Search in sources :

Example 6 with HttpLocalizedOperationResult

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));
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) Username(com.thoughtworks.go.server.domain.Username) Stage(com.thoughtworks.go.domain.Stage) Pipeline(com.thoughtworks.go.domain.Pipeline) Test(org.junit.Test)

Example 7 with HttpLocalizedOperationResult

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));
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) Username(com.thoughtworks.go.server.domain.Username) Stage(com.thoughtworks.go.domain.Stage) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Pipeline(com.thoughtworks.go.domain.Pipeline) Test(org.junit.Test)

Example 8 with HttpLocalizedOperationResult

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'"));
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) Username(com.thoughtworks.go.server.domain.Username) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Test(org.junit.Test)

Example 9 with HttpLocalizedOperationResult

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));
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) TriStateSelection(com.thoughtworks.go.presentation.TriStateSelection) Test(org.junit.Test)

Example 10 with HttpLocalizedOperationResult

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));
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) ContextConfiguration(org.springframework.test.context.ContextConfiguration) PackageDefinition(com.thoughtworks.go.domain.packagerepository.PackageDefinition) Test(org.junit.Test)

Aggregations

HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)361 Test (org.junit.Test)329 Username (com.thoughtworks.go.server.domain.Username)131 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)36 Pipeline (com.thoughtworks.go.domain.Pipeline)27 ArrayList (java.util.ArrayList)27 Before (org.junit.Before)22 MaterialRevision (com.thoughtworks.go.domain.MaterialRevision)20 PipelineMaterialRevision (com.thoughtworks.go.domain.PipelineMaterialRevision)20 PackageRepository (com.thoughtworks.go.domain.packagerepository.PackageRepository)19 SecurityAuthConfig (com.thoughtworks.go.config.SecurityAuthConfig)17 ConfigUpdateResponse (com.thoughtworks.go.config.update.ConfigUpdateResponse)17 AgentInstance (com.thoughtworks.go.domain.AgentInstance)17 UserSearchModel (com.thoughtworks.go.presentation.UserSearchModel)16 Matchers.containsString (org.hamcrest.Matchers.containsString)16 GoConfigMother (com.thoughtworks.go.helper.GoConfigMother)15 GoCipher (com.thoughtworks.go.security.GoCipher)14 SystemEnvironment (com.thoughtworks.go.util.SystemEnvironment)14 DependencyMaterial (com.thoughtworks.go.config.materials.dependency.DependencyMaterial)13 PackageRepositories (com.thoughtworks.go.domain.packagerepository.PackageRepositories)12