Search in sources :

Example 1 with PipelineInstanceModels.createPipelineInstanceModels

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));
}
Also used : HttpOperationResult(com.thoughtworks.go.server.service.result.HttpOperationResult) PipelineInstanceModels.createPipelineInstanceModels(com.thoughtworks.go.presentation.pipelinehistory.PipelineInstanceModels.createPipelineInstanceModels) Username(com.thoughtworks.go.server.domain.Username) Test(org.junit.Test)

Aggregations

PipelineInstanceModels.createPipelineInstanceModels (com.thoughtworks.go.presentation.pipelinehistory.PipelineInstanceModels.createPipelineInstanceModels)1 Username (com.thoughtworks.go.server.domain.Username)1 HttpOperationResult (com.thoughtworks.go.server.service.result.HttpOperationResult)1 Test (org.junit.Test)1