Search in sources :

Example 36 with JsonRpcClientException

use of com.googlecode.jsonrpc4j.JsonRpcClientException in project cloudbreak by hortonworks.

the class WorkloadCredentialServiceTest method testSetWorkloadCredentialWhenThereAreNoModifications.

@Test
void testSetWorkloadCredentialWhenThereAreNoModifications() throws Exception {
    when(freeIpaClient.formatDate(any(Optional.class))).thenReturn(FreeIpaClient.MAX_PASSWORD_EXPIRATION_DATETIME);
    when(freeIpaClient.invoke(any(), any(), any(), any())).thenThrow(new FreeIpaClientException("error", new JsonRpcClientException(4202, "", null)));
    underTest.setWorkloadCredential(false, freeIpaClient, new WorkloadCredentialUpdate(USER, USER_CRN, createWorkloadCredential()));
    verify(freeIpaClient).invoke(eq("user_mod"), eq(List.of(USER)), any(), any());
    verifyNoInteractions(interruptChecker);
}
Also used : JsonRpcClientException(com.googlecode.jsonrpc4j.JsonRpcClientException) Optional(java.util.Optional) FreeIpaClientException(com.sequenceiq.freeipa.client.FreeIpaClientException) WorkloadCredentialUpdate(com.sequenceiq.freeipa.service.freeipa.user.model.WorkloadCredentialUpdate) Test(org.junit.jupiter.api.Test)

Example 37 with JsonRpcClientException

use of com.googlecode.jsonrpc4j.JsonRpcClientException in project cloudbreak by hortonworks.

the class WorkloadCredentialServiceTest method testSingleSetWorkloadCredentialsWhenErrorOccurs.

@Test
void testSingleSetWorkloadCredentialsWhenErrorOccurs() throws Exception {
    Multimap<String, String> warnings = ArrayListMultimap.create();
    when(freeIpaClient.invoke(any(), any(), any(), any())).thenThrow(new FreeIpaClientException("error", new JsonRpcClientException(5000, "", null)));
    setWorkloadCredentials(false, false, freeIpaClient, getCredentialMap(), getUsersWithCredentialsToUpdate(), getUserToCrnMap(), warnings::put);
    verify(freeIpaClient, times(4)).invoke(eq("user_mod"), any(), any(), any());
    assertEquals(4, warnings.size());
    verify(interruptChecker, times(4)).throwTimeoutExIfInterrupted();
}
Also used : JsonRpcClientException(com.googlecode.jsonrpc4j.JsonRpcClientException) FreeIpaClientException(com.sequenceiq.freeipa.client.FreeIpaClientException) Test(org.junit.jupiter.api.Test)

Example 38 with JsonRpcClientException

use of com.googlecode.jsonrpc4j.JsonRpcClientException in project cloudbreak by hortonworks.

the class WorkloadCredentialServiceTest method testSingleSetWorkloadCredentialsWhenThereAreNoModifications.

@Test
void testSingleSetWorkloadCredentialsWhenThereAreNoModifications() throws Exception {
    Multimap<String, String> warnings = ArrayListMultimap.create();
    when(freeIpaClient.invoke(any(), any(), any(), any())).thenThrow(new FreeIpaClientException("error", new JsonRpcClientException(4202, "", null)));
    setWorkloadCredentials(false, false, freeIpaClient, getCredentialMap(), getUsersWithCredentialsToUpdate(), getUserToCrnMap(), warnings::put);
    verify(freeIpaClient, times(4)).invoke(eq("user_mod"), any(), any(), any());
    assertEquals(0, warnings.size());
    verify(interruptChecker, times(4)).throwTimeoutExIfInterrupted();
}
Also used : JsonRpcClientException(com.googlecode.jsonrpc4j.JsonRpcClientException) FreeIpaClientException(com.sequenceiq.freeipa.client.FreeIpaClientException) Test(org.junit.jupiter.api.Test)

Example 39 with JsonRpcClientException

use of com.googlecode.jsonrpc4j.JsonRpcClientException in project cloudbreak by hortonworks.

the class KerberosMgmtRoleComponentV1Test method testAddRoleAndPrivilegesForServiceWithRole.

@Test
public void testAddRoleAndPrivilegesForServiceWithRole() throws Exception {
    Service service = new Service();
    service.setKrbprincipalname(List.of(SERVICE));
    service.setKrbcanonicalname(SERVICE);
    RoleRequest roleRequest = new RoleRequest();
    roleRequest.setRoleName(ROLE);
    Set<String> privileges = new HashSet<>();
    privileges.add(PRIVILEGE1);
    privileges.add(PRIVILEGE2);
    roleRequest.setPrivileges(privileges);
    Role role = new Role();
    role.setCn(ROLE);
    Mockito.when(mockIpaClient.addRole(anyString())).thenReturn(role);
    Privilege privilege = new Privilege();
    Set<String> noHosts = new HashSet<>();
    Set<String> services = new HashSet<>();
    services.add(SERVICE);
    Mockito.when(mockIpaClient.showRole(roleRequest.getRoleName())).thenThrow(new FreeIpaClientException("notfound", new JsonRpcClientException(NOT_FOUND, "notfound", null))).thenReturn(role);
    Mockito.when(mockIpaClient.showPrivilege(any())).thenReturn(privilege);
    Mockito.when(mockIpaClient.addRolePrivileges(any(), any())).thenReturn(role);
    Mockito.when(mockIpaClient.addRoleMember(any(), any(), any(), any(), any(), any())).thenReturn(role);
    underTest.addRoleAndPrivileges(Optional.of(service), Optional.empty(), roleRequest, mockIpaClient);
    Mockito.verify(mockIpaClient).addRole(ROLE);
    Mockito.verify(mockIpaClient).addRolePrivileges(ROLE, privileges);
    Mockito.verify(mockIpaClient).addRoleMember(ROLE, null, null, noHosts, null, services);
}
Also used : Role(com.sequenceiq.freeipa.client.model.Role) JsonRpcClientException(com.googlecode.jsonrpc4j.JsonRpcClientException) Service(com.sequenceiq.freeipa.client.model.Service) FreeIpaClientException(com.sequenceiq.freeipa.client.FreeIpaClientException) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Privilege(com.sequenceiq.freeipa.client.model.Privilege) RoleRequest(com.sequenceiq.freeipa.api.v1.kerberosmgmt.model.RoleRequest) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 40 with JsonRpcClientException

use of com.googlecode.jsonrpc4j.JsonRpcClientException in project cloudbreak by hortonworks.

the class KerberosMgmtRoleComponentV1Test method testPrivilegeExistReturnFalse.

@Test
public void testPrivilegeExistReturnFalse() throws Exception {
    RoleRequest roleRequest = new RoleRequest();
    roleRequest.setRoleName(ROLE);
    Set<String> privileges = new HashSet<>();
    privileges.add(PRIVILEGE1);
    privileges.add(PRIVILEGE2);
    roleRequest.setPrivileges(privileges);
    Mockito.when(mockIpaClient.showPrivilege(any())).thenThrow(new FreeIpaClientException(ERROR_MESSAGE, new JsonRpcClientException(NOT_FOUND, ERROR_MESSAGE, null)));
    Assertions.assertFalse(underTest.privilegesExist(roleRequest, mockIpaClient));
}
Also used : JsonRpcClientException(com.googlecode.jsonrpc4j.JsonRpcClientException) FreeIpaClientException(com.sequenceiq.freeipa.client.FreeIpaClientException) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) RoleRequest(com.sequenceiq.freeipa.api.v1.kerberosmgmt.model.RoleRequest) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Aggregations

JsonRpcClientException (com.googlecode.jsonrpc4j.JsonRpcClientException)43 Test (org.junit.jupiter.api.Test)40 FreeIpaClientException (com.sequenceiq.freeipa.client.FreeIpaClientException)38 Map (java.util.Map)13 RoleRequest (com.sequenceiq.freeipa.api.v1.kerberosmgmt.model.RoleRequest)10 FreeIpaClient (com.sequenceiq.freeipa.client.FreeIpaClient)8 Stack (com.sequenceiq.freeipa.entity.Stack)7 Host (com.sequenceiq.freeipa.client.model.Host)6 FreeIpa (com.sequenceiq.freeipa.entity.FreeIpa)6 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)6 HashSet (java.util.HashSet)5 Optional (java.util.Optional)5 Role (com.sequenceiq.freeipa.client.model.Role)4 Service (com.sequenceiq.freeipa.client.model.Service)4 AddDnsARecordRequest (com.sequenceiq.freeipa.api.v1.dns.model.AddDnsARecordRequest)3 ServiceKeytabRequest (com.sequenceiq.freeipa.api.v1.kerberosmgmt.model.ServiceKeytabRequest)3 ServiceKeytabResponse (com.sequenceiq.freeipa.api.v1.kerberosmgmt.model.ServiceKeytabResponse)3 Privilege (com.sequenceiq.freeipa.client.model.Privilege)3 Set (java.util.Set)3 AddDnsCnameRecordRequest (com.sequenceiq.freeipa.api.v1.dns.model.AddDnsCnameRecordRequest)2