Search in sources :

Example 31 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() {
    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(), 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.jupiter.api.Test)

Example 32 with TriStateSelection

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

the class UserServiceIntegrationTest method modifyRoles_shouldRemoveUserFromRole.

@Test
public void modifyRoles_shouldRemoveUserFromRole() {
    addUser(new User("user-1"));
    // add it first
    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());
    // now remove it
    userService.modifyRolesAndUserAdminPrivileges(Arrays.asList("user-1"), new TriStateSelection(Admin.GO_SYSTEM_ADMIN, TriStateSelection.Action.nochange), Arrays.asList(new TriStateSelection("dev", TriStateSelection.Action.remove)), new HttpLocalizedOperationResult());
    CruiseConfig cruiseConfig = goConfigDao.load();
    assertThat(cruiseConfig.server().security().getRoles().findByName(new CaseInsensitiveString("dev")).hasMember(new CaseInsensitiveString("user-1")), is(false));
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) TriStateSelection(com.thoughtworks.go.presentation.TriStateSelection) Test(org.junit.jupiter.api.Test)

Aggregations

TriStateSelection (com.thoughtworks.go.presentation.TriStateSelection)32 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)14 Test (org.junit.jupiter.api.Test)13 HttpOperationResult (com.thoughtworks.go.server.service.result.HttpOperationResult)12 Test (org.junit.Test)12 Username (com.thoughtworks.go.server.domain.Username)6 BeforeEach (org.junit.jupiter.api.BeforeEach)4 GoConfigFileHelper (com.thoughtworks.go.util.GoConfigFileHelper)3 UpdateConfigCommand (com.thoughtworks.go.config.UpdateConfigCommand)2 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)1 PartialConfig (com.thoughtworks.go.config.remote.PartialConfig)1 RepoConfigOrigin (com.thoughtworks.go.config.remote.RepoConfigOrigin)1 AgentInstance (com.thoughtworks.go.domain.AgentInstance)1 MaterialConfig (com.thoughtworks.go.domain.materials.MaterialConfig)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