@Test
public void testPostInstanceRefreshRequest() throws IOException {

    Path path = Paths.get("src/test/resources/valid.csr");
    String certCsr = new String(Files.readAllBytes(path));
    InstanceRefreshRequest req = new InstanceRefreshRequest().setCsr(certCsr);
    SimplePrincipal principal = (SimplePrincipal) SimplePrincipal.create("athenz",
            "syncer", "v=S1,d=athenz;n=syncer;s=sig", 0, new PrincipalAuthority());
    principal.setKeyId("0");
    String publicKeyName = "athenz.syncer_0";
    final String ztsPublicKey = "-----BEGIN PUBLIC KEY-----\n"
            + "MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAKrvfvBgXWqWAorw5hYJu3dpOJe0gp3n\n"
            + "TgiiPGT7+jzm6BRcssOBTPFIMkePT2a8Tq+FYSmFnHfbQjwmYw2uMK8CAwEAAQ==\n"
            + "-----END PUBLIC KEY-----";
    zts.dataStore.getPublicKeyCache().put(publicKeyName, ztsPublicKey);
    HttpServletRequest servletRequest = Mockito.mock(HttpServletRequest.class);
    Mockito.when(servletRequest.isSecure()).thenReturn(true);
    ResourceContext context = createResourceContext(principal, servletRequest);
    Identity identity = zts.postInstanceRefreshRequest(context, "athenz", "syncer", req);
    assertNotNull(identity);
    X509Certificate cert = Crypto.loadX509Certificate(identity.getCertificate());
    assertNotNull(cert);
    // request same identity with expiry time
    req.setExpiryTime(1000);
    identity = zts.postInstanceRefreshRequest(context, "athenz", "syncer", req);
    assertNotNull(identity);
}