use of com.thoughtworks.go.server.domain.Username in project gocd by gocd.
the class MaterialServiceTest method shouldNotBeAuthorizedToViewAPipeline.
@Test
public void shouldNotBeAuthorizedToViewAPipeline() {
Username pavan = Username.valueOf("pavan");
when(securityService.hasViewPermissionForPipeline(pavan, "pipeline")).thenReturn(false);
LocalizedOperationResult operationResult = mock(LocalizedOperationResult.class);
materialService.searchRevisions("pipeline", "sha", "search-string", pavan, operationResult);
verify(operationResult).unauthorized(LocalizedMessage.cannotViewPipeline("pipeline"), HealthStateType.general(HealthStateScope.forPipeline("pipeline")));
}
use of com.thoughtworks.go.server.domain.Username in project gocd by gocd.
the class PipelineConfigServiceTest method shouldGetAllViewableOrOperatablePipelineConfigs.
@Test
public void shouldGetAllViewableOrOperatablePipelineConfigs() throws Exception {
CruiseConfig cruiseConfig = mock(BasicCruiseConfig.class);
PipelineConfig p1 = PipelineConfigMother.pipelineConfig("P1");
PipelineConfig p2 = PipelineConfigMother.pipelineConfig("P2");
PipelineConfig p3 = PipelineConfigMother.pipelineConfig("P3");
Username username = new Username(new CaseInsensitiveString("user"));
when(goConfigService.cruiseConfig()).thenReturn(cruiseConfig);
when(cruiseConfig.getGroups()).thenReturn(new PipelineGroups(new BasicPipelineConfigs("group1", null, p1), new BasicPipelineConfigs("group2", null, p2), new BasicPipelineConfigs("group3", null, p3)));
when(securityService.hasViewPermissionForGroup(CaseInsensitiveString.str(username.getUsername()), "group1")).thenReturn(true);
when(securityService.hasViewPermissionForGroup(CaseInsensitiveString.str(username.getUsername()), "group2")).thenReturn(false);
when(securityService.hasOperatePermissionForGroup(username.getUsername(), "group2")).thenReturn(false);
when(securityService.hasViewPermissionForGroup(CaseInsensitiveString.str(username.getUsername()), "group3")).thenReturn(false);
when(securityService.hasOperatePermissionForGroup(username.getUsername(), "group3")).thenReturn(true);
List<PipelineConfigs> pipelineConfigs = pipelineConfigService.viewableOrOperatableGroupsFor(username);
assertThat(pipelineConfigs.size(), is(2));
assertThat(pipelineConfigs.get(0).getGroup(), is("group1"));
assertThat(pipelineConfigs.get(1).getGroup(), is("group3"));
}
use of com.thoughtworks.go.server.domain.Username in project gocd by gocd.
the class PipelineConfigServiceTest method shouldGetAllViewablePipelineConfigs.
@Test
public void shouldGetAllViewablePipelineConfigs() throws Exception {
CruiseConfig cruiseConfig = mock(BasicCruiseConfig.class);
PipelineConfig p1 = PipelineConfigMother.pipelineConfig("P1");
PipelineConfig p2 = PipelineConfigMother.pipelineConfig("P2");
Username username = new Username(new CaseInsensitiveString("user"));
when(goConfigService.cruiseConfig()).thenReturn(cruiseConfig);
when(cruiseConfig.getGroups()).thenReturn(new PipelineGroups(new BasicPipelineConfigs("group1", null, p1), new BasicPipelineConfigs("group2", null, p2)));
when(securityService.hasViewPermissionForGroup(CaseInsensitiveString.str(username.getUsername()), "group1")).thenReturn(true);
when(securityService.hasViewPermissionForGroup(CaseInsensitiveString.str(username.getUsername()), "group2")).thenReturn(false);
List<PipelineConfigs> pipelineConfigs = pipelineConfigService.viewableOrOperatableGroupsFor(username);
assertThat(pipelineConfigs.size(), is(1));
assertThat(pipelineConfigs.get(0).getGroup(), is("group1"));
}
use of com.thoughtworks.go.server.domain.Username in project gocd by gocd.
the class ElasticProfileServiceTest method shouldPerformPluginValidationsBeforeUpdatingElasticProfile.
@Test
public void shouldPerformPluginValidationsBeforeUpdatingElasticProfile() {
ElasticProfile elasticProfile = new ElasticProfile("ldap", "cd.go.ldap", create("key", false, "value"));
Username username = new Username("username");
elasticProfileService.update(username, "md5", elasticProfile, new HttpLocalizedOperationResult());
verify(elasticAgentExtension).validate(elasticProfile.getPluginId(), elasticProfile.getConfigurationAsMap(true));
}
use of com.thoughtworks.go.server.domain.Username in project gocd by gocd.
the class ElasticProfileServiceTest method shouldAddPluginNotFoundErrorOnConfigForANonExistentPluginIdWhileUpdating.
@Test
public void shouldAddPluginNotFoundErrorOnConfigForANonExistentPluginIdWhileUpdating() throws Exception {
ElasticProfile elasticProfile = new ElasticProfile("some-id", "non-existent-plugin", create("key", false, "value"));
Username username = new Username("username");
when(elasticAgentExtension.validate(elasticProfile.getPluginId(), elasticProfile.getConfigurationAsMap(true))).thenThrow(new PluginNotFoundException("some error"));
elasticProfileService.update(username, "md5", elasticProfile, new HttpLocalizedOperationResult());
assertThat(elasticProfile.errors().isEmpty(), Matchers.is(false));
assertThat(elasticProfile.errors().on("pluginId"), Matchers.is("Plugin with id `non-existent-plugin` is not found."));
}
Aggregations