test: share one profile across three signed-request enforcement classes (#5952)

Slice 13 of #4542.

StsFederationCallerEnforcementIntegrationTest and
StsPresignedSignatureIntegrationTest each declared an identical profile
turning on signature validation and IAM enforcement.
CloudWatchQueryGetSignatureIntegrationTest declared the same two plus
S3 auth enforcement. All three now share SignedIamEnforcementProfile,
which sets all three, so three nested profiles become one.

S3 auth enforcement only acts on requests routed to S3, and neither STS
class sends one. No class fails with it off, CloudWatch's included; it
stays so that the CloudWatch class's signed S3 request still runs under
S3's own access checks, as the class was written to.

The profile's javadoc lists each override, the classes that rely on it,
and why it is inert for the others. Each class gains a javadoc saying
what it tests and what it gets from the profile. All three already
delete what they create.
This commit is contained in:
Priamo Germosen authored and GitHub committed 2026-10-18 20:43:34 -05:00
1 parent 401f5ce2d7
commit 9c205f7654
4 files changed
+68 -30

No files matched your search

@@ -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;
@@ -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 {
@@ -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"})
@@ -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");
}
}