use of com.sequenceiq.freeipa.api.v1.kerberosmgmt.model.RoleRequest in project cloudbreak by hortonworks.
the class ServiceKeytabServiceTest method testGenerateExistingCachedDoNotRecreateFalse.
@Test
public void testGenerateExistingCachedDoNotRecreateFalse() throws FreeIpaClientException {
ServiceKeytabRequest request = new ServiceKeytabRequest();
request.setEnvironmentCrn(ENVIRONMENT_CRN);
request.setServiceName(SERVICE_NAME);
request.setServerHostName(HOST);
request.setDoNotRecreateKeytab(Boolean.FALSE);
request.setServerHostNameAlias(ALIAS);
RoleRequest roleRequest = new RoleRequest();
request.setRoleRequest(roleRequest);
when(keytabCacheService.findByEnvironmentCrnAndPrincipal(ENVIRONMENT_CRN, PRINCIPAL)).thenReturn(Optional.of(keytabCache));
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);
when(ipaClient.showService(PRINCIPAL)).thenReturn(service);
when(keytabCommonService.constructPrincipal(SERVICE_NAME, ALIAS, REALM)).thenReturn(ALIAS_PRINCIPAL);
when(keytabCommonService.getKeytab(ENVIRONMENT_CRN, PRINCIPAL, HOST, ipaClient)).thenReturn(keytabCache);
ServiceKeytabResponse result = underTest.generateServiceKeytab(request, ACCOUNT_ID);
verify(keytabCommonService).addHost(eq(HOST), isNull(), eq(ipaClient));
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.sequenceiq.freeipa.api.v1.kerberosmgmt.model.RoleRequest 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.sequenceiq.freeipa.api.v1.kerberosmgmt.model.RoleRequest 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.api.v1.kerberosmgmt.model.RoleRequest 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.api.v1.kerberosmgmt.model.RoleRequest 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