Search in sources :

Example 6 with Username

use of com.thoughtworks.go.server.domain.Username in project gocd by gocd.

the class ScheduleServiceSecurityTest method shouldReturnAppropriateHttpResultIfTheStageIsInvalid.

@Test
public void shouldReturnAppropriateHttpResultIfTheStageIsInvalid() throws Exception {
    configHelper.addSecurityWithAdminConfig();
    configHelper.setOperatePermissionForGroup("defaultGroup", "jez");
    Username jez = new Username(new CaseInsensitiveString("jez"));
    HttpLocalizedOperationResult operationResult = new HttpLocalizedOperationResult();
    Stage resultStage = scheduleService.cancelAndTriggerRelevantStages(-23l, jez, operationResult);
    assertThat(resultStage, is(nullValue()));
    assertThat(operationResult.isSuccessful(), is(false));
    assertThat(operationResult.httpCode(), is(SC_NOT_FOUND));
}
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) Test(org.junit.Test)

Example 7 with Username

use of com.thoughtworks.go.server.domain.Username 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 8 with Username

use of com.thoughtworks.go.server.domain.Username 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 9 with Username

use of com.thoughtworks.go.server.domain.Username in project gocd by gocd.

the class PipelineServiceTriangleDependencyTest method shouldNotGetTheRevisionsFromUpStreamPipelineIfTheDependencyMaterialHasNotChanged.

@Test
public void shouldNotGetTheRevisionsFromUpStreamPipelineIfTheDependencyMaterialHasNotChanged() throws Exception {
    MaterialRevisions expected = createHgMaterialWithMultipleRevisions(1L, first);
    MaterialRevision up1Revision = dependencyMaterialRevision("up1", 1, "label", "stage", 1, new Date());
    expected.addRevision(up1Revision);
    MaterialRevisions actual = createHgMaterialWithMultipleRevisions(1L, third);
    actual.addRevision(up1Revision);
    up1Revision.markAsNotChanged();
    PipelineConfig current = createPipelineConfigWithMaterialConfig("current", actual.getMaterials().get(0).config(), new DependencyMaterialConfig(new CaseInsensitiveString("up1"), new CaseInsensitiveString("first")));
    PipelineConfig up1 = createPipelineConfigWithMaterialConfig("up1", expected.getMaterials().get(0).config());
    when(pipelineDao.findBuildCauseOfPipelineByNameAndCounter("up1", 1)).thenReturn(BuildCause.createManualForced(expected, new Username(str("loser"))));
    PipelineConfigDependencyGraph dependencyGraph = new PipelineConfigDependencyGraph(current, new PipelineConfigDependencyGraph(up1));
    assertThat(service.getRevisionsBasedOnDependencies(dependencyGraph, actual), is(actual));
}
Also used : PipelineConfigDependencyGraph(com.thoughtworks.go.server.domain.PipelineConfigDependencyGraph) PipelineConfig(com.thoughtworks.go.config.PipelineConfig) Username(com.thoughtworks.go.server.domain.Username) MaterialRevisions(com.thoughtworks.go.domain.MaterialRevisions) MaterialRevision(com.thoughtworks.go.domain.MaterialRevision) ModificationsMother.dependencyMaterialRevision(com.thoughtworks.go.helper.ModificationsMother.dependencyMaterialRevision) ModificationsMother.changedDependencyMaterialRevision(com.thoughtworks.go.helper.ModificationsMother.changedDependencyMaterialRevision) DependencyMaterialConfig(com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig) Date(java.util.Date) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Test(org.junit.Test)

Example 10 with Username

use of com.thoughtworks.go.server.domain.Username 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)

Aggregations

Username (com.thoughtworks.go.server.domain.Username)331 Test (org.junit.Test)268 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)133 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)84 Before (org.junit.Before)39 HttpOperationResult (com.thoughtworks.go.server.service.result.HttpOperationResult)35 Pipeline (com.thoughtworks.go.domain.Pipeline)34 MaterialRevision (com.thoughtworks.go.domain.MaterialRevision)28 PipelineMaterialRevision (com.thoughtworks.go.domain.PipelineMaterialRevision)21 StringContains.containsString (org.hamcrest.core.StringContains.containsString)20 GoConfigMother (com.thoughtworks.go.helper.GoConfigMother)18 PipelineInstanceModels (com.thoughtworks.go.presentation.pipelinehistory.PipelineInstanceModels)18 Modification (com.thoughtworks.go.domain.materials.Modification)17 PackageRepository (com.thoughtworks.go.domain.packagerepository.PackageRepository)15 PipelineInstanceModel (com.thoughtworks.go.presentation.pipelinehistory.PipelineInstanceModel)15 ArrayList (java.util.ArrayList)15 DependencyMaterial (com.thoughtworks.go.config.materials.dependency.DependencyMaterial)14 EmptyPipelineInstanceModel (com.thoughtworks.go.presentation.pipelinehistory.EmptyPipelineInstanceModel)13 UpdateConfigFromUI (com.thoughtworks.go.config.update.UpdateConfigFromUI)12 Date (java.util.Date)12