use of com.sequenceiq.freeipa.api.v1.freeipa.user.model.SynchronizeAllUsersRequest in project cloudbreak by hortonworks.
the class AltusMachineUserServiceTest method testDeleteMachineUserForEnvironment.
@Test
void testDeleteMachineUserForEnvironment() {
MachineUser machineUserMock = mock(MachineUser.class);
RegionAwareInternalCrnGenerator regionAwareInternalCrnGenerator = mock(RegionAwareInternalCrnGenerator.class);
when(machineUserMock.getCrn()).thenReturn(autoscaleMachineUserCrn);
when(machineUserMock.getWorkloadUsername()).thenReturn("workloadUserName");
when(roleCrnGenerator.getBuiltInEnvironmentUserResourceRoleCrn(anyString())).thenReturn(environmentRoleCrn);
when(regionAwareInternalCrnGeneratorFactory.iam()).thenReturn(regionAwareInternalCrnGenerator);
when(regionAwareInternalCrnGenerator.getInternalCrnForServiceAsString()).thenReturn(internalActorCrn);
when(grpcUmsClient.getOrCreateMachineUserWithoutAccessKey(eq(autoscaleMachineUserName), eq("testTenant"), any(Optional.class))).thenReturn(machineUserMock);
when(freeIpaCommunicator.synchronizeAllUsers(any(SynchronizeAllUsersRequest.class))).thenReturn(getSyncOpStatus(SynchronizationStatus.COMPLETED));
underTest.deleteMachineUserForEnvironment(testAccountId, autoscaleMachineUserCrn, testEnvironmentCrn);
verify(grpcUmsClient, times(1)).deleteMachineUser(eq(autoscaleMachineUserCrn), eq(internalActorCrn), eq(testAccountId), any(Optional.class), any(RegionAwareInternalCrnGeneratorFactory.class));
ArgumentCaptor<SynchronizeAllUsersRequest> synchronizeUserCaptor = ArgumentCaptor.forClass(SynchronizeAllUsersRequest.class);
verify(freeIpaCommunicator, times(1)).synchronizeAllUsers(synchronizeUserCaptor.capture());
SynchronizeAllUsersRequest synchronizeAllUsersRequest = synchronizeUserCaptor.getValue();
Assertions.assertEquals(synchronizeAllUsersRequest.getDeletedWorkloadUsers(), Set.of("workloadUserName"), "WorkloadUserName Should match");
Assertions.assertEquals(synchronizeAllUsersRequest.getEnvironments(), Set.of(testEnvironmentCrn), "Environment Crn Should match");
Assertions.assertEquals(synchronizeAllUsersRequest.getMachineUsers(), Set.of(autoscaleMachineUserCrn), "Machine User Crn Should match");
Assertions.assertEquals(synchronizeAllUsersRequest.getAccountId(), testAccountId, "Account Id Should match");
}
use of com.sequenceiq.freeipa.api.v1.freeipa.user.model.SynchronizeAllUsersRequest in project cloudbreak by hortonworks.
the class AltusMachineUserServiceTest method testInitializeMachineUserForEnvironment.
@Test
void testInitializeMachineUserForEnvironment() {
Cluster cluster = getACluster();
MachineUser machineUser = mock(MachineUser.class);
when(machineUser.getCrn()).thenReturn(autoscaleMachineUserCrn);
when(grpcUmsClient.getOrCreateMachineUserWithoutAccessKey(autoscaleMachineUserName, testAccountId, MDCUtils.getRequestId())).thenReturn(machineUser);
when(grpcUmsClient.listAssignedResourceRoles(anyString(), any(Optional.class), any(RegionAwareInternalCrnGeneratorFactory.class))).thenReturn(LinkedHashMultimap.create());
when(roleCrnGenerator.getBuiltInEnvironmentUserResourceRoleCrn(anyString())).thenReturn(environmentRoleCrn);
when(freeIpaCommunicator.synchronizeAllUsers(any(SynchronizeAllUsersRequest.class))).thenReturn(getSyncOpStatus(SynchronizationStatus.COMPLETED));
underTest.initializeMachineUserForEnvironment(cluster);
verify(grpcUmsClient, times(1)).assignResourceRole(eq(autoscaleMachineUserCrn), eq(testEnvironmentCrn), eq(environmentRoleCrn), any(Optional.class), any(RegionAwareInternalCrnGeneratorFactory.class));
verify(clusterService, times(1)).setMachineUserCrn(cluster.getId(), autoscaleMachineUserCrn);
ArgumentCaptor<SynchronizeAllUsersRequest> synchronizeUserCaptor = ArgumentCaptor.forClass(SynchronizeAllUsersRequest.class);
verify(freeIpaCommunicator, times(1)).synchronizeAllUsers(synchronizeUserCaptor.capture());
SynchronizeAllUsersRequest synchronizeAllUsersRequest = synchronizeUserCaptor.getValue();
Assertions.assertEquals(synchronizeAllUsersRequest.getEnvironments(), Set.of(testEnvironmentCrn), "Environment Crn Should match");
Assertions.assertEquals(synchronizeAllUsersRequest.getMachineUsers(), Set.of(autoscaleMachineUserCrn), "Machine User Crn Should match");
Assertions.assertEquals(synchronizeAllUsersRequest.getAccountId(), cluster.getClusterPertain().getTenant(), "Account Id Should match");
}
use of com.sequenceiq.freeipa.api.v1.freeipa.user.model.SynchronizeAllUsersRequest in project cloudbreak by hortonworks.
the class AltusMachineUserServiceTest method testinitializeMachineUserForEnvironmentWhenRoleAlreadyAssigned.
@Test
void testinitializeMachineUserForEnvironmentWhenRoleAlreadyAssigned() {
Cluster cluster = getACluster();
MachineUser machineUser = mock(MachineUser.class);
LinkedHashMultimap rolesMap = LinkedHashMultimap.create();
rolesMap.put(cluster.getEnvironmentCrn(), environmentRoleCrn);
when(grpcUmsClient.getOrCreateMachineUserWithoutAccessKey(autoscaleMachineUserName, testAccountId, MDCUtils.getRequestId())).thenReturn(machineUser);
when(machineUser.getCrn()).thenReturn(autoscaleMachineUserCrn);
when(grpcUmsClient.listAssignedResourceRoles(anyString(), any(Optional.class), any(RegionAwareInternalCrnGeneratorFactory.class))).thenReturn(rolesMap);
when(roleCrnGenerator.getBuiltInEnvironmentUserResourceRoleCrn(anyString())).thenReturn(environmentRoleCrn);
when(freeIpaCommunicator.synchronizeAllUsers(any(SynchronizeAllUsersRequest.class))).thenReturn(getSyncOpStatus(SynchronizationStatus.COMPLETED));
underTest.initializeMachineUserForEnvironment(cluster);
verify(grpcUmsClient, times(0)).assignResourceRole(eq(autoscaleMachineUserCrn), eq(testEnvironmentCrn), eq(environmentRoleCrn), any(Optional.class), any(RegionAwareInternalCrnGeneratorFactory.class));
verify(clusterService, times(1)).setMachineUserCrn(cluster.getId(), autoscaleMachineUserCrn);
ArgumentCaptor<SynchronizeAllUsersRequest> synchronizeUserCaptor = ArgumentCaptor.forClass(SynchronizeAllUsersRequest.class);
verify(freeIpaCommunicator, times(1)).synchronizeAllUsers(synchronizeUserCaptor.capture());
SynchronizeAllUsersRequest synchronizeAllUsersRequest = synchronizeUserCaptor.getValue();
Assertions.assertEquals(synchronizeAllUsersRequest.getEnvironments(), Set.of(testEnvironmentCrn), "Environment Crn Should match");
Assertions.assertEquals(synchronizeAllUsersRequest.getMachineUsers(), Set.of(autoscaleMachineUserCrn), "Machine User Crn Should match");
Assertions.assertEquals(synchronizeAllUsersRequest.getAccountId(), cluster.getClusterPertain().getTenant(), "Account Id Should match");
}
use of com.sequenceiq.freeipa.api.v1.freeipa.user.model.SynchronizeAllUsersRequest in project cloudbreak by hortonworks.
the class AltusMachineUserService method syncEnvironment.
private void syncEnvironment(String accountId, String machineUserCrn, String environmentCrn, Optional<String> deletedWorkloadUserName) {
SynchronizeAllUsersRequest request = new SynchronizeAllUsersRequest();
request.setAccountId(accountId);
request.setEnvironments(Set.of(environmentCrn));
request.setMachineUsers(Set.of(machineUserCrn));
deletedWorkloadUserName.ifPresent(s -> request.setDeletedWorkloadUsers(Set.of(s)));
SyncOperationStatus statusResponse = freeIpaCommunicator.synchronizeAllUsers(request);
LOGGER.info("Finished invoking freeIpa user Sync with operation: {}, for environmentCrn: {} and machineUserCrn: {}", statusResponse.getOperationId(), environmentCrn, machineUserCrn);
}
use of com.sequenceiq.freeipa.api.v1.freeipa.user.model.SynchronizeAllUsersRequest in project cloudbreak by hortonworks.
the class UserV1ControllerTest method synchronizeAllUsers.
@Test
void synchronizeAllUsers() {
Set<String> environments = Set.of(ENV_CRN);
Set<String> users = Set.of(USER_CRN);
Set<String> machineUsers = Set.of(MACHINE_USER_CRN);
SynchronizeAllUsersRequest request = new SynchronizeAllUsersRequest();
request.setEnvironments(environments);
request.setUsers(users);
request.setMachineUsers(machineUsers);
request.setWorkloadCredentialsUpdateType(WorkloadCredentialsUpdateType.FORCE_UPDATE);
Operation operation = mock(Operation.class);
when(userSyncService.synchronizeUsersWithCustomPermissionCheck(any(), any(), any(), any(), any(), any())).thenReturn(operation);
SyncOperationStatus status = mock(SyncOperationStatus.class);
when(operationToSyncOperationStatus.convert(operation)).thenReturn(status);
assertEquals(status, ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.synchronizeAllUsers(request)));
UserSyncRequestFilter userSyncFilter = new UserSyncRequestFilter(users, machineUsers, Optional.empty());
verify(userSyncService, times(1)).synchronizeUsersWithCustomPermissionCheck(ACCOUNT_ID, USER_CRN, environments, userSyncFilter, WorkloadCredentialsUpdateType.FORCE_UPDATE, AuthorizationResourceAction.DESCRIBE_ENVIRONMENT);
}
Aggregations