Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

workaround for issue with CORS and Origin: null in vertx-web #711

Merged
merged 1 commit into from
Apr 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion server/src/main/java/io/kroki/server/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,10 @@ static void start(Vertx vertx, JsonObject config, Handler<AsyncResult<HttpServer
allowedMethods.add(HttpMethod.GET);
allowedMethods.add(HttpMethod.POST);
allowedMethods.add(HttpMethod.OPTIONS);
router.route().handler(CorsHandler.create("*")
// REMIND: In order to accept requests with `Origin: null` header, we are using the value ".*" instead of "*".
// This can be reverted back to "*" once https://github.com/vert-x3/vertx-web/issues/1933 is fixed.
// Reference: https://github.com/yuzutech/kroki/pull/711
router.route().handler(CorsHandler.create(".*")
ggrossetie marked this conversation as resolved.
Show resolved Hide resolved
.allowedHeaders(allowedHeaders)
.allowedMethods(allowedMethods));

Expand Down
24 changes: 24 additions & 0 deletions server/src/test/java/io/kroki/server/ServerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,30 @@ void http_server_check_response(Vertx vertx, VertxTestContext testContext) {
})));
}

@Test
void http_server_check_cors_handling_regular_origin(Vertx vertx, VertxTestContext testContext) {
WebClient client = WebClient.create(vertx);
client.get(port, "localhost", "/")
.putHeader("Origin", "http://localhost")
.as(BodyCodec.string())
.send(testContext.succeeding(response -> testContext.verify(() -> {
assertThat(response.statusCode()).isEqualTo(200);
testContext.completeNow();
})));
}

@Test
void http_server_check_cors_handling_null_origin(Vertx vertx, VertxTestContext testContext) {
WebClient client = WebClient.create(vertx);
client.get(port, "localhost", "/")
.putHeader("Origin", "null")
.as(BodyCodec.string())
.send(testContext.succeeding(response -> testContext.verify(() -> {
assertThat(response.statusCode()).isEqualTo(200);
testContext.completeNow();
})));
}

ggrossetie marked this conversation as resolved.
Show resolved Hide resolved
@Test
void http_server_long_uri_414(Vertx vertx, VertxTestContext testContext) {
WebClient client = WebClient.create(vertx);
Expand Down