use of com.sequenceiq.freeipa.client.model.User in project cloudbreak by hortonworks.
the class SetPasswordHandlerTest method testWithPasswordHashSupportWithUmsPasswordWithUpdateOptimizationIpaCredentialsStale.
@Test
void testWithPasswordHashSupportWithUmsPasswordWithUpdateOptimizationIpaCredentialsStale() throws FreeIpaClientException, IOException {
SetPasswordRequest request = new SetPasswordRequest(1L, "environment", USER, USER_CRN, "password", Optional.empty());
FreeIpaClient mockFreeIpaClient = newfreeIpaClient(true);
when(freeIpaClientFactory.getFreeIpaClientForStack(any())).thenReturn(mockFreeIpaClient);
setupMocksForPasswordHashSupport(true, true);
User user = getIpaUser(USER);
when(mockFreeIpaClient.userFind(USER)).thenReturn(Optional.of(user));
UserMetadata userMetadata = new UserMetadata(USER_CRN, UMS_WORKLOAD_CREDENTIALS_VERSION - 1);
doReturn(Optional.of(userMetadata)).when(userMetadataConverter).toUserMetadata(argThat(matchesUser(user)));
underTest.accept(new Event<>(request));
verify(workloadCredentialService, times(1)).setWorkloadCredential(eq(true), any(), any());
verify(mockFreeIpaClient, times(0)).userSetPasswordWithExpiration(any(), any(), any());
}
use of com.sequenceiq.freeipa.client.model.User in project cloudbreak by hortonworks.
the class UserAddOperationTest method testInvoke.
@Test
public void testInvoke() throws FreeIpaClientException {
RPCResponse<Object> rpcResponse = new RPCResponse<>();
rpcResponse.setResult(new User());
when(freeIpaClient.invoke(any(), anyList(), any(), any())).thenReturn(rpcResponse);
UserAddOperation.create(USER_NAME, USER_NAME, USER_NAME, false).invoke(freeIpaClient);
verify(freeIpaClient).invoke(eq("user_add"), anyList(), any(), any());
}
use of com.sequenceiq.freeipa.client.model.User in project cloudbreak by hortonworks.
the class UserSyncOperationsTest method testAddUsersToGroupsSingle.
@Test
public void testAddUsersToGroupsSingle() throws Exception {
Multimap<String, String> groupMapping = setupGroupMapping(5, MAX_SUBJECTS_PER_REQUEST * 2);
Multimap<String, String> warnings = ArrayListMultimap.create();
ArgumentCaptor<List<Object>> flagsCaptor = ArgumentCaptor.forClass(List.class);
ArgumentCaptor<Map<String, Object>> paramsCaptor = ArgumentCaptor.forClass(Map.class);
RPCResponse<Object> response = new RPCResponse<>();
Group result = new Group();
result.setMemberUser(List.copyOf(groupMapping.values()));
response.setResult(result);
when(freeIpaClient.invoke(eq("group_add_member"), flagsCaptor.capture(), paramsCaptor.capture(), eq(Group.class))).thenReturn(response);
underTest.addUsersToGroups(false, freeIpaClient, groupMapping, warnings::put);
assertTrue(warnings.isEmpty());
verifyNoInteractions(batchPartitionSizeProperties);
verify(freeIpaClient, never()).callBatch(any(), any(), any(), any(), any());
List<List<Object>> flagsList = flagsCaptor.getAllValues();
Map<String, Long> flagCount = flagsList.stream().flatMap(Collection::stream).map(o -> (String) o).collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));
assertEquals(5, flagCount.size());
assertTrue(flagCount.keySet().containsAll(Set.of("group1", "group2", "group3", "group4", "group0")));
flagCount.forEach((flag, count) -> assertEquals(2, count, flag + " size should be 2"));
List<Map<String, Object>> paramsList = paramsCaptor.getAllValues();
assertEquals(10, paramsList.size());
paramsList.forEach(map -> {
assertEquals(10, ((List<String>) map.get("user")).size());
assertTrue(((List<String>) map.get("user")).stream().allMatch(user -> user.startsWith("user")));
});
verify(interruptChecker, times(20)).throwTimeoutExIfInterrupted();
}
use of com.sequenceiq.freeipa.client.model.User in project cloudbreak by hortonworks.
the class UserSyncOperationsTest method testAddUsersSingle.
@Test
public void testAddUsersSingle() throws FreeIpaClientException, TimeoutException {
Multimap<String, String> warnings = ArrayListMultimap.create();
FmsUser user1 = new FmsUser().withName("user1").withFirstName("User_1").withLastName("Test1").withState(FmsUser.State.ENABLED);
FmsUser user2 = new FmsUser().withName("user2").withFirstName("User_2").withLastName("Test2").withState(FmsUser.State.DISABLED);
Set<FmsUser> users = Set.of(user1, user2);
ArgumentCaptor<List<Object>> flagsCaptor = ArgumentCaptor.forClass(List.class);
ArgumentCaptor<Map<String, Object>> paramsCaptor = ArgumentCaptor.forClass(Map.class);
RPCResponse<Object> response1 = new RPCResponse<>();
response1.setResult(new User());
RPCResponse<Object> response2 = new RPCResponse<>();
response2.setResult(new User());
when(freeIpaClient.invoke(eq("user_add"), flagsCaptor.capture(), paramsCaptor.capture(), eq(User.class))).thenReturn(response1, response2);
underTest.addUsers(false, freeIpaClient, users, warnings::put);
assertTrue(warnings.isEmpty());
verifyNoInteractions(batchPartitionSizeProperties);
verify(freeIpaClient, never()).callBatch(any(), any(), any(), any(), any());
List<List<Object>> flagsList = flagsCaptor.getAllValues();
assertThat(flagsList, allOf(hasItem(hasItem("user1")), hasItem(hasItem("user2"))));
List<Map<String, Object>> paramsList = paramsCaptor.getAllValues();
assertThat(paramsList, everyItem(aMapWithSize(5)));
assertThat(paramsList, allOf(Matchers.<Map<String, Object>>hasItem(allOf(hasEntry("givenname", "User_1"), hasEntry("sn", "Test1"))), Matchers.<Map<String, Object>>hasItem(allOf(hasEntry("givenname", "User_2"), hasEntry("sn", "Test2")))));
verify(interruptChecker, times(4)).throwTimeoutExIfInterrupted();
}
use of com.sequenceiq.freeipa.client.model.User in project cloudbreak by hortonworks.
the class FreeipaClientTestServiceTest method createUser.
private User createUser(String user) {
User ipaUser = new User();
ipaUser.setUid(user);
return ipaUser;
}
Aggregations