private void setUpAuthServerAndRegistry(int maxAuthTokens, @Nullable String finalResponse)
      throws IOException, InterruptedException, GeneralSecurityException, URISyntaxException {
    String tokenResponse = "HTTP/1.1 200 OK\nContent-Length: 26\n\n{\"token\":\"awesome-token!\"}";
    authServer = new TestWebServer(false, Arrays.asList(tokenResponse), maxAuthTokens);

    String bearerAuth =
        "HTTP/1.1 401 Unauthorized\nContent-Length: 0\nWWW-Authenticate: Bearer realm=\""
            + authServer.getEndpoint()
            + "\"\n\n";
    List<String> responses = new ArrayList<>(Collections.nCopies(maxAuthTokens, bearerAuth));
    if (finalResponse != null) {
      responses.add(finalResponse);
    }

    registry = new TestWebServer(false, responses, responses.size(), true);
  }
Sets up an auth server and a registry. The auth server can return a bearer token up to {@code
maxAuthTokens} times. The registry will initially return "401 Unauthorized" for {@code
maxTokenResponses} times. (Therefore, a registry client has to get auth tokens from the auth
server {@code maxAuthTokens} times. After that, the registry returns {@code finalResponse}.
jib-core/src/test/java/com/google/cloud/tools/jib/registry/RegistryClientTest.java