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));
}
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));
}
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));
}
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));
}
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'"));
}
Aggregations