use of com.sequenceiq.freeipa.client.model.Host in project cloudbreak by hortonworks.
the class HostDeletionServiceTest method testOneFailedDeletion.
@Test
public void testOneFailedDeletion() throws FreeIpaClientException {
Set<String> hosts = Set.of("host1", "host2");
Host host1 = new Host();
host1.setFqdn("host1");
Host host2 = new Host();
host2.setFqdn("host2");
when(freeIpaClient.findAllHost()).thenReturn(Set.of(host1, host2));
when(freeIpaClient.deleteHost(host2.getFqdn())).thenThrow(new FreeIpaClientException("not handled"));
Pair<Set<String>, Map<String, String>> result = underTest.removeHosts(freeIpaClient, hosts);
assertEquals(1, result.getFirst().size());
assertEquals(1, result.getSecond().size());
assertTrue(result.getFirst().contains(host1.getFqdn()));
assertTrue(result.getSecond().keySet().contains(host2.getFqdn()));
assertTrue(result.getSecond().values().contains("not handled"));
}
use of com.sequenceiq.freeipa.client.model.Host in project cloudbreak by hortonworks.
the class HostDeletionServiceTest method successfulDeletionIfAllHostReturned.
@Test
public void successfulDeletionIfAllHostReturned() throws FreeIpaClientException {
Set<String> hosts = Set.of("host1", "host2");
Host host1 = new Host();
host1.setFqdn("host1");
Host host2 = new Host();
host2.setFqdn("host2");
when(freeIpaClient.findAllHost()).thenReturn(Set.of(host1, host2));
Pair<Set<String>, Map<String, String>> result = underTest.removeHosts(freeIpaClient, hosts);
assertTrue(result.getSecond().isEmpty());
assertEquals(2, result.getFirst().size());
assertTrue(result.getFirst().contains(host1.getFqdn()));
assertTrue(result.getFirst().contains(host2.getFqdn()));
verify(freeIpaClient).deleteHost(eq("host1"));
verify(freeIpaClient).deleteHost(eq("host2"));
}
use of com.sequenceiq.freeipa.client.model.Host in project cloudbreak by hortonworks.
the class KerberosMgmtRoleComponentV1Test method testAddRoleAndPrivilegesForHostWithRoleRaceCondition.
@Test
public void testAddRoleAndPrivilegesForHostWithRoleRaceCondition() throws Exception {
Host host = new Host();
host.setFqdn(HOST);
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())).thenThrow(new FreeIpaClientException("duplicate", new JsonRpcClientException(FreeIpaErrorCodes.DUPLICATE_ENTRY.getValue(), "duplicate", null)));
Privilege privilege = new Privilege();
Set<String> hosts = new HashSet<>();
hosts.add(HOST);
Set<String> noServices = new HashSet<>();
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.empty(), Optional.of(host), roleRequest, mockIpaClient);
Mockito.verify(mockIpaClient).addRole(ROLE);
Mockito.verify(mockIpaClient).addRolePrivileges(ROLE, privileges);
Mockito.verify(mockIpaClient).addRoleMember(ROLE, null, null, hosts, null, noServices);
}
use of com.sequenceiq.freeipa.client.model.Host in project cloudbreak by hortonworks.
the class KerberosMgmtRoleComponentV1Test method testAddRoleAndPrivilegesForHostWithRoleThatAlreadyExists.
@Test
public void testAddRoleAndPrivilegesForHostWithRoleThatAlreadyExists() throws Exception {
Host host = new Host();
host.setFqdn(HOST);
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);
Privilege privilege = new Privilege();
Set<String> hosts = new HashSet<>();
hosts.add(HOST);
Set<String> noServices = new HashSet<>();
Mockito.when(mockIpaClient.showPrivilege(any())).thenReturn(privilege);
Mockito.when(mockIpaClient.addRolePrivileges(any(), any())).thenReturn(role);
Mockito.when(mockIpaClient.showRole(anyString())).thenReturn(role);
Mockito.when(mockIpaClient.addRoleMember(any(), any(), any(), any(), any(), any())).thenReturn(role);
underTest.addRoleAndPrivileges(Optional.empty(), Optional.of(host), roleRequest, mockIpaClient);
Mockito.verify(mockIpaClient).addRolePrivileges(ROLE, privileges);
Mockito.verify(mockIpaClient).addRoleMember(ROLE, null, null, hosts, null, noServices);
}
use of com.sequenceiq.freeipa.client.model.Host in project cloudbreak by hortonworks.
the class KerberosMgmtRoleComponentV1Test method testAddRoleAndPrivilegesForHostWithoutRole.
@Test
public void testAddRoleAndPrivilegesForHostWithoutRole() throws Exception {
Host host = new Host();
host.setFqdn(HOST);
RoleRequest roleRequest = null;
underTest.addRoleAndPrivileges(Optional.empty(), Optional.of(host), roleRequest, mockIpaClient);
Mockito.verifyNoInteractions(mockIpaClient);
}
Aggregations