use of org.apache.ranger.view.VXPortalUser in project ranger by apache.
the class TestUserMgr method test27UpdateUser.
@Test
public void test27UpdateUser() {
setup();
XXPortalUserDao userDao = Mockito.mock(XXPortalUserDao.class);
VXPortalUser userProfile = userProfile();
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();
XXPortalUser dbXXPortalUser = userMgr.updateUser(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(restErrorUtil.createRESTException("Please provide valid email address.", MessageEnums.INVALID_INPUT_DATA)).thenThrow(new WebApplicationException());
thrown.expect(WebApplicationException.class);
Mockito.when(stringUtil.validateEmail(Mockito.anyString())).thenReturn(false);
userMgr.updateUser(userProfile);
}
use of org.apache.ranger.view.VXPortalUser in project ranger by apache.
the class TestUserMgr method test51UpdateUserWithPass.
@Test
public void test51UpdateUserWithPass() {
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(false);
Mockito.when(restErrorUtil.createRESTException("serverMsg.userMgrNewPassword", MessageEnums.INVALID_PASSWORD, null, null, user.getId().toString())).thenThrow(new WebApplicationException());
thrown.expect(WebApplicationException.class);
userMgr.updateUserWithPass(userProfile);
}
use of org.apache.ranger.view.VXPortalUser in project ranger by apache.
the class TestUserMgr method test26CreateUser.
@Test
public void test26CreateUser() {
setup();
XXPortalUserDao userDao = Mockito.mock(XXPortalUserDao.class);
XXPortalUserRoleDao roleDao = Mockito.mock(XXPortalUserRoleDao.class);
VXPortalUser userProfile = userProfile();
Collection<String> userRoleList = new ArrayList<String>();
userRoleList.add("ROLE_USER");
XXPortalUser user = new XXPortalUser();
user.setEmailAddress(userProfile.getEmailAddress());
user.setFirstName(userProfile.getFirstName());
user.setLastName(userProfile.getLastName());
user.setLoginId(userProfile.getLoginId());
String encryptedPwd = userMgr.encrypt(userProfile.getLoginId(), userProfile.getPassword());
user.setPassword(encryptedPwd);
user.setUserSource(userProfile.getUserSource());
user.setPublicScreenName(userProfile.getPublicScreenName());
user.setId(userProfile.getId());
XXPortalUserRole XXPortalUserRole = new XXPortalUserRole();
XXPortalUserRole.setId(user.getId());
XXPortalUserRole.setUserRole("ROLE_USER");
List<XXPortalUserRole> list = new ArrayList<XXPortalUserRole>();
list.add(XXPortalUserRole);
Mockito.when(daoManager.getXXPortalUser()).thenReturn(userDao);
Mockito.when(userDao.create((XXPortalUser) Mockito.any())).thenReturn(user);
Mockito.when(daoManager.getXXPortalUserRole()).thenReturn(roleDao);
Mockito.when(roleDao.findByUserId(userId)).thenReturn(list);
Mockito.when(userDao.findByLoginId(Mockito.anyString())).thenReturn(user);
XXPortalUser dbxxPortalUser = userMgr.createUser(userProfile, 1, userRoleList);
Assert.assertNotNull(dbxxPortalUser);
userId = dbxxPortalUser.getId();
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.verify(daoManager, Mockito.atLeast(1)).getXXPortalUser();
Mockito.verify(daoManager).getXXPortalUserRole();
}
use of org.apache.ranger.view.VXPortalUser in project ranger by apache.
the class TestUserMgr method test10CreateDefaultAccountUser.
@Test
public void test10CreateDefaultAccountUser() {
setup();
XXPortalUserDao userDao = Mockito.mock(XXPortalUserDao.class);
XXPortalUserRoleDao roleDao = Mockito.mock(XXPortalUserRoleDao.class);
VXPortalUser userProfile = userProfile();
Collection<String> userRoleList = new ArrayList<String>();
userRoleList.add("ROLE_USER");
userProfile.setUserRoleList(userRoleList);
XXPortalUser user = new XXPortalUser();
user.setEmailAddress(userProfile.getEmailAddress());
XXPortalUserRole XXPortalUserRole = new XXPortalUserRole();
XXPortalUserRole.setId(userId);
XXPortalUserRole.setUserRole("ROLE_USER");
List<XXPortalUserRole> list = new ArrayList<XXPortalUserRole>();
list.add(XXPortalUserRole);
Mockito.when(daoManager.getXXPortalUser()).thenReturn(userDao);
Mockito.when(userDao.findByLoginId(Mockito.anyString())).thenReturn(user);
Mockito.when(daoManager.getXXPortalUserRole()).thenReturn(roleDao);
Mockito.doNothing().when(rangerBizUtil).blockAuditorRoleUser();
userProfile.setOtherAttributes("other1");
VXPortalUser dbVXPortalUser = userMgr.createDefaultAccountUser(userProfile);
Assert.assertNotNull(dbVXPortalUser);
Assert.assertEquals(user.getId(), dbVXPortalUser.getId());
Assert.assertEquals(user.getFirstName(), dbVXPortalUser.getFirstName());
Assert.assertEquals(user.getLastName(), dbVXPortalUser.getLastName());
Assert.assertEquals(user.getLoginId(), dbVXPortalUser.getLoginId());
Assert.assertEquals(user.getEmailAddress(), dbVXPortalUser.getEmailAddress());
Assert.assertEquals(user.getPassword(), dbVXPortalUser.getPassword());
Mockito.verify(daoManager, Mockito.atLeast(1)).getXXPortalUser();
Mockito.verify(daoManager, Mockito.atLeast(1)).getXXPortalUserRole();
}
use of org.apache.ranger.view.VXPortalUser in project ranger by apache.
the class TestUserMgr method test44IsPasswordValid.
@Test
public void test44IsPasswordValid() {
VXPortalUser vXPortalUser = userProfile();
boolean isValid = userMgr.isPasswordValid(vXPortalUser.getLoginId(), "ceb4f32325eda6142bd65215f4c0f371", vXPortalUser.getPassword());
Assert.assertFalse(isValid);
}
Aggregations