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));
}
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();
}
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");
}
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);
}
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");
}
Aggregations