use of com.thoughtworks.go.presentation.pipelinehistory.PipelineInstanceModels.createPipelineInstanceModels in project gocd by gocd.
the class PipelineHistoryServiceTest method shouldPopulateResultAsUnauthorizedWhenUserNotAllowedToViewPipeline_loadMinimalData.
@Test
public void shouldPopulateResultAsUnauthorizedWhenUserNotAllowedToViewPipeline_loadMinimalData() {
Username noAccessUserName = new Username(new CaseInsensitiveString("foo"));
Username withAccessUserName = new Username(new CaseInsensitiveString("admin"));
String pipelineName = "no-access-pipeline";
CruiseConfig cruiseConfig = mock(BasicCruiseConfig.class);
when(cruiseConfig.hasPipelineNamed(new CaseInsensitiveString(pipelineName))).thenReturn(true);
when(goConfigService.currentCruiseConfig()).thenReturn(cruiseConfig);
when(securityService.hasViewPermissionForPipeline(noAccessUserName, pipelineName)).thenReturn(false);
when(securityService.hasViewPermissionForPipeline(withAccessUserName, pipelineName)).thenReturn(true);
when(pipelineDao.loadHistory(pipelineName, 10, 0)).thenReturn(PipelineInstanceModels.createPipelineInstanceModels());
HttpOperationResult result = new HttpOperationResult();
PipelineInstanceModels pipelineInstanceModels = pipelineHistoryService.loadMinimalData(pipelineName, Pagination.pageFor(0, 1, 10), noAccessUserName, result);
assertThat(pipelineInstanceModels, is(nullValue()));
assertThat(result.httpCode(), is(401));
result = new HttpOperationResult();
pipelineInstanceModels = pipelineHistoryService.loadMinimalData(pipelineName, Pagination.pageFor(0, 1, 10), withAccessUserName, result);
assertThat(pipelineInstanceModels, is(not(nullValue())));
assertThat(result.canContinue(), is(true));
}
Aggregations