use of com.googlecode.jsonrpc4j.JsonRpcClientException in project cloudbreak by hortonworks.
the class DnsRecordServiceTest method testCnameRecordAddEmptyModListIgnored.
@Test
public void testCnameRecordAddEmptyModListIgnored() throws FreeIpaClientException {
AddDnsCnameRecordRequest request = new AddDnsCnameRecordRequest();
request.setEnvironmentCrn(ENV_CRN);
request.setCname("Asdf");
request.setTargetFqdn(TARGET_FQDN);
Stack stack = createStack();
when(stackService.getByEnvironmentCrnAndAccountId(ENV_CRN, ACCOUNT_ID)).thenReturn(stack);
FreeIpa freeIpa = createFreeIpa();
when(freeIpaService.findByStack(stack)).thenReturn(freeIpa);
when(freeIpaClientFactory.getFreeIpaClientForStack(stack)).thenReturn(freeIpaClient);
JsonRpcClientException noModEx = new JsonRpcClientException(FreeIpaErrorCodes.EMPTY_MODLIST.getValue(), "no modifications to be performed", null);
when(freeIpaClient.addDnsCnameRecord(DOMAIN, request.getCname(), request.getTargetFqdn())).thenThrow(new FreeIpaClientException("can't create", noModEx));
underTest.addDnsCnameRecord(ACCOUNT_ID, request);
verify(freeIpaClient).addDnsCnameRecord(DOMAIN, request.getCname(), request.getTargetFqdn());
}
use of com.googlecode.jsonrpc4j.JsonRpcClientException in project cloudbreak by hortonworks.
the class FreeIpaUsersStateProviderTest method testGetFilteredFreeIpaState.
@Test
void testGetFilteredFreeIpaState() throws Exception {
List<String> user1GroupNames = List.of("group1", "group2");
List<String> user2GroupNames = List.of("group2", "group3", IPA_UNMANAGED_GROUPS.get(0));
List<String> groupsWithoutMembers = List.of("group4");
com.sequenceiq.freeipa.client.model.User user1 = createIpaUser("user1", user1GroupNames);
String userNotFound = "userNotFound";
Set<com.sequenceiq.freeipa.client.model.Group> groupsFindAll = Stream.of(user1GroupNames.stream(), user2GroupNames.stream(), groupsWithoutMembers.stream(), IPA_UNMANAGED_GROUPS.stream()).flatMap(groupName -> groupName).map(this::createIpaGroup).collect(Collectors.toSet());
JsonRpcClientException jsonRpcException = new JsonRpcClientException(FreeIpaErrorCodes.NOT_FOUND.getValue(), "group not found", null);
FreeIpaClientException notFoundException = new FreeIpaClientException("Invoke FreeIPA failed", jsonRpcException);
when(freeIpaClient.userShow(user1.getUid())).thenReturn(user1);
when(freeIpaClient.userShow(userNotFound)).thenThrow(notFoundException);
when(freeIpaClient.groupFindAll()).thenReturn(groupsFindAll);
Set<String> expectedUsers = Sets.newHashSet(user1.getUid());
Set<String> expectedGroups = groupsFindAll.stream().map(com.sequenceiq.freeipa.client.model.Group::getCn).filter(groupName -> !IPA_UNMANAGED_GROUPS.contains(groupName)).collect(Collectors.toSet());
UserMetadata user1Metadata = new UserMetadata("user1-crn", 1L);
doReturn(Optional.of(user1Metadata)).when(userMetadataConverter).toUserMetadata(argThat(arg -> user1.getUid().equals(arg.getUid())));
Map<String, UserMetadata> expectedUserMetadata = Map.of(user1.getUid(), user1Metadata);
UsersState ipaState = underTest.getFilteredFreeIpaState(freeIpaClient, Set.of(user1.getUid(), userNotFound));
for (FmsUser fmsUser : ipaState.getUsers()) {
assertTrue(expectedUsers.contains(fmsUser.getName()));
expectedUsers.remove(fmsUser.getName());
}
assertTrue(expectedUsers.isEmpty());
for (FmsGroup fmsGroup : ipaState.getGroups()) {
assertTrue(expectedGroups.contains(fmsGroup.getName()));
expectedGroups.remove(fmsGroup.getName());
}
assertTrue(expectedGroups.isEmpty());
assertEquals(expectedUserMetadata, ipaState.getUserMetadataMap());
}
use of com.googlecode.jsonrpc4j.JsonRpcClientException in project cloudbreak by hortonworks.
the class ServiceKeytabServiceTest method testGenerateExistingNotCachedServiceMissingAddThrowDuplicate.
@Test
public void testGenerateExistingNotCachedServiceMissingAddThrowDuplicate() 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))).thenReturn(service);
when(ipaClient.addService(PRINCIPAL)).thenThrow(new FreeIpaClientException("notfound", new JsonRpcClientException(DUPLICATE_ENTRY.getValue(), "notfound", null)));
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 CleanupServiceTest method testRemoveDnsEntries.
@Test
public void testRemoveDnsEntries() throws FreeIpaClientException {
FreeIpaClient client = mock(FreeIpaClient.class);
when(freeIpaClientFactory.getFreeIpaClientForStackId(STACK_ID)).thenReturn(client);
DnsZone dnsZone = new DnsZone();
String domain = "test.com";
dnsZone.setIdnsname(domain);
DnsZone reverseZone = new DnsZone();
reverseZone.setIdnsname("0.10.in-addr.arpa.");
DnsZone disappearingZone = new DnsZone();
disappearingZone.setIdnsname("disappear");
when(client.findAllDnsZone()).thenReturn(Set.of(dnsZone, reverseZone, disappearingZone));
DnsRecord deleteMe = new DnsRecord();
deleteMe.setIdnsname("deleteMe");
deleteMe.setArecord(List.of("ignored"));
DnsRecord notFound = new DnsRecord();
notFound.setIdnsname("notfound");
notFound.setArecord(List.of("ignored"));
DnsRecord failed = new DnsRecord();
failed.setIdnsname("failed");
failed.setArecord(List.of("ignored"));
DnsRecord ptrRecord = new DnsRecord();
ptrRecord.setIdnsname("1.0");
ptrRecord.setPtrrecord(List.of("ptrRecord"));
when(client.findAllDnsRecordInZone(dnsZone.getIdnsname())).thenReturn(Set.of(deleteMe, notFound, failed));
when(client.deleteDnsRecord(failed.getIdnsname(), domain)).thenThrow(new FreeIpaClientException("delete failed"));
when(client.deleteDnsRecord(notFound.getIdnsname(), domain)).thenThrow(new FreeIpaClientException("Not found", new JsonRpcClientException(FreeIpaErrorCodes.NOT_FOUND.getValue(), "Not found", null)));
when(client.findAllDnsRecordInZone(reverseZone.getIdnsname())).thenReturn(Set.of(ptrRecord));
when(client.findAllDnsRecordInZone(disappearingZone.getIdnsname())).thenThrow(new FreeIpaClientException("Not found zone", new JsonRpcClientException(FreeIpaErrorCodes.NOT_FOUND.getValue(), "Not found", null)));
Pair<Set<String>, Map<String, String>> result = cleanupService.removeDnsEntries(STACK_ID, Set.of(deleteMe.getIdnsname(), notFound.getIdnsname(), failed.getIdnsname(), "ptrRecord"), Set.of("10.0.0.1", "10.1.0.1"), domain);
verify(client).deleteDnsRecord(deleteMe.getIdnsname(), domain);
assertTrue(result.getFirst().containsAll(Set.of(deleteMe.getIdnsname(), notFound.getIdnsname(), "10.0.0.1")));
assertTrue(result.getSecond().containsKey(failed.getIdnsname()));
assertEquals("delete failed", result.getSecond().get(failed.getIdnsname()));
assertEquals(1, result.getSecond().size());
assertEquals(3, result.getFirst().size());
}
use of com.googlecode.jsonrpc4j.JsonRpcClientException in project cloudbreak by hortonworks.
the class DnsRecordServiceTest method testDeleteIgnoreNotFound.
@Test
public void testDeleteIgnoreNotFound() throws FreeIpaClientException {
Stack stack = createStack();
when(stackService.getByEnvironmentCrnAndAccountId(ENV_CRN, ACCOUNT_ID)).thenReturn(stack);
FreeIpa freeIpa = createFreeIpa();
when(freeIpaService.findByStack(stack)).thenReturn(freeIpa);
when(freeIpaClientFactory.getFreeIpaClientForStack(stack)).thenReturn(freeIpaClient);
when(freeIpaClient.deleteDnsRecord("asdf", DOMAIN)).thenThrow(new FreeIpaClientException("Not found", new JsonRpcClientException(FreeIpaErrorCodes.NOT_FOUND.getValue(), "Not found", null)));
underTest.deleteDnsRecord(ACCOUNT_ID, ENV_CRN, null, "asdf");
}
Aggregations