Search in sources :

Example 56 with Username

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")));
}
Also used : Username(com.thoughtworks.go.server.domain.Username) LocalizedOperationResult(com.thoughtworks.go.server.service.result.LocalizedOperationResult) Test(org.junit.Test)

Example 57 with Username

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"));
}
Also used : PipelineGroups(com.thoughtworks.go.domain.PipelineGroups) Username(com.thoughtworks.go.server.domain.Username) Test(org.junit.Test)

Example 58 with Username

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"));
}
Also used : PipelineGroups(com.thoughtworks.go.domain.PipelineGroups) Username(com.thoughtworks.go.server.domain.Username) Test(org.junit.Test)

Example 59 with Username

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));
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) Username(com.thoughtworks.go.server.domain.Username) ElasticProfile(com.thoughtworks.go.config.elastic.ElasticProfile) Test(org.junit.Test)

Example 60 with Username

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."));
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) Username(com.thoughtworks.go.server.domain.Username) PluginNotFoundException(com.thoughtworks.go.plugin.access.PluginNotFoundException) ElasticProfile(com.thoughtworks.go.config.elastic.ElasticProfile) Test(org.junit.Test)

Aggregations

Username (com.thoughtworks.go.server.domain.Username)391 Test (org.junit.Test)317 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)170 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)81 Before (org.junit.Before)42 HttpOperationResult (com.thoughtworks.go.server.service.result.HttpOperationResult)36 GoConfigMother (com.thoughtworks.go.helper.GoConfigMother)33 Pipeline (com.thoughtworks.go.domain.Pipeline)30 MaterialRevision (com.thoughtworks.go.domain.MaterialRevision)27 PipelineMaterialRevision (com.thoughtworks.go.domain.PipelineMaterialRevision)21 StringContains.containsString (org.hamcrest.core.StringContains.containsString)20 Modification (com.thoughtworks.go.domain.materials.Modification)17 ArrayList (java.util.ArrayList)16 PackageRepository (com.thoughtworks.go.domain.packagerepository.PackageRepository)15 DependencyMaterial (com.thoughtworks.go.config.materials.dependency.DependencyMaterial)14 TimeProvider (com.thoughtworks.go.util.TimeProvider)13 UpdateConfigFromUI (com.thoughtworks.go.config.update.UpdateConfigFromUI)12 Date (java.util.Date)12 SvnMaterial (com.thoughtworks.go.config.materials.svn.SvnMaterial)11 ConfigUpdateResponse (com.thoughtworks.go.config.update.ConfigUpdateResponse)10