Search in sources :

Example 11 with SimbaRoleR

use of org.simbasecurity.dwclient.gateway.representations.SimbaRoleR in project simba-os by cegeka.

the class SimbaManagerRestGatewayTest method unassignRoleFromUser_WhenUsernameDoesNotExist_ThrowsIllegalArgumentException.

@Test
public void unassignRoleFromUser_WhenUsernameDoesNotExist_ThrowsIllegalArgumentException() throws Exception {
    String username = "ivar";
    String rolename = "role name";
    logInWithValidUser();
    when(simbaUserServiceMock.findUserByName(anyString(), eq(username))).thenThrow(new IllegalArgumentException());
    when(simbaRoleServiceMock.findRoleByName(anyString(), eq(rolename))).thenReturn(new SimbaRoleR());
    expectedException.expect(IllegalArgumentException.class);
    simbaManagerRestGateway.unassignRoleFromUser(rolename, username);
}
Also used : SimbaRoleR(org.simbasecurity.dwclient.gateway.representations.SimbaRoleR) Test(org.junit.Test)

Example 12 with SimbaRoleR

use of org.simbasecurity.dwclient.gateway.representations.SimbaRoleR in project simba-os by cegeka.

the class SimbaManagerRestGatewayTest method unassignRoleFromUser_RemovesLookedUpSimbaRoleFromLookedUpSimbaUser.

@Test
public void unassignRoleFromUser_RemovesLookedUpSimbaRoleFromLookedUpSimbaUser() throws Exception {
    String username = "herp";
    String rolename = "derp";
    String ssoToken = logInWithValidUser();
    SimbaRoleR simbaRole = new SimbaRoleR();
    SimbaUserR simbaUser = new SimbaUserR("simbauser");
    when(simbaRoleServiceMock.findRoleByName(ssoToken, rolename)).thenReturn(simbaRole);
    when(simbaUserServiceMock.findUserByName(ssoToken, username)).thenReturn(simbaUser);
    simbaManagerRestGateway.unassignRoleFromUser(rolename, username);
    verify(simbaGatewayMock, times(1)).login(APP_USER, APP_PASSWORD);
    verify(simbaRoleServiceMock, times(1)).findRoleByName(ssoToken, rolename);
    verify(simbaUserServiceMock, times(1)).findUserByName(ssoToken, username);
    verify(simbaRoleServiceMock, times(1)).removeRoleFromUser(ssoToken, simbaRole, simbaUser);
}
Also used : SimbaRoleR(org.simbasecurity.dwclient.gateway.representations.SimbaRoleR) SimbaUserR(org.simbasecurity.dwclient.gateway.representations.SimbaUserR) Test(org.junit.Test)

Example 13 with SimbaRoleR

use of org.simbasecurity.dwclient.gateway.representations.SimbaRoleR in project simba-os by cegeka.

the class SimbaRoleServiceTest method addRoleToUser_WhenUserIsNull_ThrowsIllegalArgumentException.

@Test
public void addRoleToUser_WhenUserIsNull_ThrowsIllegalArgumentException() throws Exception {
    expectedException.expect(IllegalArgumentException.class);
    expectedException.expectMessage("User cannot be null.");
    simbaRoleService.addRoleToUser(getValidSSOToken(), new SimbaRoleR(), null);
}
Also used : SimbaRoleR(org.simbasecurity.dwclient.gateway.representations.SimbaRoleR) Test(org.junit.Test)

Example 14 with SimbaRoleR

use of org.simbasecurity.dwclient.gateway.representations.SimbaRoleR in project simba-os by cegeka.

the class SimbaRoleServiceTest method addRoleToUser_WhenBothRoleAndUserExist_UserHasRole.

@Test
public void addRoleToUser_WhenBothRoleAndUserExist_UserHasRole() throws Exception {
    String anExistingRolename = "simba-manager";
    SimbaRoleR simbaRole = simbaRoleService.findRoleByName(getValidSSOToken(), anExistingRolename);
    SimbaUserR user = simbaUserService.findUserByName(getValidSSOToken(), DUMMY_TEST_USER);
    simbaRoleService.addRoleToUser(getValidSSOToken(), simbaRole, user);
    simbaDatabaseRule.assertUserRoleExistsAndCleanUp(DUMMY_TEST_USER, anExistingRolename);
}
Also used : SimbaRoleR(org.simbasecurity.dwclient.gateway.representations.SimbaRoleR) SimbaUserR(org.simbasecurity.dwclient.gateway.representations.SimbaUserR) Test(org.junit.Test)

Aggregations

SimbaRoleR (org.simbasecurity.dwclient.gateway.representations.SimbaRoleR)14 Test (org.junit.Test)11 SimbaUserR (org.simbasecurity.dwclient.gateway.representations.SimbaUserR)6 ClientResponse (com.sun.jersey.api.client.ClientResponse)1 Cookie (javax.ws.rs.core.Cookie)1