Search in sources :

Example 16 with SyncOperationStatus

use of com.sequenceiq.freeipa.api.v1.freeipa.user.model.SyncOperationStatus in project cloudbreak by hortonworks.

the class UserV1ControllerTest method synchronizeAllUsersAsInternalActor.

@Test
void synchronizeAllUsersAsInternalActor() {
    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.setAccountId(ACCOUNT_ID);
    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.doAsInternalActor("crn:altus:iam:us-west-1:altus:user:__internal__actor__", () -> underTest.synchronizeAllUsers(request)));
    UserSyncRequestFilter userSyncFilter = new UserSyncRequestFilter(users, machineUsers, Optional.empty());
    verify(userSyncService, times(1)).synchronizeUsersWithCustomPermissionCheck(ACCOUNT_ID, "crn:altus:iam:us-west-1:altus:user:__internal__actor__", environments, userSyncFilter, WorkloadCredentialsUpdateType.UPDATE_IF_CHANGED, AuthorizationResourceAction.DESCRIBE_ENVIRONMENT);
}
Also used : UserSyncRequestFilter(com.sequenceiq.freeipa.service.freeipa.user.UserSyncRequestFilter) OperationToSyncOperationStatus(com.sequenceiq.freeipa.converter.freeipa.user.OperationToSyncOperationStatus) SyncOperationStatus(com.sequenceiq.freeipa.api.v1.freeipa.user.model.SyncOperationStatus) Operation(com.sequenceiq.freeipa.entity.Operation) SynchronizeAllUsersRequest(com.sequenceiq.freeipa.api.v1.freeipa.user.model.SynchronizeAllUsersRequest) Test(org.junit.jupiter.api.Test)

Example 17 with SyncOperationStatus

use of com.sequenceiq.freeipa.api.v1.freeipa.user.model.SyncOperationStatus in project cloudbreak by hortonworks.

the class UserV1ControllerTest method setPasswordRejected.

@Test
void setPasswordRejected() {
    String password = "password";
    SetPasswordRequest request = mock(SetPasswordRequest.class);
    when(request.getPassword()).thenReturn(password);
    Operation operation = mock(Operation.class);
    when(passwordService.setPasswordWithCustomPermissionCheck(ACCOUNT_ID, USER_CRN, password, new HashSet<>(), AuthorizationResourceAction.DESCRIBE_ENVIRONMENT)).thenReturn(operation);
    SyncOperationStatus status = mock(SyncOperationStatus.class);
    when(status.getStatus()).thenReturn(SynchronizationStatus.REJECTED);
    when(operationToSyncOperationStatus.convert(operation)).thenReturn(status);
    assertThrows(SyncOperationAlreadyRunningException.class, () -> ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.setPassword(request)));
}
Also used : SetPasswordRequest(com.sequenceiq.freeipa.api.v1.freeipa.user.model.SetPasswordRequest) OperationToSyncOperationStatus(com.sequenceiq.freeipa.converter.freeipa.user.OperationToSyncOperationStatus) SyncOperationStatus(com.sequenceiq.freeipa.api.v1.freeipa.user.model.SyncOperationStatus) Operation(com.sequenceiq.freeipa.entity.Operation) Test(org.junit.jupiter.api.Test)

Example 18 with SyncOperationStatus

use of com.sequenceiq.freeipa.api.v1.freeipa.user.model.SyncOperationStatus in project cloudbreak by hortonworks.

the class UserV1ControllerTest method synchronizeUserMachineUser.

@Test
void synchronizeUserMachineUser() {
    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);
    SynchronizeUserRequest request = mock(SynchronizeUserRequest.class);
    assertEquals(status, ThreadBasedUserCrnProvider.doAs(MACHINE_USER_CRN, () -> underTest.synchronizeUser(request)));
    UserSyncRequestFilter userSyncFilter = new UserSyncRequestFilter(Set.of(), Set.of(MACHINE_USER_CRN), Optional.empty());
    verify(userSyncService, times(1)).synchronizeUsersWithCustomPermissionCheck(ACCOUNT_ID, MACHINE_USER_CRN, Set.of(), userSyncFilter, WorkloadCredentialsUpdateType.UPDATE_IF_CHANGED, AuthorizationResourceAction.DESCRIBE_ENVIRONMENT);
}
Also used : UserSyncRequestFilter(com.sequenceiq.freeipa.service.freeipa.user.UserSyncRequestFilter) OperationToSyncOperationStatus(com.sequenceiq.freeipa.converter.freeipa.user.OperationToSyncOperationStatus) SyncOperationStatus(com.sequenceiq.freeipa.api.v1.freeipa.user.model.SyncOperationStatus) SynchronizeUserRequest(com.sequenceiq.freeipa.api.v1.freeipa.user.model.SynchronizeUserRequest) Operation(com.sequenceiq.freeipa.entity.Operation) Test(org.junit.jupiter.api.Test)

Example 19 with SyncOperationStatus

use of com.sequenceiq.freeipa.api.v1.freeipa.user.model.SyncOperationStatus in project cloudbreak by hortonworks.

the class UserV1ControllerTest method getStatus.

@Test
void getStatus() {
    String operationId = "testId";
    Operation operation = mock(Operation.class);
    when(operationService.getOperationForAccountIdAndOperationId(ACCOUNT_ID, operationId)).thenReturn(operation);
    SyncOperationStatus status = mock(SyncOperationStatus.class);
    when(operationToSyncOperationStatus.convert(operation)).thenReturn(status);
    assertEquals(status, ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.getSyncOperationStatus(operationId)));
    verify(operationService, times(1)).getOperationForAccountIdAndOperationId(ACCOUNT_ID, operationId);
}
Also used : OperationToSyncOperationStatus(com.sequenceiq.freeipa.converter.freeipa.user.OperationToSyncOperationStatus) SyncOperationStatus(com.sequenceiq.freeipa.api.v1.freeipa.user.model.SyncOperationStatus) Operation(com.sequenceiq.freeipa.entity.Operation) Test(org.junit.jupiter.api.Test)

Example 20 with SyncOperationStatus

use of com.sequenceiq.freeipa.api.v1.freeipa.user.model.SyncOperationStatus in project cloudbreak by hortonworks.

the class UserV1ControllerTest method synchronizeAllUsersDeleteWorkloadUser.

@Test
void synchronizeAllUsersDeleteWorkloadUser() {
    Set<String> users = Set.of(USER_CRN);
    String deletedWorkloadUser = "workload-user";
    SynchronizeAllUsersRequest request = new SynchronizeAllUsersRequest();
    request.setEnvironments(Set.of());
    request.setUsers(users);
    request.setDeletedWorkloadUsers(Set.of(deletedWorkloadUser));
    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, Set.of(), Optional.of(deletedWorkloadUser));
    verify(userSyncService, times(1)).synchronizeUsersWithCustomPermissionCheck(ACCOUNT_ID, USER_CRN, Set.of(), userSyncFilter, WorkloadCredentialsUpdateType.UPDATE_IF_CHANGED, AuthorizationResourceAction.DESCRIBE_ENVIRONMENT);
}
Also used : UserSyncRequestFilter(com.sequenceiq.freeipa.service.freeipa.user.UserSyncRequestFilter) OperationToSyncOperationStatus(com.sequenceiq.freeipa.converter.freeipa.user.OperationToSyncOperationStatus) SyncOperationStatus(com.sequenceiq.freeipa.api.v1.freeipa.user.model.SyncOperationStatus) Operation(com.sequenceiq.freeipa.entity.Operation) SynchronizeAllUsersRequest(com.sequenceiq.freeipa.api.v1.freeipa.user.model.SynchronizeAllUsersRequest) Test(org.junit.jupiter.api.Test)

Aggregations

SyncOperationStatus (com.sequenceiq.freeipa.api.v1.freeipa.user.model.SyncOperationStatus)26 Test (org.junit.jupiter.api.Test)18 Operation (com.sequenceiq.freeipa.entity.Operation)15 OperationToSyncOperationStatus (com.sequenceiq.freeipa.converter.freeipa.user.OperationToSyncOperationStatus)12 SynchronizeAllUsersRequest (com.sequenceiq.freeipa.api.v1.freeipa.user.model.SynchronizeAllUsersRequest)8 UserSyncRequestFilter (com.sequenceiq.freeipa.service.freeipa.user.UserSyncRequestFilter)8 EnvironmentUserSyncState (com.sequenceiq.freeipa.api.v1.freeipa.user.model.EnvironmentUserSyncState)3 SetPasswordRequest (com.sequenceiq.freeipa.api.v1.freeipa.user.model.SetPasswordRequest)3 SynchronizationStatus (com.sequenceiq.freeipa.api.v1.freeipa.user.model.SynchronizationStatus)3 SynchronizeUserRequest (com.sequenceiq.freeipa.api.v1.freeipa.user.model.SynchronizeUserRequest)3 OperationState (com.sequenceiq.freeipa.api.v1.operation.model.OperationState)3 CheckPermissionByResourceCrn (com.sequenceiq.authorization.annotation.CheckPermissionByResourceCrn)1 ResourceCrn (com.sequenceiq.authorization.annotation.ResourceCrn)1 Crn (com.sequenceiq.cloudbreak.auth.crn.Crn)1 UserV1Endpoint (com.sequenceiq.freeipa.api.v1.freeipa.user.UserV1Endpoint)1 FailureDetails (com.sequenceiq.freeipa.api.v1.freeipa.user.model.FailureDetails)1 SuccessDetails (com.sequenceiq.freeipa.api.v1.freeipa.user.model.SuccessDetails)1 TestFailException (com.sequenceiq.it.cloudbreak.exception.TestFailException)1 ClientErrorException (javax.ws.rs.ClientErrorException)1 WebApplicationException (javax.ws.rs.WebApplicationException)1