Search in sources :

Example 31 with Username

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

the class SecurityServiceTest method shouldReturnTrueForGroupAdminsToViewTemplateConfigurationByDefault.

@Test
public void shouldReturnTrueForGroupAdminsToViewTemplateConfigurationByDefault() {
    CruiseConfig config = getCruiseConfigWithSecurityEnabled();
    CaseInsensitiveString groupAdmin = new CaseInsensitiveString("groupAdmin");
    setUpGroupWithAuthorization(config, new Authorization(new AdminsConfig(new AdminUser(groupAdmin))));
    CaseInsensitiveString templateName = new CaseInsensitiveString("template");
    config.addTemplate(createTemplate("template"));
    when(goConfigService.cruiseConfig()).thenReturn(config);
    when(goConfigService.isUserAdmin(new Username(groupAdmin))).thenReturn(false);
    when(goConfigService.isGroupAdministrator(groupAdmin)).thenReturn(true);
    assertThat(securityService.isAuthorizedToViewTemplate(templateName, new Username(groupAdmin)), is(true));
}
Also used : Username(com.thoughtworks.go.server.domain.Username) Test(org.junit.Test)

Example 32 with Username

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

the class SecurityServiceTest method shouldSayThatAUserIsAuthorizedToViewAndEditTemplatesWhenTheUserHasPermissionsForAtLeastOneTemplate.

@Test
public void shouldSayThatAUserIsAuthorizedToViewAndEditTemplatesWhenTheUserHasPermissionsForAtLeastOneTemplate() throws Exception {
    CruiseConfig config = new BasicCruiseConfig();
    String theSuperAdmin = "theSuperAdmin";
    String templateName = "template";
    String secondTemplateName = "secondTemplate";
    CaseInsensitiveString templateAdminName = new CaseInsensitiveString("templateAdmin");
    CaseInsensitiveString secondTemplateAdminName = new CaseInsensitiveString("secondTemplateAdmin");
    GoConfigMother.enableSecurityWithPasswordFilePlugin(config);
    GoConfigMother.addUserAsSuperAdmin(config, theSuperAdmin);
    config.addTemplate(createTemplate(templateName, new Authorization(new AdminsConfig(new AdminUser(templateAdminName)))));
    config.addTemplate(createTemplate(secondTemplateName, new Authorization(new AdminsConfig(new AdminUser(secondTemplateAdminName)))));
    when(goConfigService.cruiseConfig()).thenReturn(config);
    when(goConfigService.isUserAdmin(new Username(templateAdminName))).thenReturn(false);
    when(goConfigService.isUserAdmin(new Username(secondTemplateName))).thenReturn(false);
    when(goConfigService.isUserAdmin(new Username(new CaseInsensitiveString(theSuperAdmin)))).thenReturn(true);
    when(goConfigService.isUserAdmin(new Username(new CaseInsensitiveString("someOtherUserWhoIsNotAdminOfAnyTemplates")))).thenReturn(false);
    assertThat(securityService.isAuthorizedToViewAndEditTemplates(new Username(templateAdminName)), is(true));
    assertThat(securityService.isAuthorizedToViewAndEditTemplates(new Username(secondTemplateAdminName)), is(true));
    assertThat(securityService.isAuthorizedToViewAndEditTemplates(new Username(new CaseInsensitiveString(theSuperAdmin))), is(true));
    assertThat(securityService.isAuthorizedToViewAndEditTemplates(new Username(new CaseInsensitiveString("someOtherUserWhoIsNotAdminOfAnyTemplates"))), is(false));
}
Also used : Username(com.thoughtworks.go.server.domain.Username) Test(org.junit.Test)

Example 33 with Username

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

the class SecurityServiceTest method shouldReturnFalseForViewingAdminPageForARegularUser.

@Test
public void shouldReturnFalseForViewingAdminPageForARegularUser() {
    final Username user = new Username(new CaseInsensitiveString("user"));
    CruiseConfig config = new BasicCruiseConfig();
    when(goConfigService.cruiseConfig()).thenReturn(config);
    when(goConfigService.isUserAdmin(user)).thenReturn(false);
    when(goConfigService.isGroupAdministrator(user.getUsername())).thenReturn(false);
    when(goConfigService.isSecurityEnabled()).thenReturn(true);
    SecurityService spy = spy(securityService);
    doReturn(false).when(spy).isAuthorizedToViewAndEditTemplates(user);
    doReturn(false).when(spy).isAuthorizedToViewTemplates(user);
    assertThat(spy.canViewAdminPage(user), is(false));
}
Also used : Username(com.thoughtworks.go.server.domain.Username) Test(org.junit.Test)

Example 34 with Username

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

the class SecurityServiceTest method shouldSayThatAUserIsAuthorizedToEditTemplateWhenTheUserIsASuperAdmin.

@Test
public void shouldSayThatAUserIsAuthorizedToEditTemplateWhenTheUserIsASuperAdmin() throws Exception {
    CruiseConfig cruiseConfig = new BasicCruiseConfig();
    String adminName = "theSuperAdmin";
    CaseInsensitiveString templateName = new CaseInsensitiveString("template");
    GoConfigMother.enableSecurityWithPasswordFilePlugin(cruiseConfig);
    GoConfigMother.addUserAsSuperAdmin(cruiseConfig, adminName).addTemplate(createTemplate("template"));
    when(goConfigService.cruiseConfig()).thenReturn(cruiseConfig);
    when(goConfigService.isUserAdmin(new Username(new CaseInsensitiveString(adminName)))).thenReturn(true);
    assertThat(securityService.isAuthorizedToEditTemplate(templateName, new Username(new CaseInsensitiveString(adminName))), is(true));
}
Also used : Username(com.thoughtworks.go.server.domain.Username) Test(org.junit.Test)

Example 35 with Username

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

the class SecurityServiceTest method shouldBeAbleToTellIfAUserIsAnAdmin.

@Test
public void shouldBeAbleToTellIfAUserIsAnAdmin() {
    Username username = new Username(new CaseInsensitiveString("user"));
    when(goConfigService.isUserAdmin(username)).thenReturn(Boolean.TRUE);
    when(goConfigService.isSecurityEnabled()).thenReturn(true);
    assertThat(securityService.canViewAdminPage(username), is(true));
    verify(goConfigService).isUserAdmin(username);
}
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