From fe197dd7f382b55d24f2b9405143509fd001e4b7 Mon Sep 17 00:00:00 2001 From: Sergey Beryozkin Date: Thu, 13 Jul 2023 12:36:35 +0100 Subject: [PATCH] Add CORS regex test --- .../vertx/http/cors/CORSRegexTestCase.java | 36 +++++++++++++++++++ .../test/resources/conf/cors-regex.properties | 2 ++ 2 files changed, 38 insertions(+) create mode 100644 extensions/vertx-http/deployment/src/test/java/io/quarkus/vertx/http/cors/CORSRegexTestCase.java create mode 100644 extensions/vertx-http/deployment/src/test/resources/conf/cors-regex.properties diff --git a/extensions/vertx-http/deployment/src/test/java/io/quarkus/vertx/http/cors/CORSRegexTestCase.java b/extensions/vertx-http/deployment/src/test/java/io/quarkus/vertx/http/cors/CORSRegexTestCase.java new file mode 100644 index 0000000000000..7c841062ac5ef --- /dev/null +++ b/extensions/vertx-http/deployment/src/test/java/io/quarkus/vertx/http/cors/CORSRegexTestCase.java @@ -0,0 +1,36 @@ +package io.quarkus.vertx.http.cors; + +import static io.restassured.RestAssured.given; +import static org.hamcrest.core.IsNull.nullValue; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import io.quarkus.test.QuarkusUnitTest; + +public class CORSRegexTestCase { + + @RegisterExtension + static QuarkusUnitTest runner = new QuarkusUnitTest() + .withApplicationRoot((jar) -> jar + .addClasses(BeanRegisteringRoute.class) + .addAsResource("conf/cors-regex.properties", "application.properties")); + + @Test + public void corsRegexValidOriginTest() { + given().header("Origin", "https://asdf.domain.com") + .when() + .get("/test").then() + .statusCode(200) + .header("Access-Control-Allow-Origin", "https://asdf.domain.com"); + } + + @Test + public void corsRegexInvalidOriginTest() { + given().header("Origin", "https://asdfdomain.com") + .when() + .get("/test").then() + .statusCode(403) + .header("Access-Control-Allow-Origin", nullValue()); + } +} diff --git a/extensions/vertx-http/deployment/src/test/resources/conf/cors-regex.properties b/extensions/vertx-http/deployment/src/test/resources/conf/cors-regex.properties new file mode 100644 index 0000000000000..38571679f275e --- /dev/null +++ b/extensions/vertx-http/deployment/src/test/resources/conf/cors-regex.properties @@ -0,0 +1,2 @@ +quarkus.http.cors=true +quarkus.http.cors.origins=/https:\\/\\/(?:[a-z0-9\\-]+\\\\.)*domain\\\\.com/ \ No newline at end of file