Skip to content
Permalink
Browse files
Ensure that redirects are followed when verifying webrev links
Reviewed-by: ehelin
  • Loading branch information
rwestberg committed Jan 16, 2020
1 parent 771a56c commit e6e05bcb1a227147726dc7c63936a955d1264678
Showing 3 changed files with 16 additions and 3 deletions.
@@ -150,6 +150,7 @@ private void awaitPublication(URI uri, Duration timeout) throws IOException {
var uriBuilder = URIBuilder.base(uri);
var client = HttpClient.newBuilder()
.connectTimeout(Duration.ofSeconds(30))
.followRedirects(HttpClient.Redirect.NORMAL)
.build();
while (Instant.now().isBefore(end)) {
var uncachedUri = uriBuilder.setQuery(Map.of("nocache", UUID.randomUUID().toString())).build();
@@ -70,8 +70,9 @@ void overwriteExisting(TestInfo testInfo) throws IOException {
var generator = storage.generator(pr, prRepo, scratchFolder);
generator.generate(masterHash, editHash, "00");

// Check that the web link has been verified now
// Check that the web link has been verified now and followed the redirect
assertTrue(webrevServer.isChecked());
assertTrue(webrevServer.isRedirectFollowed());

// Update the local repository and check that the webrev has been generated
Repository.materialize(repoFolder, archive.url(), "webrev");
@@ -32,17 +32,24 @@
public class TestWebrevServer implements AutoCloseable {
private final HttpServer httpServer;
private boolean checked = false;
private boolean redirectFollowed = true;

private class Handler implements HttpHandler {
@Override
public void handle(HttpExchange exchange) throws IOException {
checked = true;
var response = "ok!";
var responseBytes = response.getBytes(StandardCharsets.UTF_8);
exchange.sendResponseHeaders(200, responseBytes.length);
if (!exchange.getRequestURI().toString().contains("final=true")) {
exchange.getResponseHeaders().add("Location", exchange.getRequestURI().toString() + "&final=true");
exchange.sendResponseHeaders(302, responseBytes.length);
} else {
redirectFollowed = true;
exchange.sendResponseHeaders(200, responseBytes.length);
}
OutputStream outputStream = exchange.getResponseBody();
outputStream.write(responseBytes);
outputStream.close();
checked = true;
}
}

@@ -62,6 +69,10 @@ public boolean isChecked() {
return checked;
}

public boolean isRedirectFollowed() {
return redirectFollowed;
}

@Override
public void close() throws IOException {
httpServer.stop(0);

0 comments on commit e6e05bc

Please sign in to comment.