Search in sources :

Example 1 with FreeIpaClient

use of com.sequenceiq.freeipa.client.FreeIpaClient in project cloudbreak by hortonworks.

the class SudoRuleAddOperationTest method testInvokeWithAllHostCategory.

@Test
public void testInvokeWithAllHostCategory() throws FreeIpaClientException {
    RPCResponse<Object> rpcResponse = new RPCResponse<>();
    rpcResponse.setResult(new SudoRule());
    when(freeIpaClient.invoke(any(), anyList(), any(), any())).thenReturn(rpcResponse);
    SudoRuleAddOperation.create(NAME, true, null).invoke(freeIpaClient);
    verify(freeIpaClient).invoke(eq("sudorule_add"), argThat(argument -> argument.contains(NAME) && argument.size() == 1), argThat(argument -> "all".equals(argument.get("hostcategory")) && argument.size() == 1), eq(SudoRule.class));
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Mock(org.mockito.Mock) RPCResponse(com.sequenceiq.cloudbreak.client.RPCResponse) FreeIpaClientException(com.sequenceiq.freeipa.client.FreeIpaClientException) Mockito.when(org.mockito.Mockito.when) SudoRule(com.sequenceiq.freeipa.client.model.SudoRule) ArgumentMatchers.anyList(org.mockito.ArgumentMatchers.anyList) FreeIpaClient(com.sequenceiq.freeipa.client.FreeIpaClient) Mockito.verify(org.mockito.Mockito.verify) Test(org.junit.jupiter.api.Test) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) RPCResponse(com.sequenceiq.cloudbreak.client.RPCResponse) SudoRule(com.sequenceiq.freeipa.client.model.SudoRule) Test(org.junit.jupiter.api.Test)

Example 2 with FreeIpaClient

use of com.sequenceiq.freeipa.client.FreeIpaClient in project cloudbreak by hortonworks.

the class SudoRuleAddOperationTest method testInvoke.

@Test
public void testInvoke() throws FreeIpaClientException {
    RPCResponse<Object> rpcResponse = new RPCResponse<>();
    rpcResponse.setResult(new SudoRule());
    when(freeIpaClient.invoke(any(), anyList(), any(), any())).thenReturn(rpcResponse);
    SudoRuleAddOperation.create(NAME, false, null).invoke(freeIpaClient);
    verify(freeIpaClient).invoke(eq("sudorule_add"), argThat(argument -> argument.contains(NAME) && argument.size() == 1), argThat(argument -> argument.isEmpty()), eq(SudoRule.class));
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Mock(org.mockito.Mock) RPCResponse(com.sequenceiq.cloudbreak.client.RPCResponse) FreeIpaClientException(com.sequenceiq.freeipa.client.FreeIpaClientException) Mockito.when(org.mockito.Mockito.when) SudoRule(com.sequenceiq.freeipa.client.model.SudoRule) ArgumentMatchers.anyList(org.mockito.ArgumentMatchers.anyList) FreeIpaClient(com.sequenceiq.freeipa.client.FreeIpaClient) Mockito.verify(org.mockito.Mockito.verify) Test(org.junit.jupiter.api.Test) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) RPCResponse(com.sequenceiq.cloudbreak.client.RPCResponse) SudoRule(com.sequenceiq.freeipa.client.model.SudoRule) Test(org.junit.jupiter.api.Test)

Example 3 with FreeIpaClient

use of com.sequenceiq.freeipa.client.FreeIpaClient in project cloudbreak by hortonworks.

the class SudoRuleShowOperationTest method testInvokeShouldFreeIpaClientException.

@Test
public void testInvokeShouldFreeIpaClientException() throws FreeIpaClientException {
    when(freeIpaClient.invoke(any(), anyList(), any(), any())).thenThrow(new FreeIpaClientException(null));
    assertThrows(FreeIpaClientException.class, () -> SudoRuleShowOperation.create(NAME).invoke(freeIpaClient));
    verify(freeIpaClient).invoke(eq("sudorule_show"), argThat(argument -> argument.contains(NAME) && argument.size() == 1), argThat(argument -> argument.isEmpty()), eq(SudoRule.class));
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Mock(org.mockito.Mock) RPCResponse(com.sequenceiq.cloudbreak.client.RPCResponse) FreeIpaClientException(com.sequenceiq.freeipa.client.FreeIpaClientException) Mockito.when(org.mockito.Mockito.when) SudoRule(com.sequenceiq.freeipa.client.model.SudoRule) ArgumentMatchers.anyList(org.mockito.ArgumentMatchers.anyList) FreeIpaClient(com.sequenceiq.freeipa.client.FreeIpaClient) FreeIpaErrorCodes(com.sequenceiq.freeipa.client.FreeIpaErrorCodes) Mockito.verify(org.mockito.Mockito.verify) Test(org.junit.jupiter.api.Test) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) JsonRpcClientException(com.googlecode.jsonrpc4j.JsonRpcClientException) Optional(java.util.Optional) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) FreeIpaClientException(com.sequenceiq.freeipa.client.FreeIpaClientException) SudoRule(com.sequenceiq.freeipa.client.model.SudoRule) Test(org.junit.jupiter.api.Test)

Example 4 with FreeIpaClient

use of com.sequenceiq.freeipa.client.FreeIpaClient in project cloudbreak by hortonworks.

the class SudoRuleShowOperationTest method testInvokeShouldReturnEmptyInCaseOfNotFoundException.

@Test
public void testInvokeShouldReturnEmptyInCaseOfNotFoundException() throws FreeIpaClientException {
    when(freeIpaClient.invoke(any(), anyList(), any(), any())).thenThrow(new FreeIpaClientException("", new JsonRpcClientException(FreeIpaErrorCodes.NOT_FOUND.getValue(), null, null)));
    Optional<SudoRule> result = SudoRuleShowOperation.create(NAME).invoke(freeIpaClient);
    assertEquals(Optional.empty(), result);
    verify(freeIpaClient).invoke(eq("sudorule_show"), argThat(argument -> argument.contains(NAME) && argument.size() == 1), argThat(argument -> argument.isEmpty()), eq(SudoRule.class));
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Mock(org.mockito.Mock) RPCResponse(com.sequenceiq.cloudbreak.client.RPCResponse) FreeIpaClientException(com.sequenceiq.freeipa.client.FreeIpaClientException) Mockito.when(org.mockito.Mockito.when) SudoRule(com.sequenceiq.freeipa.client.model.SudoRule) ArgumentMatchers.anyList(org.mockito.ArgumentMatchers.anyList) FreeIpaClient(com.sequenceiq.freeipa.client.FreeIpaClient) FreeIpaErrorCodes(com.sequenceiq.freeipa.client.FreeIpaErrorCodes) Mockito.verify(org.mockito.Mockito.verify) Test(org.junit.jupiter.api.Test) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) JsonRpcClientException(com.googlecode.jsonrpc4j.JsonRpcClientException) Optional(java.util.Optional) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) JsonRpcClientException(com.googlecode.jsonrpc4j.JsonRpcClientException) FreeIpaClientException(com.sequenceiq.freeipa.client.FreeIpaClientException) SudoRule(com.sequenceiq.freeipa.client.model.SudoRule) Test(org.junit.jupiter.api.Test)

Example 5 with FreeIpaClient

use of com.sequenceiq.freeipa.client.FreeIpaClient in project cloudbreak by hortonworks.

the class KeytabCleanupService method deleteServicePrincipal.

public void deleteServicePrincipal(ServicePrincipalRequest request, String accountId) throws FreeIpaClientException, DeleteException {
    LOGGER.debug("Request to delete service principal for account {}: {}", accountId, request);
    Stack freeIpaStack = keytabCommonService.getFreeIpaStackWithMdcContext(request.getEnvironmentCrn(), accountId);
    String realm = keytabCommonService.getRealm(freeIpaStack);
    String canonicalPrincipal = keytabCommonService.constructPrincipal(request.getServiceName(), request.getServerHostName(), realm);
    FreeIpaClient ipaClient = freeIpaClientFactory.getFreeIpaClientForStack(freeIpaStack);
    deleteService(canonicalPrincipal, ipaClient);
    VaultPathBuilder vaultPathBuilder = new VaultPathBuilder().withSecretType(VaultPathBuilder.SecretType.SERVICE_KEYTAB).withAccountId(accountId).withEnvironmentCrn(request.getEnvironmentCrn()).withClusterCrn(request.getClusterCrn()).withServerHostName(request.getServerHostName()).withServiceName(request.getServiceName());
    vaultComponent.recursivelyCleanupVault(vaultPathBuilder.withSubType(VaultPathBuilder.SecretSubType.SERVICE_PRINCIPAL).build());
    vaultComponent.recursivelyCleanupVault(vaultPathBuilder.withSubType(VaultPathBuilder.SecretSubType.KEYTAB).build());
    roleComponent.deleteRoleIfItIsNoLongerUsed(request.getRoleName(), ipaClient);
    keytabCacheService.deleteByEnvironmentCrnAndPrincipal(request.getEnvironmentCrn(), canonicalPrincipal);
}
Also used : FreeIpaClient(com.sequenceiq.freeipa.client.FreeIpaClient) Stack(com.sequenceiq.freeipa.entity.Stack)

Aggregations

FreeIpaClient (com.sequenceiq.freeipa.client.FreeIpaClient)124 Test (org.junit.jupiter.api.Test)64 FreeIpaClientException (com.sequenceiq.freeipa.client.FreeIpaClientException)55 Stack (com.sequenceiq.freeipa.entity.Stack)31 Set (java.util.Set)31 Map (java.util.Map)28 RetryableFreeIpaClientException (com.sequenceiq.freeipa.client.RetryableFreeIpaClientException)20 Retryable (org.springframework.retry.annotation.Retryable)19 RoleRequest (com.sequenceiq.freeipa.api.v1.kerberosmgmt.model.RoleRequest)17 User (com.sequenceiq.freeipa.client.model.User)17 Optional (java.util.Optional)17 Test (org.junit.Test)16 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)16 JsonRpcClientException (com.googlecode.jsonrpc4j.JsonRpcClientException)14 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)14 Mock (org.mockito.Mock)14 Mockito.when (org.mockito.Mockito.when)14 MockitoExtension (org.mockito.junit.jupiter.MockitoExtension)14 Collectors (java.util.stream.Collectors)13 RPCResponse (com.sequenceiq.cloudbreak.client.RPCResponse)12