@Test
public void testValidateDnsNamesWithCnameValues() throws IOException {

    Path path = Paths.get("src/test/resources/athenz.instanceid.cname.csr");
    String csr = new String(Files.readAllBytes(path));
    String service = "athenz.production";
    X509CertRequest certReq = new X509CertRequest(csr);
    assertNotNull(certReq);
    DataCache athenzSysDomainCache = Mockito.mock(DataCache.class);
    Mockito.when(athenzSysDomainCache.getProviderDnsSuffixList("provider"))
            .thenReturn(Collections.singletonList("ostk.athenz.cloud"));
    List<String> allowedSuffixList = new ArrayList<>();
    allowedSuffixList.add("athenz.info");
    allowedSuffixList.add("athenz.cloud");
    Mockito.when(athenzSysDomainCache.getProviderHostnameAllowedSuffixList("provider"))
            .thenReturn(allowedSuffixList);
    Mockito.when(athenzSysDomainCache.getProviderHostnameDeniedSuffixList("provider"))
            .thenReturn(null);
    List<String> cnameList = new ArrayList<>();
    cnameList.add("cname1.athenz.info");
    cnameList.add("cname2.athenz.info");
    HostnameResolver resolver = Mockito.mock(HostnameResolver.class);
    Mockito.when(resolver.isValidHostCnameList(service, "host1.athenz.cloud", cnameList, CertType.X509))
            .thenReturn(false)
            .thenReturn(true);
    Mockito.when(resolver.isValidHostname("host1.athenz.cloud")).thenReturn(true);
    // first call we're going to get failure
    assertFalse(certReq.validateDnsNames("athenz", "production", "provider", athenzSysDomainCache,
            "ostk.athenz.cloud", "host1.athenz.cloud", cnameList, resolver));
    // second call is success
    assertTrue(certReq.validateDnsNames("athenz", "production", "provider", athenzSysDomainCache,
            "ostk.athenz.cloud", "host1.athenz.cloud", cnameList, resolver));
}