Search in sources :

Example 71 with Username

use of com.thoughtworks.go.server.domain.Username in project gocd by gocd.

the class EnvironmentServiceTest method shouldReturnPipelineHistoryForPipelinesInAnEnvironment.

@Test
public void shouldReturnPipelineHistoryForPipelinesInAnEnvironment() throws Exception {
    Username username = new Username(new CaseInsensitiveString("Foo"));
    when(environmentConfigService.pipelinesFor(new CaseInsensitiveString("uat"))).thenReturn(Arrays.asList(new CaseInsensitiveString("uat-pipeline"), new CaseInsensitiveString("staging-pipeline")));
    PipelineInstanceModel uatInstance = stubPipelineHistoryServiceToReturnPipelines("uat-pipeline");
    PipelineInstanceModel stagingInstance = stubPipelineHistoryServiceToReturnPipelines("staging-pipeline");
    ArrayList<Environment> environments = new ArrayList<>();
    environmentService.addEnvironmentFor(new CaseInsensitiveString("uat"), username, environments);
    assertThat(environments.size(), is(1));
    Environment environment = environments.get(0);
    assertThat(environment.getName(), is("uat"));
    List<PipelineModel> models = environment.getPipelineModels();
    assertThat(models.size(), is(2));
    PipelineModel model1 = new PipelineModel(uatInstance.getName(), true, true, PipelinePauseInfo.notPaused());
    model1.addPipelineInstance(uatInstance);
    assertThat(models, hasItem(model1));
    PipelineModel model2 = new PipelineModel(stagingInstance.getName(), true, true, PipelinePauseInfo.notPaused());
    model2.addPipelineInstance(stagingInstance);
    assertThat(models, hasItem(model2));
}
Also used : Username(com.thoughtworks.go.server.domain.Username) PipelineInstanceModel(com.thoughtworks.go.presentation.pipelinehistory.PipelineInstanceModel) ArrayList(java.util.ArrayList) Environment(com.thoughtworks.go.presentation.pipelinehistory.Environment) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) PipelineModel(com.thoughtworks.go.presentation.pipelinehistory.PipelineModel) Test(org.junit.Test)

Example 72 with Username

use of com.thoughtworks.go.server.domain.Username in project gocd by gocd.

the class FailureServiceTest method setUp.

@Before
public void setUp() {
    shineDao = mock(ShineDao.class);
    securityService = mock(SecurityService.class);
    stageFinder = mock(StageFinder.class);
    failureService = new FailureService(securityService, shineDao, stageFinder);
    username = new Username(new CaseInsensitiveString("foo"));
    jobIdentifier = new JobIdentifier(new StageIdentifier("pipeline", 10, "stage", "5"), "job");
    result = new HttpLocalizedOperationResult();
}
Also used : StageIdentifier(com.thoughtworks.go.domain.StageIdentifier) HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) ShineDao(com.thoughtworks.go.server.dao.sparql.ShineDao) Username(com.thoughtworks.go.server.domain.Username) JobIdentifier(com.thoughtworks.go.domain.JobIdentifier) StageFinder(com.thoughtworks.go.domain.StageFinder) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Before(org.junit.Before)

Example 73 with Username

use of com.thoughtworks.go.server.domain.Username in project gocd by gocd.

the class PipelineConfigsServiceTest method setUp.

@Before
public void setUp() {
    goConfigService = mock(GoConfigService.class);
    securityService = mock(SecurityService.class);
    configCache = new ConfigCache();
    registry = ConfigElementImplementationRegistryMother.withNoPlugins();
    validUser = new Username(new CaseInsensitiveString("validUser"));
    service = new PipelineConfigsService(configCache, registry, goConfigService, securityService);
    result = new HttpLocalizedOperationResult();
    cruiseConfig = new BasicCruiseConfig();
    ReflectionUtil.setField(cruiseConfig, "md5", "md5");
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) Username(com.thoughtworks.go.server.domain.Username) Before(org.junit.Before)

Example 74 with Username

use of com.thoughtworks.go.server.domain.Username in project gocd by gocd.

the class PipelineConfigsServiceTest method shouldReturnUnauthorizedResultWhenUserIsNotAuthorizedToViewGroup_onUpdateXml.

@Test
public void shouldReturnUnauthorizedResultWhenUserIsNotAuthorizedToViewGroup_onUpdateXml() throws Exception {
    String groupName = "some-secret-group";
    Localizer localizer = mock(Localizer.class);
    when(localizer.localize("UNAUTHORIZED_TO_EDIT_GROUP", groupName)).thenReturn("Unauthorized!");
    Username invalidUser = new Username(new CaseInsensitiveString("invalidUser"));
    when(securityService.isUserAdminOfGroup(invalidUser.getUsername(), groupName)).thenReturn(false);
    when(goConfigService.configFileMd5()).thenReturn("md5");
    GoConfigOperationalResponse<PipelineConfigs> actual = service.updateXml(groupName, "", "md5", invalidUser, result);
    PipelineConfigs configElement = actual.getConfigElement();
    GoConfigValidity validity = actual.getValidity();
    assertThat(configElement, is(nullValue()));
    assertThat(result.httpCode(), is(401));
    assertThat(result.isSuccessful(), is(false));
    assertThat(result.message(localizer), is("Unauthorized!"));
    assertThat(validity.isValid(), is(true));
    verify(securityService, times(1)).isUserAdminOfGroup(invalidUser.getUsername(), groupName);
}
Also used : Username(com.thoughtworks.go.server.domain.Username) Localizer(com.thoughtworks.go.i18n.Localizer) GoConfigValidity(com.thoughtworks.go.config.validation.GoConfigValidity) Test(org.junit.Test)

Example 75 with Username

use of com.thoughtworks.go.server.domain.Username in project gocd by gocd.

the class PipelineHistoryServiceTest method shouldRestrictAdminPermissionOnRemotePipelines.

@Test
public void shouldRestrictAdminPermissionOnRemotePipelines() throws Exception {
    when(goConfigService.isPipelineEditable(any(String.class))).thenReturn(false);
    Username jez = new Username(new CaseInsensitiveString("jez"));
    setupExpectationsForAllActivePipelinesWithTwoGroups(jez);
    when(goConfigService.isUserAdminOfGroup(jez.getUsername(), "defaultGroup")).thenReturn(true);
    when(goConfigService.isUserAdminOfGroup(jez.getUsername(), "foo")).thenReturn(false);
    List<PipelineGroupModel> groups = pipelineHistoryService.allActivePipelineInstances(jez, PipelineSelections.ALL);
    assertThat(groups.get(0).getPipelineModels().get(0).canAdminister(), is(false));
    assertThat(groups.get(0).getPipelineModels().get(1).canAdminister(), is(false));
    assertThat(groups.get(1).getPipelineModels().get(0).canAdminister(), is(false));
    verify(goConfigService, times(1)).isUserAdminOfGroup(jez.getUsername(), "defaultGroup");
    verify(goConfigService, times(1)).isUserAdminOfGroup(jez.getUsername(), "foo");
}
Also used : Username(com.thoughtworks.go.server.domain.Username) 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