use of org.apache.ranger.entity.XXPortalUser in project ranger by apache.
the class TestUserMgr method test48ChangePasswordAsUser.
@Test
public void test48ChangePasswordAsUser() {
destroySession();
setupUser();
XXPortalUserDao userDao = Mockito.mock(XXPortalUserDao.class);
VXPortalUser userProfile = userProfile();
VXPasswordChange pwdChange = new VXPasswordChange();
pwdChange.setId(userProfile.getId());
pwdChange.setLoginId(userProfile.getLoginId());
pwdChange.setOldPassword(userProfile.getPassword());
pwdChange.setEmailAddress(userProfile.getEmailAddress());
pwdChange.setUpdPassword(userProfile.getPassword());
XXPortalUser user = new XXPortalUser();
user.setId(userProfile.getId());
user.setLoginId(userProfile.getLoginId());
String encryptCred = userMgr.encrypt(userProfile.getLoginId(), userProfile.getPassword());
user.setPassword(encryptCred);
Mockito.when(daoManager.getXXPortalUser()).thenReturn(userDao);
Mockito.when(userDao.findByLoginId(Mockito.anyString())).thenReturn(user);
Mockito.when(stringUtil.equals(Mockito.anyString(), Mockito.nullable(String.class))).thenReturn(true);
Mockito.when(daoManager.getXXPortalUser()).thenReturn(userDao);
Mockito.when(stringUtil.validatePassword(Mockito.anyString(), Mockito.any(String[].class))).thenReturn(false);
Mockito.when(restErrorUtil.createRESTException("serverMsg.userMgrNewPassword", MessageEnums.INVALID_PASSWORD, null, null, pwdChange.getLoginId())).thenThrow(new WebApplicationException());
thrown.expect(WebApplicationException.class);
userMgr.changePassword(pwdChange);
}
use of org.apache.ranger.entity.XXPortalUser in project ranger by apache.
the class TestUserMgr method test33checkAccessForUpdate.
@Test
public void test33checkAccessForUpdate() {
setup();
XXPortalUser xPortalUser = Mockito.mock(XXPortalUser.class);
userMgr.checkAccessForUpdate(xPortalUser);
destroySession();
xPortalUser.setId(userId);
VXResponse vXResponse = new VXResponse();
vXResponse.setStatusCode(HttpServletResponse.SC_FORBIDDEN);
vXResponse.setMsgDesc("User access denied. loggedInUser=Not Logged In , accessing user=" + xPortalUser.getId());
Mockito.when(restErrorUtil.generateRESTException((VXResponse) Mockito.any())).thenThrow(new WebApplicationException());
thrown.expect(WebApplicationException.class);
userMgr.checkAccessForUpdate(xPortalUser);
xPortalUser = null;
Mockito.when(restErrorUtil.create403RESTException("serverMsg.userMgrWrongUser")).thenThrow(new WebApplicationException());
thrown.expect(WebApplicationException.class);
userMgr.checkAccessForUpdate(xPortalUser);
}
use of org.apache.ranger.entity.XXPortalUser in project ranger by apache.
the class TestUserMgr method test14UpdateUserWithPass.
@Test
public void test14UpdateUserWithPass() {
setup();
XXPortalUserDao userDao = Mockito.mock(XXPortalUserDao.class);
VXPortalUser userProfile = userProfile();
userProfile.setPassword("password1234");
XXPortalUser user = new XXPortalUser();
user.setId(userProfile.getId());
user.setLoginId(userProfile.getLoginId());
user.setEmailAddress(userProfile.getEmailAddress());
user.setLoginId(userProfile.getLoginId());
String encryptedPwd = userMgr.encrypt(userProfile.getLoginId(), userProfile.getPassword());
user.setPassword(encryptedPwd);
Mockito.when(daoManager.getXXPortalUser()).thenReturn(userDao);
Mockito.when(userDao.getById(userProfile.getId())).thenReturn(user);
Mockito.when(stringUtil.validateEmail(Mockito.anyString())).thenReturn(true);
Mockito.doNothing().when(rangerBizUtil).blockAuditorRoleUser();
Mockito.when(stringUtil.validatePassword(Mockito.anyString(), Mockito.any(String[].class))).thenReturn(true);
Mockito.when(userDao.update(user)).thenReturn(user);
XXPortalUser dbXXPortalUser = userMgr.updateUserWithPass(userProfile);
Assert.assertNotNull(dbXXPortalUser);
Assert.assertEquals(userId, dbXXPortalUser.getId());
Assert.assertEquals(userProfile.getFirstName(), dbXXPortalUser.getFirstName());
Assert.assertEquals(userProfile.getFirstName(), dbXXPortalUser.getFirstName());
Assert.assertEquals(userProfile.getLastName(), dbXXPortalUser.getLastName());
Assert.assertEquals(userProfile.getLoginId(), dbXXPortalUser.getLoginId());
Assert.assertEquals(userProfile.getEmailAddress(), dbXXPortalUser.getEmailAddress());
Assert.assertEquals(encryptedPwd, dbXXPortalUser.getPassword());
Mockito.when(userDao.getById(userProfile.getId())).thenReturn(null);
dbXXPortalUser = userMgr.updateUserWithPass(userProfile);
Assert.assertNull(dbXXPortalUser);
}
use of org.apache.ranger.entity.XXPortalUser in project ranger by apache.
the class TestUserMgr method test46ChangePassword.
@Test
public void test46ChangePassword() {
destroySession();
setupUser();
VXPortalUser userProfile = userProfile();
XXPortalUser user2 = new XXPortalUser();
user2.setId(userId);
VXPasswordChange invalidpwdChange = new VXPasswordChange();
invalidpwdChange.setId(userProfile.getId());
invalidpwdChange.setLoginId(userProfile.getLoginId() + 1);
invalidpwdChange.setOldPassword("invalidOldPassword");
invalidpwdChange.setEmailAddress(userProfile.getEmailAddress());
invalidpwdChange.setUpdPassword(userProfile.getPassword());
XXPortalUserDao userDao = Mockito.mock(XXPortalUserDao.class);
Mockito.when(daoManager.getXXPortalUser()).thenReturn(userDao);
Mockito.when(userDao.findByLoginId(userProfile.getLoginId())).thenReturn(user2);
Mockito.when(userDao.findByLoginId(invalidpwdChange.getLoginId())).thenReturn(null);
Mockito.when(restErrorUtil.createRESTException("serverMsg.userMgrInvalidUser", MessageEnums.DATA_NOT_FOUND, null, null, invalidpwdChange.getLoginId())).thenThrow(new WebApplicationException());
thrown.expect(WebApplicationException.class);
userMgr.changePassword(invalidpwdChange);
}
use of org.apache.ranger.entity.XXPortalUser in project ranger by apache.
the class TestRangerBizUtil method testHasPermission_emptyResourceName.
@Test
public void testHasPermission_emptyResourceName() {
VXResource vXResource = new VXResource();
vXResource.setAssetId(12345L);
XXPortalUser portalUser = new XXPortalUser();
portalUser.setId(id);
portalUser.setLoginId("12121");
RangerContextHolder.getSecurityContext().getUserSession().setXXPortalUser(portalUser);
XXUserDao xxUserDao = Mockito.mock(XXUserDao.class);
XXPortalUserDao userDao = Mockito.mock(XXPortalUserDao.class);
XXUser xxUser = new XXUser();
XXAsset xxAsset = new XXAsset();
List<XXResource> lst = new ArrayList<XXResource>();
XXResourceDao xxResourceDao = Mockito.mock(XXResourceDao.class);
XXAssetDao xxAssetDao = Mockito.mock(XXAssetDao.class);
Mockito.when(daoManager.getXXPortalUser()).thenReturn(userDao);
Mockito.when(userDao.getById(Mockito.anyLong())).thenReturn(portalUser);
Mockito.when(daoManager.getXXUser()).thenReturn(xxUserDao);
Mockito.when(xxUserDao.findByUserName(Mockito.anyString())).thenReturn(xxUser);
Mockito.when(daoManager.getXXResource()).thenReturn(xxResourceDao);
Mockito.when(xxResourceDao.findByAssetIdAndResourceStatus(Mockito.anyLong(), Mockito.anyInt())).thenReturn(lst);
Mockito.when(daoManager.getXXAsset()).thenReturn(xxAssetDao);
Mockito.when(xxAssetDao.getById(Mockito.anyLong())).thenReturn(xxAsset);
VXResponse resp = rangerBizUtil.hasPermission(vXResource, AppConstants.XA_PERM_TYPE_UNKNOWN);
Mockito.verify(daoManager).getXXPortalUser();
Mockito.verify(userDao).getById(Mockito.anyLong());
Mockito.verify(daoManager).getXXUser();
Mockito.verify(xxUserDao).findByUserName(Mockito.anyString());
Assert.assertNotNull(resp);
Assert.assertEquals(VXResponse.STATUS_ERROR, resp.getStatusCode());
Assert.assertEquals("Permission Denied !", resp.getMsgDesc());
}
Aggregations