use of org.pentaho.platform.plugin.services.importexport.UserExport in project pentaho-platform by pentaho.
the class SolutionImportHandlerTest method testImportUsers_oneUserManyRoles.
@Test
public void testImportUsers_oneUserManyRoles() throws Exception {
List<UserExport> users = new ArrayList<>();
UserExport user = new UserExport();
user.setUsername("scrum master");
user.setRole("coder");
user.setRole("product owner");
user.setRole("cat herder");
user.setPassword("password");
users.add(user);
Map<String, List<String>> rolesToUsers = importHandler.importUsers(users);
Assert.assertEquals(3, rolesToUsers.size());
Assert.assertEquals("scrum master", rolesToUsers.get("coder").get(0));
Assert.assertEquals("scrum master", rolesToUsers.get("product owner").get(0));
Assert.assertEquals("scrum master", rolesToUsers.get("cat herder").get(0));
String[] strings = {};
Mockito.verify(userRoleDao).createUser(Mockito.any(ITenant.class), Mockito.eq("scrum master"), Mockito.anyString(), Mockito.anyString(), Mockito.any(strings.getClass()));
// should not set the password or roles explicitly if the createUser worked
Mockito.verify(userRoleDao, Mockito.never()).setUserRoles(Mockito.any(ITenant.class), Mockito.anyString(), Mockito.any(strings.getClass()));
Mockito.verify(userRoleDao, Mockito.never()).setPassword(Mockito.any(ITenant.class), Mockito.anyString(), Mockito.anyString());
}
use of org.pentaho.platform.plugin.services.importexport.UserExport in project pentaho-platform by pentaho.
the class PentahoPlatformExporterTest method testExportUsersAndRoles.
@Test
public void testExportUsersAndRoles() {
IUserRoleListService mockDao = mock(IUserRoleListService.class);
IAnyUserSettingService userSettingService = mock(IAnyUserSettingService.class);
UserDetailsService userDetailsService = mock(UserDetailsService.class);
PentahoSystem.registerObject(mockDao);
PentahoSystem.registerObject(userSettingService);
PentahoSystem.registerObject(userDetailsService);
IRoleAuthorizationPolicyRoleBindingDao roleBindingDao = mock(IRoleAuthorizationPolicyRoleBindingDao.class);
PentahoSystem.registerObject(roleBindingDao);
String tenantPath = "path";
when(session.getAttribute(IPentahoSession.TENANT_ID_KEY)).thenReturn(tenantPath);
List<String> userList = new ArrayList<String>();
String user = "testUser";
String role = "testRole";
userList.add(user);
when(mockDao.getAllUsers(any(ITenant.class))).thenReturn(userList);
List<String> roleList = new ArrayList<String>();
roleList.add(role);
when(mockDao.getAllRoles()).thenReturn(roleList);
Map<String, List<String>> map = new HashMap<String, List<String>>();
List<String> permissions = new ArrayList<String>();
permissions.add("read");
map.put("testRole", permissions);
RoleBindingStruct struct = mock(RoleBindingStruct.class);
struct.bindingMap = map;
when(roleBindingDao.getRoleBindingStruct(anyString())).thenReturn(struct);
ArgumentCaptor<UserExport> userCaptor = ArgumentCaptor.forClass(UserExport.class);
ArgumentCaptor<RoleExport> roleCaptor = ArgumentCaptor.forClass(RoleExport.class);
ExportManifest manifest = mock(ExportManifest.class);
exporter.setExportManifest(manifest);
List<IUserSetting> settings = new ArrayList<>();
IUserSetting setting = mock(IUserSetting.class);
settings.add(setting);
when(userSettingService.getUserSettings(user)).thenReturn(settings);
when(userSettingService.getGlobalUserSettings()).thenReturn(settings);
List<GrantedAuthority> authList = new ArrayList<GrantedAuthority>();
UserDetails userDetails = new User("testUser", "testPassword", true, true, true, true, authList);
when(userDetailsService.loadUserByUsername(anyString())).thenReturn(userDetails);
exporter.exportUsersAndRoles();
verify(manifest).addUserExport(userCaptor.capture());
verify(manifest).addRoleExport(roleCaptor.capture());
verify(userSettingService).getGlobalUserSettings();
verify(manifest).addGlobalUserSetting(any(ExportManifestUserSetting.class));
assertEquals(settings.size(), userCaptor.getValue().getUserSettings().size());
UserExport userExport = userCaptor.getValue();
assertEquals("testUser", userExport.getUsername());
RoleExport roleExport = roleCaptor.getValue();
assertEquals("testRole", roleExport.getRolename());
}
use of org.pentaho.platform.plugin.services.importexport.UserExport in project pentaho-platform by pentaho.
the class SolutionImportHandlerTest method testImportUsers_userAlreadyExists_overwriteFalse.
@Test
public void testImportUsers_userAlreadyExists_overwriteFalse() throws Exception {
List<UserExport> users = new ArrayList<>();
UserExport user = new UserExport();
user.setUsername("scrum master");
user.setRole("coder");
user.setPassword("password");
users.add(user);
String[] strings = {};
Mockito.when(userRoleDao.createUser(Mockito.any(ITenant.class), Mockito.eq("scrum master"), Mockito.anyString(), Mockito.anyString(), Mockito.any(strings.getClass()))).thenThrow(new AlreadyExistsException("already there"));
importHandler.setOverwriteFile(false);
Map<String, List<String>> rolesToUsers = importHandler.importUsers(users);
Assert.assertEquals(1, rolesToUsers.size());
Assert.assertEquals("scrum master", rolesToUsers.get("coder").get(0));
Mockito.verify(userRoleDao).createUser(Mockito.any(ITenant.class), Mockito.eq("scrum master"), Mockito.anyString(), Mockito.anyString(), Mockito.any(strings.getClass()));
// should set the password or roles explicitly if the createUser failed
Mockito.verify(userRoleDao, Mockito.never()).setUserRoles(Mockito.any(ITenant.class), Mockito.anyString(), Mockito.any(strings.getClass()));
Mockito.verify(userRoleDao, Mockito.never()).setPassword(Mockito.any(ITenant.class), Mockito.anyString(), Mockito.anyString());
}
use of org.pentaho.platform.plugin.services.importexport.UserExport in project pentaho-platform by pentaho.
the class SolutionImportHandlerTest method testImportUsers_manyUserManyRoles.
@Test
public void testImportUsers_manyUserManyRoles() throws Exception {
List<UserExport> users = new ArrayList<>();
UserExport user = new UserExport();
user.setUsername("scrum master");
user.setRole("coder");
user.setRole("product owner");
user.setRole("cat herder");
user.setPassword("password");
users.add(user);
UserExport user2 = new UserExport();
user2.setUsername("the dude");
user2.setRole("coder");
user2.setRole("awesome");
user2.setPassword("password");
users.add(user2);
Map<String, List<String>> rolesToUsers = importHandler.importUsers(users);
Assert.assertEquals(4, rolesToUsers.size());
Assert.assertEquals(2, rolesToUsers.get("coder").size());
Assert.assertEquals(1, rolesToUsers.get("product owner").size());
Assert.assertEquals("scrum master", rolesToUsers.get("product owner").get(0));
Assert.assertEquals(1, rolesToUsers.get("cat herder").size());
Assert.assertEquals("scrum master", rolesToUsers.get("cat herder").get(0));
Assert.assertEquals(1, rolesToUsers.get("awesome").size());
Assert.assertEquals("the dude", rolesToUsers.get("awesome").get(0));
String[] strings = {};
Mockito.verify(userRoleDao).createUser(Mockito.any(ITenant.class), Mockito.eq("scrum master"), Mockito.anyString(), Mockito.anyString(), Mockito.any(strings.getClass()));
Mockito.verify(userRoleDao).createUser(Mockito.any(ITenant.class), Mockito.eq("the dude"), Mockito.anyString(), Mockito.anyString(), Mockito.any(strings.getClass()));
// should not set the password or roles explicitly if the createUser worked
Mockito.verify(userRoleDao, Mockito.never()).setUserRoles(Mockito.any(ITenant.class), Mockito.anyString(), Mockito.any(strings.getClass()));
Mockito.verify(userRoleDao, Mockito.never()).setPassword(Mockito.any(ITenant.class), Mockito.anyString(), Mockito.anyString());
}
Aggregations