Search in sources :

Example 46 with Username

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

the class AuthorityGranterTest method shouldGrantRoleUserToUsersWhoAreNotSpecial.

@Test
public void shouldGrantRoleUserToUsersWhoAreNotSpecial() {
    when(securityService.isUserAdmin(new Username(new CaseInsensitiveString("admin")))).thenReturn(false);
    when(securityService.isUserGroupAdmin(new Username(new CaseInsensitiveString("admin")))).thenReturn(false);
    GrantedAuthority[] authorities = authorityGranter.authorities("admin");
    assertThat("Should not have " + GoAuthority.ROLE_SUPERVISOR + " authority", authorities, not(hasItemInArray(GoAuthority.ROLE_SUPERVISOR.asAuthority())));
    assertThat("Should not have " + GoAuthority.ROLE_GROUP_SUPERVISOR + " authority", authorities, not(hasItemInArray(GoAuthority.ROLE_GROUP_SUPERVISOR.asAuthority())));
    assertThat("Should have " + GoAuthority.ROLE_USER + " authority", authorities, hasItemInArray(GoAuthority.ROLE_USER.asAuthority()));
}
Also used : Username(com.thoughtworks.go.server.domain.Username) GrantedAuthority(org.springframework.security.GrantedAuthority) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Test(org.junit.Test)

Example 47 with Username

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

the class AuthorityGranterTest method shouldGrantSupervisorRoleToUsersWhoAreAdminsAndGroupAdmins.

@Test
public void shouldGrantSupervisorRoleToUsersWhoAreAdminsAndGroupAdmins() {
    when(securityService.isUserAdmin(new Username(new CaseInsensitiveString("admin")))).thenReturn(true);
    when(securityService.isUserGroupAdmin(new Username(new CaseInsensitiveString("admin")))).thenReturn(true);
    GrantedAuthority[] authorities = authorityGranter.authorities("admin");
    assertThat("Should have " + GoAuthority.ROLE_SUPERVISOR + " authority", authorities, hasItemInArray(GoAuthority.ROLE_SUPERVISOR.asAuthority()));
    assertThat("Should have " + GoAuthority.ROLE_GROUP_SUPERVISOR + " authority", authorities, hasItemInArray(GoAuthority.ROLE_GROUP_SUPERVISOR.asAuthority()));
    assertThat("Should have " + GoAuthority.ROLE_USER + " authority", authorities, hasItemInArray(GoAuthority.ROLE_USER.asAuthority()));
}
Also used : Username(com.thoughtworks.go.server.domain.Username) GrantedAuthority(org.springframework.security.GrantedAuthority) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Test(org.junit.Test)

Example 48 with Username

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

the class GoConfigServiceTest method shouldReturnNotMergedInConfigUpdateResponse_WhenConfigIsUpdated.

@Test
public void shouldReturnNotMergedInConfigUpdateResponse_WhenConfigIsUpdated() {
    when(goConfigDao.updateConfig(org.mockito.Matchers.<UpdateConfigCommand>any())).thenReturn(ConfigSaveState.UPDATED);
    ConfigUpdateResponse configUpdateResponse = goConfigService.updateConfigFromUI(mock(UpdateConfigFromUI.class), "md5", new Username(new CaseInsensitiveString("user")), new HttpLocalizedOperationResult());
    assertThat(configUpdateResponse.wasMerged(), is(false));
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) Username(com.thoughtworks.go.server.domain.Username) ConfigUpdateResponse(com.thoughtworks.go.config.update.ConfigUpdateResponse) UpdateConfigFromUI(com.thoughtworks.go.config.update.UpdateConfigFromUI) Test(org.junit.Test)

Example 49 with Username

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

the class GoConfigServiceTest method shouldBeAbleToEditAnExistentLocalPipelineWithAdminPrivileges.

@Test
public void shouldBeAbleToEditAnExistentLocalPipelineWithAdminPrivileges() throws Exception {
    CruiseConfig cruiseConfig = mock(CruiseConfig.class);
    PipelineConfig pipeline = new PipelineConfig();
    pipeline.setName("pipeline1");
    pipeline.setOrigin(null);
    when(goConfigDao.load()).thenReturn(cruiseConfig);
    when(cruiseConfig.pipelineConfigByName(new CaseInsensitiveString("pipeline1"))).thenReturn(pipeline);
    when(cruiseConfig.getGroups()).thenReturn(new GoConfigMother().cruiseConfigWithOnePipelineGroup().getGroups());
    when(cruiseConfig.isAdministrator("admin_user")).thenReturn(true);
    assertTrue(goConfigService.canEditPipeline("pipeline1", new Username("admin_user")));
}
Also used : Username(com.thoughtworks.go.server.domain.Username) GoConfigMother(com.thoughtworks.go.helper.GoConfigMother) Test(org.junit.Test)

Example 50 with Username

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

the class GoConfigServiceTest method shouldTellIfAnUserIsAdministrator.

@Test
public void shouldTellIfAnUserIsAdministrator() throws Exception {
    final Username user = new Username(new CaseInsensitiveString("user"));
    expectLoad(mock(BasicCruiseConfig.class));
    goConfigService.isAdministrator(user.getUsername());
    verify(goConfigDao.load()).isAdministrator(user.getUsername().toString());
}
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