use of com.sequenceiq.freeipa.api.v1.kerberosmgmt.model.RoleRequest in project cloudbreak by hortonworks.
the class HostKeytabServiceTest method testGenerateHostKeytabGetExisting.
@Test
public void testGenerateHostKeytabGetExisting() throws FreeIpaClientException {
HostKeytabRequest request = new HostKeytabRequest();
request.setEnvironmentCrn(ENVIRONMENT_CRN);
request.setRoleRequest(new RoleRequest());
request.setDoNotRecreateKeytab(Boolean.TRUE);
request.setServerHostName("asdf");
Stack stack = new Stack();
when(keytabCommonService.getFreeIpaStackWithMdcContext(request.getEnvironmentCrn(), ACCOUNT_ID)).thenReturn(stack);
FreeIpaClient freeIpaClient = mock(FreeIpaClient.class);
when(freeIpaClientFactory.getFreeIpaClientForStack(stack)).thenReturn(freeIpaClient);
when(roleComponent.privilegesExist(request.getRoleRequest(), freeIpaClient)).thenReturn(Boolean.TRUE);
Host host = new Host();
host.setHasKeytab(Boolean.TRUE);
host.setKrbprincipalname("dfdf");
when(keytabCommonService.addHost(request.getServerHostName(), request.getRoleRequest(), freeIpaClient)).thenReturn(host);
KeytabCache keytabCache = mock(KeytabCache.class);
Secret keytabSecret = new Secret("keytab", "keytabSecret");
Secret principalSecret = new Secret("principal", "principalSecret");
when(keytabCache.getKeytab()).thenReturn(keytabSecret);
when(keytabCache.getPrincipal()).thenReturn(principalSecret);
when(keytabCommonService.getExistingKeytab(request.getEnvironmentCrn(), host.getKrbprincipalname(), request.getServerHostName(), freeIpaClient)).thenReturn(keytabCache);
SecretResponse keytabResponse = new SecretResponse();
keytabResponse.setSecretPath("keytabPath");
when(secretResponseConverter.convert(keytabCache.getKeytab().getSecret())).thenReturn(keytabResponse);
SecretResponse principalResponse = new SecretResponse();
principalResponse.setSecretPath("principalPath");
when(secretResponseConverter.convert(keytabCache.getPrincipal().getSecret())).thenReturn(principalResponse);
HostKeytabResponse response = underTest.generateHostKeytab(request, ACCOUNT_ID);
assertEquals(keytabResponse, response.getKeytab());
assertEquals(principalResponse, response.getHostPrincipal());
}
use of com.sequenceiq.freeipa.api.v1.kerberosmgmt.model.RoleRequest in project cloudbreak by hortonworks.
the class KeytabCommonServiceTest method testAddHostALlowKeytabRetrievalError.
@Test
public void testAddHostALlowKeytabRetrievalError() throws FreeIpaClientException {
FreeIpaClient ipaClient = mock(FreeIpaClient.class);
RoleRequest roleRequest = new RoleRequest();
Host host = new Host();
when(ipaClient.showHost(HOST)).thenReturn(host);
doThrow(new FreeIpaClientException("expected")).when(ipaClient).allowHostKeytabRetrieval(HOST, FreeIpaClientFactory.ADMIN_USER);
assertThrows(KeytabCreationException.class, () -> underTest.addHost(HOST, roleRequest, ipaClient));
}
use of com.sequenceiq.freeipa.api.v1.kerberosmgmt.model.RoleRequest 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.sequenceiq.freeipa.api.v1.kerberosmgmt.model.RoleRequest in project cloudbreak by hortonworks.
the class KeytabCommonServiceTest method testAddHostAlreadyExists.
@Test
public void testAddHostAlreadyExists() throws FreeIpaClientException {
FreeIpaClient ipaClient = mock(FreeIpaClient.class);
RoleRequest roleRequest = new RoleRequest();
Host host = new Host();
when(ipaClient.showHost(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.sequenceiq.freeipa.api.v1.kerberosmgmt.model.RoleRequest 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);
}
Aggregations