@Test void testRenewCertificateWhenCertGenerationIsTriggerableAndDnsEntryShouldBeCreated() throws IOException { SecurityConfig securityConfig = new SecurityConfig(); securityConfig.setUserFacingCert("CERT"); securityConfig.setUserFacingKey(USER_FACING_PRIVATE_KEY); Cluster cluster = TestUtil.cluster(); Stack stack = cluster.getStack(); stack.setSecurityConfig(securityConfig); stack.setCluster(cluster); String envName = "anEnvName"; DetailedEnvironmentResponse environment = DetailedEnvironmentResponse.Builder .builder() .withName(envName) .build(); when(environmentClientService.getByCrn(Mockito.anyString())).thenReturn(environment); String accountWorkloadSubdomain = "aWorkloadSubdomain"; UserManagementProto.Account umsAccount = UserManagementProto.Account.newBuilder() .setWorkloadSubdomain(accountWorkloadSubdomain) .build(); when(grpcUmsClient.getAccountDetails(USER_CRN, "123", Optional.empty())).thenReturn(umsAccount); String endpointName = stack.getPrimaryGatewayInstance().getShortHostname(); String commonName = "hashofshorthostname.anenvname.xcu2-8y8x.dev.cldr.work"; when(domainNameProvider.getCommonName(endpointName, envName, accountWorkloadSubdomain)).thenReturn(commonName); String fqdn = endpointName + ".anenvname.xcu2-8y8x.dev.cldr.work"; when(domainNameProvider.getFullyQualifiedEndpointName(endpointName, envName, accountWorkloadSubdomain)).thenReturn(fqdn); when(certificateCreationService.create(eq(USER_CRN), eq("123"), eq(endpointName), eq(envName), any(PKCS10CertificationRequest.class))) .thenReturn(List.of()); when(dnsManagementService.createOrUpdateDnsEntryWithIp(anyString(), anyString(), anyString(), anyString(), anyBoolean(), any())).thenReturn(true); boolean result = ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.renewCertificate(stack)); verify(environmentClientService, times(2)).getByCrn(anyString()); verify(grpcUmsClient, times(2)).getAccountDetails(USER_CRN, "123", Optional.empty()); verify(domainNameProvider, times(1)).getCommonName(endpointName, envName, accountWorkloadSubdomain); verify(domainNameProvider, times(2)).getFullyQualifiedEndpointName(endpointName, envName, accountWorkloadSubdomain); verify(certificateCreationService, times(1)) .create(eq(USER_CRN), eq("123"), eq(endpointName), eq(envName), any(PKCS10CertificationRequest.class)); verify(securityConfigService, times(1)).save(any(SecurityConfig.class)); verify(dnsManagementService, times(1)).createOrUpdateDnsEntryWithIp(anyString(), anyString(), anyString(), anyString(), anyBoolean(), any()); verify(clusterService, times(1)).save(cluster); Assertions.assertEquals(Boolean.TRUE, result); }
public boolean renewCertificate(Stack stack) { boolean result = true; if (isCertRenewalTriggerable(stack)) { LOGGER.info("Renew certificate for stack: '{}'", stack.getName()); result = generateCertAndSaveForStack(stack); if (StringUtils.isEmpty(stack.getCluster().getFqdn())) { LOGGER.info("The cluster doesn't have public DNS entry, starting to create one."); updateDnsEntryForCluster(stack); } } return result; }
GatewayPublicEndpointManagementService extends BasePublicEndpointManagementService { public boolean renewCertificate(Stack stack) { boolean result = true; if (isCertRenewalTriggerable(stack)) { LOGGER.info("Renew certificate for stack: '{}'", stack.getName()); result = generateCertAndSaveForStack(stack); if (StringUtils.isEmpty(stack.getCluster().getFqdn())) { LOGGER.info("The cluster doesn't have public DNS entry, starting to create one."); updateDnsEntryForCluster(stack); } } return result; } }
GatewayPublicEndpointManagementService extends BasePublicEndpointManagementService { public boolean renewCertificate(Stack stack) { boolean result = true; if (isCertRenewalTriggerable(stack)) { LOGGER.info("Renew certificate for stack: '{}'", stack.getName()); result = generateCertAndSaveForStack(stack); if (StringUtils.isEmpty(stack.getCluster().getFqdn())) { LOGGER.info("The cluster doesn't have public DNS entry, starting to create one."); updateDnsEntryForCluster(stack); } } return result; }  }
GatewayPublicEndpointManagementService extends BasePublicEndpointManagementService { public boolean renewCertificate(Stack stack) { boolean result = true; if (isCertRenewalTriggerable(stack)) { LOGGER.info("Renew certificate for stack: '{}'", stack.getName()); result = generateCertAndSaveForStack(stack); if (StringUtils.isEmpty(stack.getCluster().getFqdn())) { LOGGER.info("The cluster doesn't have public DNS entry, starting to create one."); updateDnsEntryForCluster(stack); } } return result; }  boolean isCertRenewalTriggerable(Stack stack); boolean generateCertAndSaveForStackAndUpdateDnsEntry(Stack stack); String updateDnsEntry(Stack stack, String gatewayIp); String deleteDnsEntry(Stack stack, String environmentName); boolean renewCertificate(Stack stack); }
GatewayPublicEndpointManagementService extends BasePublicEndpointManagementService { public boolean renewCertificate(Stack stack) { boolean result = true; if (isCertRenewalTriggerable(stack)) { LOGGER.info("Renew certificate for stack: '{}'", stack.getName()); result = generateCertAndSaveForStack(stack); if (StringUtils.isEmpty(stack.getCluster().getFqdn())) { LOGGER.info("The cluster doesn't have public DNS entry, starting to create one."); updateDnsEntryForCluster(stack); } } return result; }  boolean isCertRenewalTriggerable(Stack stack); boolean generateCertAndSaveForStackAndUpdateDnsEntry(Stack stack); String updateDnsEntry(Stack stack, String gatewayIp); String deleteDnsEntry(Stack stack, String environmentName); boolean renewCertificate(Stack stack);  }