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.java index 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. + * + *

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 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.java index 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. + * + *

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 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.java index 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. + * + *

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 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.java new file mode 100644 index 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. + * + *

The overrides, and who relies on them: + *

+ */ +public class SignedIamEnforcementProfile implements QuarkusTestProfile { + + @Override + public Map getConfigOverrides() { + return Map.of( + "floci.auth.validate-signatures", "true", + "floci.services.iam.enforcement-enabled", "true", + "floci.services.s3.enforce-auth", "true"); + } +}