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