Search in sources :

Example 26 with TriStateSelection

use of com.thoughtworks.go.presentation.TriStateSelection in project gocd by gocd.

the class UserServiceIntegrationTest method shouldNotModifyAdminPrivilegesWhen_NoChange_requested.

@Test
public void shouldNotModifyAdminPrivilegesWhen_NoChange_requested() throws Exception {
    configFileHelper.addAdmins("user", "boozer");
    configFileHelper.addRole(new RoleConfig(new CaseInsensitiveString("mastersOfTheWorld"), new RoleUser(new CaseInsensitiveString("loser")), new RoleUser(new CaseInsensitiveString("boozer"))));
    configFileHelper.addAdminRoles("mastersOfTheWorld");
    addUser(new User("user"));
    addUser(new User("loser"));
    addUser(new User("boozer"));
    HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
    userService.modifyRolesAndUserAdminPrivileges(Arrays.asList("user", "boozer"), new TriStateSelection(Admin.GO_SYSTEM_ADMIN, TriStateSelection.Action.nochange), new ArrayList<>(), result);
    final CruiseConfig cruiseConfig = goConfigDao.load();
    final SecurityConfig securityConfig = cruiseConfig.server().security();
    final AdminsConfig adminsConfig = securityConfig.adminsConfig();
    assertThat(adminsConfig.hasUser(new CaseInsensitiveString("user"), UserRoleMatcherMother.ALWAYS_FALSE_MATCHER), is(true));
    assertThat(adminsConfig.hasUser(new CaseInsensitiveString("loser"), UserRoleMatcherMother.ALWAYS_FALSE_MATCHER), is(false));
    assertThat(adminsConfig.hasUser(new CaseInsensitiveString("boozer"), UserRoleMatcherMother.ALWAYS_FALSE_MATCHER), is(true));
    assertThat(result.isSuccessful(), is(true));
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) TriStateSelection(com.thoughtworks.go.presentation.TriStateSelection) Test(org.junit.Test)

Example 27 with TriStateSelection

use of com.thoughtworks.go.presentation.TriStateSelection in project gocd by gocd.

the class UserServiceIntegrationTest method shouldRemoveUserLevelAdminPrivilegeFromMultipleUsers_withoutModifingRoleLevelPrvileges.

@Test
public void shouldRemoveUserLevelAdminPrivilegeFromMultipleUsers_withoutModifingRoleLevelPrvileges() throws Exception {
    configFileHelper.addAdmins("user", "boozer");
    configFileHelper.addRole(new RoleConfig(new CaseInsensitiveString("mastersOfTheWorld"), new RoleUser(new CaseInsensitiveString("loser")), new RoleUser(new CaseInsensitiveString("boozer"))));
    configFileHelper.addAdminRoles("mastersOfTheWorld");
    addUser(new User("user"));
    addUser(new User("loser"));
    addUser(new User("boozer"));
    CruiseConfig cruiseConfig = goConfigDao.load();
    SecurityConfig securityConfig = cruiseConfig.server().security();
    AdminsConfig adminsConfig = securityConfig.adminsConfig();
    assertThat(adminsConfig.hasUser(new CaseInsensitiveString("user"), UserRoleMatcherMother.ALWAYS_FALSE_MATCHER), is(true));
    assertThat(adminsConfig.hasUser(new CaseInsensitiveString("loser"), UserRoleMatcherMother.ALWAYS_FALSE_MATCHER), is(false));
    assertThat(adminsConfig.hasUser(new CaseInsensitiveString("boozer"), UserRoleMatcherMother.ALWAYS_FALSE_MATCHER), is(true));
    HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
    userService.modifyRolesAndUserAdminPrivileges(Arrays.asList("user", "boozer"), new TriStateSelection(Admin.GO_SYSTEM_ADMIN, TriStateSelection.Action.remove), new ArrayList<>(), result);
    cruiseConfig = goConfigDao.load();
    securityConfig = cruiseConfig.server().security();
    adminsConfig = securityConfig.adminsConfig();
    assertThat(adminsConfig.hasUser(new CaseInsensitiveString("user"), UserRoleMatcherMother.ALWAYS_FALSE_MATCHER), is(false));
    assertThat(adminsConfig.hasUser(new CaseInsensitiveString("loser"), UserRoleMatcherMother.ALWAYS_FALSE_MATCHER), is(false));
    assertThat(adminsConfig.hasUser(new CaseInsensitiveString("boozer"), UserRoleMatcherMother.ALWAYS_FALSE_MATCHER), is(false));
    final SecurityService.UserRoleMatcherImpl groupMatcher = new SecurityService.UserRoleMatcherImpl(securityConfig);
    assertThat(adminsConfig.hasUser(new CaseInsensitiveString("user"), groupMatcher), is(false));
    assertThat(adminsConfig.hasUser(new CaseInsensitiveString("loser"), groupMatcher), is(true));
    assertThat(adminsConfig.hasUser(new CaseInsensitiveString("boozer"), groupMatcher), is(true));
    assertThat(result.isSuccessful(), is(true));
}
Also used : TriStateSelection(com.thoughtworks.go.presentation.TriStateSelection) HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) Test(org.junit.Test)

Example 28 with TriStateSelection

use of com.thoughtworks.go.presentation.TriStateSelection in project gocd by gocd.

the class UserServiceIntegrationTest method modifyRoles_shouldNotModifyRolesForAUserThatDoesNotExistInDb.

@Test
public void modifyRoles_shouldNotModifyRolesForAUserThatDoesNotExistInDb() throws Exception {
    assertThat(userDao.findUser("user-1"), is(instanceOf(NullUser.class)));
    HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
    userService.modifyRolesAndUserAdminPrivileges(Arrays.asList("user-1"), new TriStateSelection(Admin.GO_SYSTEM_ADMIN, TriStateSelection.Action.nochange), Arrays.asList(new TriStateSelection("dev", TriStateSelection.Action.add)), result);
    assertThat(userDao.findUser("user-1"), is(instanceOf(NullUser.class)));
    assertThat(result.isSuccessful(), is(false));
    assertThat(result.message(localizer), containsString("User 'user-1' does not exist in the database."));
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) TriStateSelection(com.thoughtworks.go.presentation.TriStateSelection) Test(org.junit.Test)

Example 29 with TriStateSelection

use of com.thoughtworks.go.presentation.TriStateSelection in project gocd by gocd.

the class UserServiceIntegrationTest method shouldModifyRolesAndAdminPrivilegeAtTheSameTime.

@Test
public void shouldModifyRolesAndAdminPrivilegeAtTheSameTime() throws Exception {
    configFileHelper.addRole(new RoleConfig(new CaseInsensitiveString("dev")));
    addUser(new User("user-1"));
    HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
    userService.modifyRolesAndUserAdminPrivileges(Arrays.asList("user-1"), new TriStateSelection(Admin.GO_SYSTEM_ADMIN, TriStateSelection.Action.add), Arrays.asList(new TriStateSelection("dev", TriStateSelection.Action.add)), result);
    CruiseConfig cruiseConfig = goConfigDao.load();
    assertThat(cruiseConfig.server().security().getRoles().findByName(new CaseInsensitiveString("dev")).hasMember(new CaseInsensitiveString("user-1")), is(true));
    assertThat(cruiseConfig.server().security().adminsConfig().hasUser(new CaseInsensitiveString("user-1"), UserRoleMatcherMother.ALWAYS_FALSE_MATCHER), is(true));
    assertThat(result.isSuccessful(), is(true));
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) TriStateSelection(com.thoughtworks.go.presentation.TriStateSelection) Test(org.junit.Test)

Example 30 with TriStateSelection

use of com.thoughtworks.go.presentation.TriStateSelection in project gocd by gocd.

the class UserServiceIntegrationTest method modifyRoles_shouldNotAddUserToExistingRoleIfAlreadyAMember.

@Test
public void modifyRoles_shouldNotAddUserToExistingRoleIfAlreadyAMember() throws Exception {
    addUser(new User("user-1"));
    // first time
    userService.modifyRolesAndUserAdminPrivileges(Arrays.asList("user-1"), new TriStateSelection(Admin.GO_SYSTEM_ADMIN, TriStateSelection.Action.nochange), Arrays.asList(new TriStateSelection("dev", TriStateSelection.Action.add)), new HttpLocalizedOperationResult());
    // second time
    userService.modifyRolesAndUserAdminPrivileges(Arrays.asList("user-1"), new TriStateSelection(Admin.GO_SYSTEM_ADMIN, TriStateSelection.Action.nochange), Arrays.asList(new TriStateSelection("dev", TriStateSelection.Action.add)), new HttpLocalizedOperationResult());
    CruiseConfig cruiseConfig = goConfigDao.load();
    assertThat(cruiseConfig.server().security().getRoles().findByName(new CaseInsensitiveString("dev")).hasMember(new CaseInsensitiveString("user-1")), is(true));
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) TriStateSelection(com.thoughtworks.go.presentation.TriStateSelection) Test(org.junit.Test)

Aggregations

TriStateSelection (com.thoughtworks.go.presentation.TriStateSelection)30 Test (org.junit.Test)24 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)13 HttpOperationResult (com.thoughtworks.go.server.service.result.HttpOperationResult)12 Username (com.thoughtworks.go.server.domain.Username)5 GoConfigFileHelper (com.thoughtworks.go.util.GoConfigFileHelper)2 Before (org.junit.Before)2 UpdateConfigCommand (com.thoughtworks.go.config.UpdateConfigCommand)1 GitMaterialConfig (com.thoughtworks.go.config.materials.git.GitMaterialConfig)1 ConfigRepoConfig (com.thoughtworks.go.config.remote.ConfigRepoConfig)1 PartialConfig (com.thoughtworks.go.config.remote.PartialConfig)1 RepoConfigOrigin (com.thoughtworks.go.config.remote.RepoConfigOrigin)1 AgentInstance (com.thoughtworks.go.domain.AgentInstance)1 PackageRepositories (com.thoughtworks.go.domain.packagerepository.PackageRepositories)1 PackageRepository (com.thoughtworks.go.domain.packagerepository.PackageRepository)1 GoCipher (com.thoughtworks.go.security.GoCipher)1 AgentConfigsUpdateValidator (com.thoughtworks.go.validation.AgentConfigsUpdateValidator)1 ArrayList (java.util.ArrayList)1 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)1 ExpectedException (org.junit.rules.ExpectedException)1