private void doSignAndVerifyTest(AmbryUrlSigningService signer, RestMethod restMethod, Time time) throws Exception {
    long urlTtl = Math.min(Utils.getRandomLong(TestUtils.RANDOM, 2000) + 2000, MAX_URL_TTL_SECS);
    String randomHeaderVal = TestUtils.getRandomString(10);
    long maxUploadSize = Utils.getRandomLong(TestUtils.RANDOM, 4001) + 2000;

    // all defaults overridden
    RestRequest request = getUrlSignRequest(restMethod, urlTtl, randomHeaderVal, maxUploadSize, false);
    String url = signer.getSignedUrl(request);
    verifySignedUrl(signer, url, restMethod, randomHeaderVal, maxUploadSize, Utils.Infinite_Time, false);
    time.sleep(TimeUnit.SECONDS.toMillis(urlTtl + 1));
    ensureVerificationFailure(signer, getRequestFromUrl(restMethod, url), RestServiceErrorCode.Unauthorized);
    // chunk upload case, should use special stitched chunk upload settings.
    request = getUrlSignRequest(restMethod, urlTtl, randomHeaderVal, maxUploadSize, true);
    url = signer.getSignedUrl(request);
    verifySignedUrl(signer, url, restMethod, randomHeaderVal, CHUNK_UPLOAD_MAX_CHUNK_SIZE,
        CHUNK_UPLOAD_INITIAL_CHUNK_TTL_SECS, true);
    time.sleep(TimeUnit.SECONDS.toMillis(urlTtl + 1));
    ensureVerificationFailure(signer, getRequestFromUrl(restMethod, url), RestServiceErrorCode.Unauthorized);
    // no defaults overridden
    request = getUrlSignRequest(restMethod, Utils.Infinite_Time, randomHeaderVal, null, false);
    url = signer.getSignedUrl(request);
    verifySignedUrl(signer, url, restMethod, randomHeaderVal, DEFAULT_MAX_UPLOAD_SIZE, Utils.Infinite_Time, false);
    // change RestMethod and ensure verification failure
    ensureVerificationFailure(signer, getRequestFromUrl(RestMethod.UNKNOWN, url), RestServiceErrorCode.Unauthorized);
    time.sleep(TimeUnit.SECONDS.toMillis(DEFAULT_URL_TTL_SECS + 1));
    ensureVerificationFailure(signer, getRequestFromUrl(restMethod, url), RestServiceErrorCode.Unauthorized);
  }
Generates and verifies signed URLs. Also tests some failure scenarios.
@param signer the {@link AmbryUrlSigningService} to use.
@param restMethod the {@link RestMethod} to verify.
@param time the {@link Time} instance to use.
@throws Exception
ambry-frontend/src/test/java/com/github/ambry/frontend/AmbryUrlSigningServiceTest.java