Skip to content

armgit / floci

Public Imported from GitHub
0

Light, fluffy, and always free - The AWS Local Emulator alternative

test: retire two redundant test profiles and revive three CORS tests that never ran (#4609)

Priamo Germosen8c2ceb5aa137
diff --git a/src/test/java/io/github/hectorvent/floci/core/common/GlobalCorsFilterDefaultIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/core/common/GlobalCorsFilterDefaultIntegrationTest.java
new file mode 100644
index 0000000000..8121749bcb
--- /dev/null
+++ b/src/test/java/io/github/hectorvent/floci/core/common/GlobalCorsFilterDefaultIntegrationTest.java
@@ -0,0 +1,48 @@
+package io.github.hectorvent.floci.core.common;
+
+import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
+import io.quarkus.test.junit.QuarkusTest;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+
+import static io.restassured.RestAssured.given;
+import static org.hamcrest.Matchers.nullValue;
+
+/**
+ * With the configured defaults, no extra origin is allowed, so the global filter adds no CORS
+ * headers for a browser origin, on a preflight or on the actual request.
+ */
+@QuarkusTest
+class GlobalCorsFilterDefaultIntegrationTest {
+
+ @BeforeAll
+ static void configureRestAssured() {
+ RestAssuredJsonUtils.configureAwsContentTypes();
+ }
+
+ @Test
+ void preflightReturnsForbiddenWithoutCorsHeaders() {
+ given()
+ .header("Origin", "http://localhost:3000")
+ .header("Access-Control-Request-Method", "PUT")
+ .when()
+ .options("/my-bucket/some-key")
+ .then()
+ .statusCode(403)
+ .header("Access-Control-Allow-Origin", nullValue());
+ }
+
+ @Test
+ void actualRequestGetsNoCorsHeaders() {
+ given()
+ .header("Origin", "http://localhost:3000")
+ .header("X-Amz-Target", "DynamoDB_20120810.ListTables")
+ .contentType("application/x-amz-json-1.0")
+ .body("{}")
+ .when()
+ .post("/")
+ .then()
+ .statusCode(200)
+ .header("Access-Control-Allow-Origin", nullValue());
+ }
+}
diff --git a/src/test/java/io/github/hectorvent/floci/core/common/GlobalCorsFilterIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/core/common/GlobalCorsFilterIntegrationTest.java
index 39c09b3f91..c4c7c48d19 100644
--- a/src/test/java/io/github/hectorvent/floci/core/common/GlobalCorsFilterIntegrationTest.java
+++ b/src/test/java/io/github/hectorvent/floci/core/common/GlobalCorsFilterIntegrationTest.java
@@ -146,76 +146,4 @@ class GlobalCorsFilterIntegrationTest {
"floci.security.cors-allow-private-network", "true");
}
}
-
- @QuarkusTest
- @TestProfile(PrivateNetworkDefaultOffTest.CorsPnaDefaultProfile.class)
- static class PrivateNetworkDefaultOffTest {
-
- @BeforeAll
- static void configureRestAssured() {
- RestAssuredJsonUtils.configureAwsContentTypes();
- }
-
- @Test
- void privateNetworkAccessNotGrantedByDefault() {
- given()
- .header("Origin", "http://localhost:3000")
- .header("Access-Control-Request-Method", "POST")
- .header("Access-Control-Request-Private-Network", "true")
- .when()
- .options("/")
- .then()
- .statusCode(204)
- .header("Access-Control-Allow-Origin", equalTo("http://localhost:3000"))
- .header("Access-Control-Allow-Private-Network", nullValue());
- }
-
- // Only origins set — cors-allow-private-network left at its (off) default.
- public static final class CorsPnaDefaultProfile implements QuarkusTestProfile {
- @Override
- public Map<String, String> getConfigOverrides() {
- return Map.of("floci.security.extra-cors-allowed-origins", "http://localhost:3000");
- }
- }
- }
-
- @QuarkusTest
- @TestProfile(DisabledGlobalCorsFilterTest.DisabledCorsProfile.class)
- static class DisabledGlobalCorsFilterTest {
-
- @BeforeAll
- static void configureRestAssured() {
- RestAssuredJsonUtils.configureAwsContentTypes();
- }
-
- @Test
- void preflightReturnsForbiddenWithoutCorsHeaders() {
- given()
- .header("Origin", "http://localhost:3000")
- .header("Access-Control-Request-Method", "PUT")
- .when()
- .options("/my-bucket/some-key")
- .then()
- .statusCode(403)
- .header("Access-Control-Allow-Origin", nullValue());
- }
-
- @Test
- void actualRequestGetsNoCorsHeaders() {
- given()
- .header("Origin", "http://localhost:3000")
- .header("X-Amz-Target", "DynamoDB_20120810.ListTables")
- .contentType("application/x-amz-json-1.0")
- .body("{}")
- .when()
- .post("/")
- .then()
- .statusCode(200)
- .header("Access-Control-Allow-Origin", nullValue());
- }
-
- public static final class DisabledCorsProfile implements QuarkusTestProfile {
- // No config overrides, testing default application.yml values
- }
- }
}
diff --git a/src/test/java/io/github/hectorvent/floci/core/common/GlobalCorsFilterPrivateNetworkDefaultIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/core/common/GlobalCorsFilterPrivateNetworkDefaultIntegrationTest.java
new file mode 100644
index 0000000000..51b9900259
--- /dev/null
+++ b/src/test/java/io/github/hectorvent/floci/core/common/GlobalCorsFilterPrivateNetworkDefaultIntegrationTest.java
@@ -0,0 +1,40 @@
+package io.github.hectorvent.floci.core.common;
+
+import io.github.hectorvent.floci.testing.ExtraCorsOriginProfile;
+import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
+import io.quarkus.test.junit.QuarkusTest;
+import io.quarkus.test.junit.TestProfile;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+
+import static io.restassured.RestAssured.given;
+import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.nullValue;
+
+/**
+ * An extra allowed origin on its own does not grant private network access:
+ * {@code cors-allow-private-network} stays at its off default.
+ */
+@QuarkusTest
+@TestProfile(ExtraCorsOriginProfile.class)
+class GlobalCorsFilterPrivateNetworkDefaultIntegrationTest {
+
+ @BeforeAll
+ static void configureRestAssured() {
+ RestAssuredJsonUtils.configureAwsContentTypes();
+ }
+
+ @Test
+ void privateNetworkAccessNotGrantedByDefault() {
+ given()
+ .header("Origin", ExtraCorsOriginProfile.ORIGIN)
+ .header("Access-Control-Request-Method", "POST")
+ .header("Access-Control-Request-Private-Network", "true")
+ .when()
+ .options("/")
+ .then()
+ .statusCode(204)
+ .header("Access-Control-Allow-Origin", equalTo(ExtraCorsOriginProfile.ORIGIN))
+ .header("Access-Control-Allow-Private-Network", nullValue());
+ }
+}
diff --git a/src/test/java/io/github/hectorvent/floci/services/apigateway/ApiGatewayPreflightRoutingIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/apigateway/ApiGatewayPreflightRoutingIntegrationTest.java
index 8db230e503..5c1a0981b4 100644
--- a/src/test/java/io/github/hectorvent/floci/services/apigateway/ApiGatewayPreflightRoutingIntegrationTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/apigateway/ApiGatewayPreflightRoutingIntegrationTest.java
@@ -1,7 +1,7 @@
package io.github.hectorvent.floci.services.apigateway;
+import io.github.hectorvent.floci.testing.ExtraCorsOriginProfile;
import io.quarkus.test.junit.QuarkusTest;
-import io.quarkus.test.junit.QuarkusTestProfile;
import io.quarkus.test.junit.TestProfile;
import io.restassured.http.ContentType;
import org.junit.jupiter.api.MethodOrderer;
@@ -9,8 +9,6 @@ import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder;
-import java.util.Map;
-
import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.notNullValue;
@@ -26,13 +24,16 @@ import static org.hamcrest.Matchers.notNullValue;
* {@code /execute-api/...} path must be skipped by the filter and routed all the way to the
* integration. This test drives that full chain — filter skip → route match → OPTIONS/ANY
* method resolution → integration invocation — so a regression in any single stage fails here.</p>
+ *
+ * <p>Global CORS has to be on for this to mean anything: without the deployed-path exclusion, the
+ * filter would answer the preflight itself and the integration would never run.</p>
*/
@QuarkusTest
-@TestProfile(ApiGatewayPreflightRoutingIntegrationTest.CorsEnabledProfile.class)
+@TestProfile(ExtraCorsOriginProfile.class)
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
class ApiGatewayPreflightRoutingIntegrationTest {
- private static final String ORIGIN = "http://localhost:3000";
+ private static final String ORIGIN = ExtraCorsOriginProfile.ORIGIN;
private static final String STAGE = "cors";
private static String apiId;
@@ -261,13 +262,4 @@ class ApiGatewayPreflightRoutingIntegrationTest {
given().when().delete("/restapis/" + apiId).then().statusCode(202);
given().when().delete("/v2/apis/" + httpApiId).then().statusCode(204);
}
-
- public static final class CorsEnabledProfile implements QuarkusTestProfile {
- @Override
- public Map<String, String> getConfigOverrides() {
- // Global CORS on: without the deployed-path exclusion, this filter would answer the
- // preflight itself and the integration would never run.
- return Map.of("floci.security.extra-cors-allowed-origins", ORIGIN);
- }
- }
}
diff --git a/src/test/java/io/github/hectorvent/floci/services/eks/EksRoute53DnsDockerIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/eks/EksRoute53DnsDockerIntegrationTest.java
index 354cb852b3..b88852aee0 100644
--- a/src/test/java/io/github/hectorvent/floci/services/eks/EksRoute53DnsDockerIntegrationTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/eks/EksRoute53DnsDockerIntegrationTest.java
@@ -11,8 +11,6 @@ import io.github.hectorvent.floci.services.route53.model.ResourceRecord;
import io.github.hectorvent.floci.services.route53.model.ResourceRecordSet;
import io.github.hectorvent.floci.services.route53.model.VpcAssociation;
import io.quarkus.test.junit.QuarkusTest;
-import io.quarkus.test.junit.QuarkusTestProfile;
-import io.quarkus.test.junit.TestProfile;
import jakarta.inject.Inject;
import org.jboss.logging.Logger;
import org.junit.jupiter.api.AfterEach;
@@ -29,18 +27,15 @@ import java.util.UUID;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
+/**
+ * Enables embedded DNS on the container it starts itself, so it needs no profile and runs on the
+ * default one alongside the other EKS Docker classes. It needs Docker and a bound embedded DNS
+ * server, and that server only binds when Floci itself runs in a container, so anywhere else the
+ * class skips.
+ */
@QuarkusTest
-@TestProfile(EksRoute53DnsDockerIntegrationTest.Profile.class)
class EksRoute53DnsDockerIntegrationTest {
- public static final class Profile implements QuarkusTestProfile {
- @Override
- public Map<String, String> getConfigOverrides() {
- return Map.of(
- "floci.services.eks.embedded-dns", "true");
- }
- }
-
private static final Logger LOG = Logger.getLogger(EksRoute53DnsDockerIntegrationTest.class);
private static final String TEST_IMAGE = "alpine:3.21";
diff --git a/src/test/java/io/github/hectorvent/floci/services/s3/S3BlockPublicAccessEnforcementIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/s3/S3BlockPublicAccessEnforcementIntegrationTest.java
index 0bd32f1fea..85dccda55b 100644
--- a/src/test/java/io/github/hectorvent/floci/services/s3/S3BlockPublicAccessEnforcementIntegrationTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/s3/S3BlockPublicAccessEnforcementIntegrationTest.java
@@ -1,12 +1,11 @@
package io.github.hectorvent.floci.services.s3;
+import io.github.hectorvent.floci.testing.S3EnforceAuthProfile;
import io.github.hectorvent.floci.testutil.S3RequestSigner;
import io.quarkus.test.junit.QuarkusTest;
-import io.quarkus.test.junit.QuarkusTestProfile;
import io.quarkus.test.junit.TestProfile;
import org.junit.jupiter.api.Test;
-import java.util.Map;
import java.util.UUID;
import static io.restassured.RestAssured.given;
@@ -21,7 +20,7 @@ import static org.hamcrest.Matchers.equalTo;
* turns on.
*/
@QuarkusTest
-@TestProfile(S3BlockPublicAccessEnforcementIntegrationTest.EnforcementProfile.class)
+@TestProfile(S3EnforceAuthProfile.class)
class S3BlockPublicAccessEnforcementIntegrationTest {
private static final S3RequestSigner OWNER = S3RequestSigner.signedAs("test", "test");
@@ -32,13 +31,6 @@ class S3BlockPublicAccessEnforcementIntegrationTest {
"Resource":["arn:aws:s3:::%1$s","arn:aws:s3:::%1$s/*"]}]}
""";
- public static final class EnforcementProfile implements QuarkusTestProfile {
- @Override
- public Map<String, String> getConfigOverrides() {
- return Map.of("floci.services.s3.enforce-auth", "true");
- }
- }
-
@Test
void anonymousGetSucceedsOnAPublicPolicyWithoutRestrictPublicBuckets() {
String bucket = bucketWithPublicPolicy();
diff --git a/src/test/java/io/github/hectorvent/floci/testing/ExtraCorsOriginProfile.java b/src/test/java/io/github/hectorvent/floci/testing/ExtraCorsOriginProfile.java
new file mode 100644
index 0000000000..8229fbbf4f
--- /dev/null
+++ b/src/test/java/io/github/hectorvent/floci/testing/ExtraCorsOriginProfile.java
@@ -0,0 +1,21 @@
+package io.github.hectorvent.floci.testing;
+
+import io.quarkus.test.junit.QuarkusTestProfile;
+
+import java.util.Map;
+
+/**
+ * Allows one extra CORS origin, {@link #ORIGIN}, and leaves every other CORS setting at its
+ * default, including {@code cors-allow-private-network}. Quarkus restarts and re-augments the
+ * application once per distinct profile class, so the classes that need only this override share
+ * this one rather than each declaring an identical nested profile.
+ */
+public class ExtraCorsOriginProfile implements QuarkusTestProfile {
+
+ public static final String ORIGIN = "http://localhost:3000";
+
+ @Override
+ public Map<String, String> getConfigOverrides() {
+ return Map.of("floci.security.extra-cors-allowed-origins", ORIGIN);
+ }
+}