Search in sources :

Example 1 with SudoRule

use of com.sequenceiq.freeipa.client.model.SudoRule 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 SudoRule

use of com.sequenceiq.freeipa.client.model.SudoRule 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 SudoRule

use of com.sequenceiq.freeipa.client.model.SudoRule 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 4 with SudoRule

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

the class SudoRuleShowOperation method invoke.

@Override
public Optional<SudoRule> invoke(FreeIpaClient freeipaClient) throws FreeIpaClientException {
    try {
        LOGGER.debug("Show '{}'", ruleName);
        SudoRule sudoRule = invoke(freeipaClient, SudoRule.class);
        LOGGER.debug("Success: '{}'", sudoRule);
        return Optional.ofNullable(sudoRule);
    } catch (FreeIpaClientException ex) {
        if (FreeIpaClientExceptionUtil.isNotFoundException(ex)) {
            LOGGER.debug("Not found '{}'", ruleName);
            return Optional.empty();
        }
        LOGGER.error("Failed to show '{}': ", ruleName, ex);
        throw ex;
    }
}
Also used : FreeIpaClientException(com.sequenceiq.freeipa.client.FreeIpaClientException) SudoRule(com.sequenceiq.freeipa.client.model.SudoRule)

Example 5 with SudoRule

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

the class SudoRuleServiceTest method shouldThrowIllegalStateExceptionInCaseOfExistingSudoRuleButNotAllHostGroup.

@Test
public void shouldThrowIllegalStateExceptionInCaseOfExistingSudoRuleButNotAllHostGroup() throws FreeIpaClientException {
    Optional<SudoRule> sudoRule = Optional.of(new SudoRule());
    when(stack.getEnvironmentCrn()).thenReturn(ENV_CRN);
    when(virtualGroupService.getVirtualGroup(any(), eq(UmsVirtualGroupRight.ALLOW_PRIVILEGED_OS_OPERATIONS))).thenReturn(GROUP);
    when(freeIpaClient.groupShow(GROUP)).thenReturn(mock(Group.class));
    when(freeIpaClient.sudoRuleShow(RULE_NAME)).thenReturn(sudoRule);
    assertThrows(IllegalStateException.class, () -> victim.setupSudoRule(stack, freeIpaClient));
}
Also used : Group(com.sequenceiq.freeipa.client.model.Group) SudoRule(com.sequenceiq.freeipa.client.model.SudoRule) Test(org.junit.jupiter.api.Test)

Aggregations

SudoRule (com.sequenceiq.freeipa.client.model.SudoRule)12 Test (org.junit.jupiter.api.Test)9 FreeIpaClientException (com.sequenceiq.freeipa.client.FreeIpaClientException)8 RPCResponse (com.sequenceiq.cloudbreak.client.RPCResponse)7 FreeIpaClient (com.sequenceiq.freeipa.client.FreeIpaClient)7 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)7 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)7 ArgumentMatchers.anyList (org.mockito.ArgumentMatchers.anyList)7 ArgumentMatchers.argThat (org.mockito.ArgumentMatchers.argThat)7 ArgumentMatchers.eq (org.mockito.ArgumentMatchers.eq)7 Mock (org.mockito.Mock)7 Mockito.verify (org.mockito.Mockito.verify)7 Mockito.when (org.mockito.Mockito.when)7 MockitoExtension (org.mockito.junit.jupiter.MockitoExtension)7 JsonRpcClientException (com.googlecode.jsonrpc4j.JsonRpcClientException)2 FreeIpaErrorCodes (com.sequenceiq.freeipa.client.FreeIpaErrorCodes)2 Group (com.sequenceiq.freeipa.client.model.Group)2 Optional (java.util.Optional)2 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)2 Assertions.assertThrows (org.junit.jupiter.api.Assertions.assertThrows)2