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));
}
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));
}
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));
}
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;
}
}
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));
}
Aggregations