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