use of com.thoughtworks.go.helper.GoConfigMother in project gocd by gocd.
the class TemplateConfigServiceTest method shouldReturnAnEmptyListOfTemplatesForARegularUser.
@Test
public void shouldReturnAnEmptyListOfTemplatesForARegularUser() {
BasicCruiseConfig cruiseConfig = getCruiseConfigWithSecurityEnabled();
CaseInsensitiveString regularUser = new CaseInsensitiveString("view");
new GoConfigMother().addPipelineWithTemplate(cruiseConfig, "p1", "t1", "s1", "j1");
Username viewUser = new Username(regularUser);
when(goConfigService.getCurrentConfig()).thenReturn(cruiseConfig);
when(securityService.isAuthorizedToViewTemplate(new CaseInsensitiveString("t1"), viewUser)).thenReturn(false);
assertThat(service.getTemplatesList(viewUser), is(new ArrayList<>()));
}
use of com.thoughtworks.go.helper.GoConfigMother in project gocd by gocd.
the class TemplateConfigServiceTest method shouldReturnASubsetOfTemplatesWithAssociatedPipelinesForTemplateViewUser.
@Test
public void shouldReturnASubsetOfTemplatesWithAssociatedPipelinesForTemplateViewUser() {
BasicCruiseConfig cruiseConfig = getCruiseConfigWithSecurityEnabled();
CaseInsensitiveString templateViewUser = new CaseInsensitiveString("template-view");
new GoConfigMother().addPipelineWithTemplate(cruiseConfig, "p1", "t1", "s1", "j1");
PipelineTemplateConfig template2 = PipelineTemplateConfigMother.createTemplate("t2", new Authorization(new ViewConfig(new AdminUser(templateViewUser))), StageConfigMother.manualStage("foo"));
cruiseConfig.addTemplate(template2);
Username templateView = new Username(templateViewUser);
when(goConfigService.getCurrentConfig()).thenReturn(cruiseConfig);
when(securityService.isAuthorizedToViewTemplate(new CaseInsensitiveString("t2"), templateView)).thenReturn(true);
when(securityService.isAuthorizedToEditTemplate(new CaseInsensitiveString("t2"), templateView)).thenReturn(false);
when(securityService.isUserAdmin(templateView)).thenReturn(false);
List<TemplateToPipelines> templateToPipelines = new ArrayList<>();
TemplateToPipelines t2 = new TemplateToPipelines(new CaseInsensitiveString("t2"), false, false);
templateToPipelines.add(t2);
assertThat(service.getTemplatesList(templateView), is(templateToPipelines));
}
use of com.thoughtworks.go.helper.GoConfigMother in project gocd by gocd.
the class TemplateConfigServiceTest method shouldReturnAListOfTemplatesWithAssociatedPipelinesForAnAdminUser.
@Test
public void shouldReturnAListOfTemplatesWithAssociatedPipelinesForAnAdminUser() {
BasicCruiseConfig cruiseConfig = getCruiseConfigWithSecurityEnabled();
new GoConfigMother().addPipelineWithTemplate(cruiseConfig, "p1", "t1", "s1", "j1");
new GoConfigMother().addPipelineWithTemplate(cruiseConfig, "p2", "t2", "s2", "j2");
Username admin = new Username("admin");
when(goConfigService.getCurrentConfig()).thenReturn(cruiseConfig);
when(goConfigService.isPipelineEditable(new CaseInsensitiveString("p1"))).thenReturn(true);
when(goConfigService.isPipelineEditable(new CaseInsensitiveString("p2"))).thenReturn(true);
when(securityService.isAuthorizedToViewTemplate(new CaseInsensitiveString("t1"), admin)).thenReturn(true);
when(securityService.isAuthorizedToViewTemplate(new CaseInsensitiveString("t2"), admin)).thenReturn(true);
when(securityService.isAuthorizedToEditTemplate(new CaseInsensitiveString("t1"), admin)).thenReturn(true);
when(securityService.isAuthorizedToEditTemplate(new CaseInsensitiveString("t2"), admin)).thenReturn(true);
when(securityService.isUserAdmin(admin)).thenReturn(true);
List<TemplateToPipelines> templateToPipelines = new ArrayList<>();
TemplateToPipelines template1 = new TemplateToPipelines(new CaseInsensitiveString("t1"), true, true);
template1.add(new PipelineEditabilityInfo(new CaseInsensitiveString("p1"), true, true));
templateToPipelines.add(template1);
TemplateToPipelines template2 = new TemplateToPipelines(new CaseInsensitiveString("t2"), true, true);
template2.add(new PipelineEditabilityInfo(new CaseInsensitiveString("p2"), true, true));
templateToPipelines.add(template2);
assertThat(service.getTemplatesList(admin), is(templateToPipelines));
}
use of com.thoughtworks.go.helper.GoConfigMother in project gocd by gocd.
the class TemplateConfigServiceTest method shouldReturnASubsetOfTemplatesWithAssociatedPipelinesForTemplateAdmin.
@Test
public void shouldReturnASubsetOfTemplatesWithAssociatedPipelinesForTemplateAdmin() {
BasicCruiseConfig cruiseConfig = getCruiseConfigWithSecurityEnabled();
CaseInsensitiveString templateAdmin = new CaseInsensitiveString("template-admin");
new GoConfigMother().addPipelineWithTemplate(cruiseConfig, "p1", "t1", "s1", "j1");
PipelineTemplateConfig template2 = PipelineTemplateConfigMother.createTemplate("t2", new Authorization(new AdminsConfig(new AdminUser(templateAdmin))), StageConfigMother.manualStage("foo"));
cruiseConfig.addTemplate(template2);
Username admin = new Username(templateAdmin);
when(goConfigService.getCurrentConfig()).thenReturn(cruiseConfig);
when(securityService.isAuthorizedToViewTemplate(new CaseInsensitiveString("t2"), admin)).thenReturn(true);
when(securityService.isAuthorizedToEditTemplate(new CaseInsensitiveString("t2"), admin)).thenReturn(true);
when(securityService.isUserAdmin(admin)).thenReturn(false);
List<TemplateToPipelines> templateToPipelines = new ArrayList<>();
TemplateToPipelines t2 = new TemplateToPipelines(new CaseInsensitiveString("t2"), true, false);
templateToPipelines.add(t2);
assertThat(service.getTemplatesList(admin), is(templateToPipelines));
}
use of com.thoughtworks.go.helper.GoConfigMother in project gocd by gocd.
the class BasicCruiseConfigTest method shouldGetAllGroupsForUserInAnAdminRole.
@Test
public void shouldGetAllGroupsForUserInAnAdminRole() {
GoConfigMother goConfigMother = new GoConfigMother();
BasicCruiseConfig cruiseConfig = GoConfigMother.defaultCruiseConfig();
goConfigMother.addPipelineWithGroup(cruiseConfig, "group", "p1", "s1", "j1");
GoConfigMother.enableSecurityWithPasswordFilePlugin(cruiseConfig);
Role role = goConfigMother.createRole("role1", "foo", "bar");
cruiseConfig.server().security().addRole(role);
goConfigMother.addRoleAsSuperAdmin(cruiseConfig, "role1");
ArrayList<Role> roles = new ArrayList<>();
roles.add(role);
List<String> groupsForUser = cruiseConfig.getGroupsForUser(new CaseInsensitiveString("foo"), roles);
assertThat(groupsForUser, contains("group"));
}
Aggregations