Search in sources :

Example 71 with GoConfigMother

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<>()));
}
Also used : Username(com.thoughtworks.go.server.domain.Username) ArrayList(java.util.ArrayList) GoConfigMother(com.thoughtworks.go.helper.GoConfigMother) Test(org.junit.jupiter.api.Test)

Example 72 with GoConfigMother

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));
}
Also used : Username(com.thoughtworks.go.server.domain.Username) ArrayList(java.util.ArrayList) GoConfigMother(com.thoughtworks.go.helper.GoConfigMother) Test(org.junit.jupiter.api.Test)

Example 73 with GoConfigMother

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));
}
Also used : Username(com.thoughtworks.go.server.domain.Username) ArrayList(java.util.ArrayList) GoConfigMother(com.thoughtworks.go.helper.GoConfigMother) Test(org.junit.jupiter.api.Test)

Example 74 with GoConfigMother

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));
}
Also used : Username(com.thoughtworks.go.server.domain.Username) ArrayList(java.util.ArrayList) GoConfigMother(com.thoughtworks.go.helper.GoConfigMother) Test(org.junit.jupiter.api.Test)

Example 75 with GoConfigMother

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"));
}
Also used : ArrayList(java.util.ArrayList) GoConfigMother(com.thoughtworks.go.helper.GoConfigMother) Test(org.junit.jupiter.api.Test)

Aggregations

GoConfigMother (com.thoughtworks.go.helper.GoConfigMother)102 Test (org.junit.jupiter.api.Test)64 Username (com.thoughtworks.go.server.domain.Username)30 BeforeEach (org.junit.jupiter.api.BeforeEach)19 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)15 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)13 GoConfigValidity (com.thoughtworks.go.config.validation.GoConfigValidity)12 File (java.io.File)9 ArrayList (java.util.ArrayList)9 Test (org.junit.Test)9 MaterialConfigs (com.thoughtworks.go.config.materials.MaterialConfigs)8 PartialConfig (com.thoughtworks.go.config.remote.PartialConfig)8 ByteArrayOutputStream (java.io.ByteArrayOutputStream)7 SCM (com.thoughtworks.go.domain.scm.SCM)4 CruiseConfig (com.thoughtworks.go.config.CruiseConfig)3 GoConfigInvalidException (com.thoughtworks.go.config.exceptions.GoConfigInvalidException)3 SvnMaterialConfig (com.thoughtworks.go.config.materials.svn.SvnMaterialConfig)3 FullConfigUpdateCommand (com.thoughtworks.go.config.update.FullConfigUpdateCommand)3 Configuration (com.thoughtworks.go.domain.config.Configuration)3 PackageRepositories (com.thoughtworks.go.domain.packagerepository.PackageRepositories)3