use of com.googlecode.jsonrpc4j.JsonRpcClientException in project cloudbreak by hortonworks.
the class UserSyncOperationsTest method testSingleErrorHandlingNotAcceptableErrorCode.
@Test
public void testSingleErrorHandlingNotAcceptableErrorCode() throws FreeIpaClientException, TimeoutException {
Multimap<String, String> warnings = ArrayListMultimap.create();
Set<String> users = Set.of("user1", "user2");
ArgumentCaptor<List<Object>> flagsCaptor = ArgumentCaptor.forClass(List.class);
ArgumentCaptor<Map<String, Object>> paramsCaptor = ArgumentCaptor.forClass(Map.class);
when(freeIpaClient.invoke(eq("user_enable"), flagsCaptor.capture(), paramsCaptor.capture(), eq(Object.class))).thenThrow(new FreeIpaClientException("Asdf", new JsonRpcClientException(FreeIpaErrorCodes.SESSION_ERROR.getValue(), "fdsa", null)));
underTest.enableUsers(false, freeIpaClient, users, warnings::put);
assertFalse(warnings.isEmpty());
verifyNoInteractions(batchPartitionSizeProperties);
verify(freeIpaClient, never()).callBatch(any(), any(), any(), any(), any());
verify(freeIpaClient, times(2)).checkIfClientStillUsable(any(FreeIpaClientException.class));
List<List<Object>> flagsList = flagsCaptor.getAllValues();
assertThat(flagsList, allOf(hasItem(hasItem("user1")), hasItem(hasItem("user2"))));
List<Map<String, Object>> paramsList = paramsCaptor.getAllValues();
assertThat(paramsList, everyItem(aMapWithSize(0)));
verify(interruptChecker, times(4)).throwTimeoutExIfInterrupted();
}
use of com.googlecode.jsonrpc4j.JsonRpcClientException in project cloudbreak by hortonworks.
the class KeytabCommonServiceTest method testAddHost.
@Test
public void testAddHost() throws FreeIpaClientException {
FreeIpaClient ipaClient = mock(FreeIpaClient.class);
RoleRequest roleRequest = new RoleRequest();
Host host = new Host();
when(ipaClient.showHost(HOST)).thenThrow(new FreeIpaClientException("notfound", new JsonRpcClientException(NOT_FOUND, "notfound", null)));
when(ipaClient.addHost(HOST)).thenReturn(host);
Host result = underTest.addHost(HOST, roleRequest, ipaClient);
verify(ipaClient).allowHostKeytabRetrieval(HOST, FreeIpaClientFactory.ADMIN_USER);
ArgumentCaptor<Optional<Service>> serviceCaptor = ArgumentCaptor.forClass(Optional.class);
ArgumentCaptor<Optional<Host>> hostCaptor = ArgumentCaptor.forClass(Optional.class);
verify(roleComponent).addRoleAndPrivileges(serviceCaptor.capture(), hostCaptor.capture(), eq(roleRequest), eq(ipaClient));
assertTrue(serviceCaptor.getValue().isEmpty());
assertEquals(host, hostCaptor.getValue().get());
assertEquals(host, result);
}
use of com.googlecode.jsonrpc4j.JsonRpcClientException in project cloudbreak by hortonworks.
the class KeytabCommonServiceTest method testAddHostDuplicateEntry.
@Test
public void testAddHostDuplicateEntry() throws FreeIpaClientException {
FreeIpaClient ipaClient = mock(FreeIpaClient.class);
RoleRequest roleRequest = new RoleRequest();
Host host = new Host();
when(ipaClient.showHost(HOST)).thenThrow(new FreeIpaClientException("notfound", new JsonRpcClientException(NOT_FOUND, "notfound", null))).thenReturn(host);
when(ipaClient.addHost(HOST)).thenThrow(new FreeIpaClientException("duplicate", new JsonRpcClientException(DUPLICATE_ENTRY.getValue(), "duplicate", null)));
Host result = underTest.addHost(HOST, roleRequest, ipaClient);
verify(ipaClient).allowHostKeytabRetrieval(HOST, FreeIpaClientFactory.ADMIN_USER);
ArgumentCaptor<Optional<Service>> serviceCaptor = ArgumentCaptor.forClass(Optional.class);
ArgumentCaptor<Optional<Host>> hostCaptor = ArgumentCaptor.forClass(Optional.class);
verify(roleComponent).addRoleAndPrivileges(serviceCaptor.capture(), hostCaptor.capture(), eq(roleRequest), eq(ipaClient));
assertTrue(serviceCaptor.getValue().isEmpty());
assertEquals(host, hostCaptor.getValue().get());
assertEquals(host, result);
}
use of com.googlecode.jsonrpc4j.JsonRpcClientException in project cloudbreak by hortonworks.
the class ServiceKeytabServiceTest method testGenerateExistingNotCachedServiceMissing.
@Test
public void testGenerateExistingNotCachedServiceMissing() throws FreeIpaClientException {
ServiceKeytabRequest request = new ServiceKeytabRequest();
request.setEnvironmentCrn(ENVIRONMENT_CRN);
request.setServiceName(SERVICE_NAME);
request.setServerHostName(HOST);
request.setDoNotRecreateKeytab(Boolean.TRUE);
request.setServerHostNameAlias(ALIAS);
RoleRequest roleRequest = new RoleRequest();
request.setRoleRequest(roleRequest);
when(keytabCacheService.findByEnvironmentCrnAndPrincipal(ENVIRONMENT_CRN, PRINCIPAL)).thenReturn(Optional.empty());
FreeIpaClient ipaClient = mock(FreeIpaClient.class);
when(freeIpaClientFactory.getFreeIpaClientForStack(stack)).thenReturn(ipaClient);
when(roleComponent.privilegesExist(roleRequest, ipaClient)).thenReturn(Boolean.TRUE);
Service service = new Service();
service.setKrbcanonicalname(PRINCIPAL);
service.setHasKeytab(Boolean.TRUE);
when(ipaClient.showService(PRINCIPAL)).thenThrow(new FreeIpaClientException("notfound", new JsonRpcClientException(NOT_FOUND.getValue(), "notfound", null)));
when(ipaClient.addService(PRINCIPAL)).thenReturn(service);
when(keytabCommonService.constructPrincipal(SERVICE_NAME, ALIAS, REALM)).thenReturn(ALIAS_PRINCIPAL);
when(keytabCommonService.getExistingKeytab(ENVIRONMENT_CRN, PRINCIPAL, HOST, ipaClient)).thenReturn(keytabCache);
ServiceKeytabResponse result = underTest.generateServiceKeytab(request, ACCOUNT_ID);
verify(ipaClient).addServiceAlias(PRINCIPAL, ALIAS_PRINCIPAL);
verify(roleComponent).addRoleAndPrivileges(Optional.of(service), Optional.empty(), roleRequest, ipaClient);
assertEquals(keytabResponse, result.getKeytab());
assertEquals(principalResponse, result.getServicePrincipal());
}
use of com.googlecode.jsonrpc4j.JsonRpcClientException in project cloudbreak by hortonworks.
the class ServiceKeytabServiceTest method testGenerateExistingNotCachedDoNotRecreateTrueAliasExists.
@Test
public void testGenerateExistingNotCachedDoNotRecreateTrueAliasExists() throws FreeIpaClientException {
ServiceKeytabRequest request = new ServiceKeytabRequest();
request.setEnvironmentCrn(ENVIRONMENT_CRN);
request.setServiceName(SERVICE_NAME);
request.setServerHostName(HOST);
request.setDoNotRecreateKeytab(Boolean.TRUE);
request.setServerHostNameAlias(ALIAS);
RoleRequest roleRequest = new RoleRequest();
request.setRoleRequest(roleRequest);
when(keytabCacheService.findByEnvironmentCrnAndPrincipal(ENVIRONMENT_CRN, PRINCIPAL)).thenReturn(Optional.empty());
FreeIpaClient ipaClient = mock(FreeIpaClient.class);
when(freeIpaClientFactory.getFreeIpaClientForStack(stack)).thenReturn(ipaClient);
when(roleComponent.privilegesExist(roleRequest, ipaClient)).thenReturn(Boolean.TRUE);
Service service = new Service();
service.setKrbcanonicalname(PRINCIPAL);
service.setHasKeytab(Boolean.TRUE);
when(ipaClient.showService(PRINCIPAL)).thenReturn(service);
when(keytabCommonService.constructPrincipal(SERVICE_NAME, ALIAS, REALM)).thenReturn(ALIAS_PRINCIPAL);
when(keytabCommonService.getExistingKeytab(ENVIRONMENT_CRN, PRINCIPAL, HOST, ipaClient)).thenReturn(keytabCache);
doThrow(new FreeIpaClientException("notfound", new JsonRpcClientException(EXECUTION_ERROR.getValue(), "notfound", null))).when(ipaClient).addServiceAlias(PRINCIPAL, ALIAS_PRINCIPAL);
ServiceKeytabResponse result = underTest.generateServiceKeytab(request, ACCOUNT_ID);
verify(roleComponent).addRoleAndPrivileges(Optional.of(service), Optional.empty(), roleRequest, ipaClient);
assertEquals(keytabResponse, result.getKeytab());
assertEquals(principalResponse, result.getServicePrincipal());
}
Aggregations