Light, fluffy, and always free - The AWS Local Emulator alternative
test: share one profile across three signed-request enforcement classes (#5952)
Priamo Germosen9c205f7654b9
diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudwatch/metrics/CloudWatchQueryGetSignatureIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudwatch/metrics/CloudWatchQueryGetSignatureIntegrationTest.javaindex 40562dfc6b..1a7448d289 100644--- a/src/test/java/io/github/hectorvent/floci/services/cloudwatch/metrics/CloudWatchQueryGetSignatureIntegrationTest.java+++ b/src/test/java/io/github/hectorvent/floci/services/cloudwatch/metrics/CloudWatchQueryGetSignatureIntegrationTest.java@@ -1,10 +1,10 @@package io.github.hectorvent.floci.services.cloudwatch.metrics;+import io.github.hectorvent.floci.testing.SignedIamEnforcementProfile;import io.github.hectorvent.floci.testutil.AwsRequestSigner;import io.github.hectorvent.floci.testutil.S3RequestSigner;import io.quarkus.test.common.http.TestHTTPResource;import io.quarkus.test.junit.QuarkusTest;-import io.quarkus.test.junit.QuarkusTestProfile;import io.quarkus.test.junit.TestProfile;import io.restassured.response.Response;import org.junit.jupiter.api.Test;@@ -23,19 +23,19 @@ import static org.hamcrest.Matchers.containsString;import static org.hamcrest.Matchers.equalTo;import static org.hamcrest.Matchers.not;+/**+ * Verifies that a CloudWatch Query GET request, signed in its headers or presigned, is+ * authenticated and then decided by IAM in the region it was signed for, and that an S3-signed+ * request to the root stays with S3.+ *+ * <p>Signature validation, IAM enforcement and S3 auth enforcement come from+ * {@link SignedIamEnforcementProfile}, which this class shares with the other classes that test+ * signed requests under IAM enforcement.+ */@QuarkusTest-@TestProfile(CloudWatchQueryGetSignatureIntegrationTest.Authentication.class)+@TestProfile(SignedIamEnforcementProfile.class)class CloudWatchQueryGetSignatureIntegrationTest {- public static class Authentication implements QuarkusTestProfile {- @Override- public Map<String, String> getConfigOverrides() {- return Map.of("floci.auth.validate-signatures", "true",- "floci.services.s3.enforce-auth", "true",- "floci.services.iam.enforcement-enabled", "true");- }- }-@TestHTTPResource("/")URI endpoint;diff --git a/src/test/java/io/github/hectorvent/floci/services/iam/StsFederationCallerEnforcementIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/iam/StsFederationCallerEnforcementIntegrationTest.javaindex 310cb78be3..603f80d0e8 100644--- a/src/test/java/io/github/hectorvent/floci/services/iam/StsFederationCallerEnforcementIntegrationTest.java+++ b/src/test/java/io/github/hectorvent/floci/services/iam/StsFederationCallerEnforcementIntegrationTest.java@@ -2,10 +2,10 @@ package io.github.hectorvent.floci.services.iam;import io.github.hectorvent.floci.services.iam.model.AccessKey;import io.github.hectorvent.floci.testing.PartitionCleanup;+import io.github.hectorvent.floci.testing.SignedIamEnforcementProfile;import io.github.hectorvent.floci.testutil.StsRequests;import io.github.hectorvent.floci.testutil.StsRequests.Credentials;import io.quarkus.test.junit.QuarkusTest;-import io.quarkus.test.junit.QuarkusTestProfile;import io.quarkus.test.junit.TestProfile;import io.restassured.response.Response;import jakarta.inject.Inject;@@ -22,8 +22,16 @@ import java.util.UUID;import static org.hamcrest.Matchers.equalTo;import static org.junit.jupiter.api.Assertions.assertNotNull;+/**+ * Verifies that STS refuses {@code GetFederationToken} to a caller with temporary credentials, only+ * once the request is authenticated, and that a long-term caller is still decided by its IAM+ * policies.+ *+ * <p>Signature validation and IAM enforcement come from {@link SignedIamEnforcementProfile}, which+ * this class shares with the other classes that test signed requests under IAM enforcement.+ */@QuarkusTest-@TestProfile(StsFederationCallerEnforcementIntegrationTest.SignedEnforcement.class)+@TestProfile(SignedIamEnforcementProfile.class)class StsFederationCallerEnforcementIntegrationTest {private static final String ACCOUNT = "000000000000";private static final String ALLOW_STS = "{\"Version\":\"2012-10-17\",\"Statement\":["@@ -32,13 +40,6 @@ class StsFederationCallerEnforcementIntegrationTest {@Inject IamService iam;@RegisterExtension final PartitionCleanup cleanup = new PartitionCleanup();- public static class SignedEnforcement implements QuarkusTestProfile {- @Override- public Map<String, String> getConfigOverrides() {- return Map.of("floci.auth.validate-signatures", "true", "floci.services.iam.enforcement-enabled", "true");- }- }-@ParameterizedTest@ValueSource(strings = {"GetFederationToken", "GetSessionToken", "AssumeRole"})void issuedTemporaryCallerKeepsExactRefusal(String issuer) throws Exception {diff --git a/src/test/java/io/github/hectorvent/floci/services/iam/StsPresignedSignatureIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/iam/StsPresignedSignatureIntegrationTest.javaindex bdfe8832d6..099095c255 100644--- a/src/test/java/io/github/hectorvent/floci/services/iam/StsPresignedSignatureIntegrationTest.java+++ b/src/test/java/io/github/hectorvent/floci/services/iam/StsPresignedSignatureIntegrationTest.java@@ -2,9 +2,9 @@ package io.github.hectorvent.floci.services.iam;import io.github.hectorvent.floci.core.common.Digests;import io.github.hectorvent.floci.core.common.auth.SigV4RequestValidator;+import io.github.hectorvent.floci.testing.SignedIamEnforcementProfile;import io.github.hectorvent.floci.testutil.AwsRequestSigner;import io.quarkus.test.junit.QuarkusTest;-import io.quarkus.test.junit.QuarkusTestProfile;import io.quarkus.test.junit.TestProfile;import io.restassured.RestAssured;import io.restassured.response.Response;@@ -33,19 +33,19 @@ import static org.junit.jupiter.api.Assertions.assertEquals;import static org.junit.jupiter.api.Assertions.assertNotNull;import static org.junit.jupiter.api.Assertions.assertTrue;+/**+ * Verifies SigV4 authentication carried in the query string: a presigned request authenticates its+ * caller only when its signature, scope, date and expiry are genuine, and the same verifier covers+ * JSON, REST and Query services.+ *+ * <p>Signature validation and IAM enforcement come from {@link SignedIamEnforcementProfile}, which+ * this class shares with the other classes that test signed requests under IAM enforcement.+ */@QuarkusTest-@TestProfile(StsPresignedSignatureIntegrationTest.SignaturesAndEnforcement.class)+@TestProfile(SignedIamEnforcementProfile.class)class StsPresignedSignatureIntegrationTest {@Inject IamService iam;- public static class SignaturesAndEnforcement implements QuarkusTestProfile {- @Override- public Map<String, String> getConfigOverrides() {- return Map.of("floci.auth.validate-signatures", "true",- "floci.services.iam.enforcement-enabled", "true");- }- }-@ParameterizedTest@ValueSource(strings = {"valid", "forged", "missing", "expired", "scope", "body", "future", "date", "expiry", "algorithm", "host", "blank","alias", "url-shadow", "duplicate", "signature-first", "encoded", "unknown", "inactive"})diff --git a/src/test/java/io/github/hectorvent/floci/testing/SignedIamEnforcementProfile.java b/src/test/java/io/github/hectorvent/floci/testing/SignedIamEnforcementProfile.javanew file mode 100644index 0000000000..ed328df9be--- /dev/null+++ b/src/test/java/io/github/hectorvent/floci/testing/SignedIamEnforcementProfile.java@@ -0,0 +1,37 @@+package io.github.hectorvent.floci.testing;++import io.quarkus.test.junit.QuarkusTestProfile;++import java.util.Map;++/**+ * Signature validation and IAM enforcement together, with S3 auth enforcement next to them, for+ * the classes that test how a signed request is authenticated before IAM decides it. Quarkus builds+ * the application once per distinct profile class, so they share this one rather than each+ * declaring their own.+ *+ * <p>The overrides, and who relies on them:+ * <ul>+ * <li>{@code floci.auth.validate-signatures=true} verifies every SigV4 signature, in the header+ * or the query string, and refuses a forged or unknown credential. Every class relies on it.</li>+ * <li>{@code floci.services.iam.enforcement-enabled=true} evaluates every request against the+ * caller's IAM policies. {@code StsFederationCallerEnforcementIntegrationTest} and+ * {@code CloudWatchQueryGetSignatureIntegrationTest} rely on it, for the refusals their IAM+ * users' policies decide; {@code StsPresignedSignatureIntegrationTest} passes with it off.</li>+ * <li>{@code floci.services.s3.enforce-auth=true} makes S3 run its own access checks, bucket+ * policies among them, on top of the signature check. No class fails with it off. It stays so+ * that the signed S3 request in {@code CloudWatchQueryGetSignatureIntegrationTest}, which must+ * reach S3 rather than CloudWatch, still runs under those checks, as that class was written to.+ * It only acts on requests routed to S3, and neither STS class sends one.</li>+ * </ul>+ */+public class SignedIamEnforcementProfile implements QuarkusTestProfile {++ @Override+ public Map<String, String> getConfigOverrides() {+ return Map.of(+ "floci.auth.validate-signatures", "true",+ "floci.services.iam.enforcement-enabled", "true",+ "floci.services.s3.enforce-auth", "true");+ }+}