fix(core): build and recognise AWS hostnames in every partition (#4451)

* fix(core): build and recognise AWS hostnames in every partition

AwsEndpoints builds the AWS-shaped hosts Floci returns from the region's partition DNS suffix: execute-api, the S3 bucket, regional, dual-stack and website hosts, Cognito and EKS OIDC issuers, APS, Bedrock AgentCore, AppSync and EC2 public DNS names. partitions.json records the regions whose S3 endpoint publishes a dual-stack variant, so DualStackDomainName is only returned there. The S3 virtual-host fallback, the execute-api host filter, the ECR image URI and the CloudFront S3-origin parsers recognise every published suffix, longest first. The CloudFront domain suffix Cognito and API Gateway mint comes from floci.services.cloudfront.domain-suffix.

Two commercial bugs go with it: WebsiteURL uses the dash form (s3-website-<region>) in the nine regions that keep it and ends with a slash, and EMR's public DNS name is compute-1 only in us-east-1.

Also carries the follow-ups from the #4444 review: accessDeniedResponse gets its Javadoc back in IamEnforcementFilter, IamAuthValidator's imports are in order, and the IAM test helper's pair loop cannot read past the array.

Part of #4272

* fix(core): keep CloudTrail S3 hosts and CFN dual-stack attributes consistent with their region

CloudTrail built an S3 data event's Host, TLS host header and resource ARNs from the request scope, but the log writer emits its own deliveries from the flush thread, where the request region falls back to the deployment default: a cn-north-1 trail's self-delivery record said awsRegion cn-north-1 with a .amazonaws.com host and an arn:aws: ARN. buildS3Record now takes the event region emitS3DataEvent already resolves and derives all of them from it.

AWS::S3::Bucket drops a prior DualStackDomainName when an update lands in a region without an S3 dual-stack endpoint, since provision receives the previous attributes on update.

* test(resourceexplorer2): check a regionless ARN's partition against the resource's region

The cn-north-1 CloudTrail self-delivery test left its bucket behind in the shared emulator, and ResourceExplorer2's partition assertion then failed on arn:aws-cn:s3:::loop-logs-..., a correct ARN: S3 ARNs carry no region, so the expected partition fell back to aws. The assertion now takes a regionless ARN's partition from the Region the listing reports, and skips it when that is not a published region (global resources). The CloudTrail test deletes its trail, objects and bucket after each case through PartitionCleanup.
This commit is contained in:
Hector Ventura authored and GitHub committed 2026-09-26 10:15:18 -04:00
1 parent df67d421f9
commit 2cccc73499
43 files changed
+617 -155

No files matched your search

@@ -0,0 +1,82 @@
package io.github.hectorvent.floci.core.common;
import io.github.hectorvent.floci.testing.PartitionMatrix;
import io.github.hectorvent.floci.testing.PartitionMatrix.PartitionCase;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import org.junit.jupiter.params.provider.MethodSource;
import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* The hostnames AWS-shaped response fields carry. The S3 website form and the EC2 public DNS
* name are the two shapes that are not a plain {@code service.region.suffix}, and both were
* wrong in the commercial partition before this helper existed.
*/
class AwsEndpointsTest {
@ParameterizedTest
@MethodSource("io.github.hectorvent.floci.testing.PartitionMatrix#cases")
void regionalHostsCarryThePartitionSuffix(PartitionCase partitionCase) {
String region = partitionCase.region();
PartitionMatrix.assertHostIn(partitionCase, AwsEndpoints.host("ec2", region));
assertEquals("ec2." + region + "." + partitionCase.dnsSuffix(), AwsEndpoints.host("ec2", region));
assertEquals("abc123.execute-api." + region + "." + partitionCase.dnsSuffix(),
AwsEndpoints.executeApiHost("abc123", region));
assertEquals("b.s3." + partitionCase.dnsSuffix(), AwsEndpoints.s3Host("b", region));
assertEquals("b.s3." + region + "." + partitionCase.dnsSuffix(), AwsEndpoints.s3RegionalHost("b", region));
assertEquals("b.s3.dualstack." + region + "." + partitionCase.dnsSuffix(), AwsEndpoints.s3DualStackHost("b", region));
}
/**
* The nine regions before the CDK's {@code RULE_S3_WEBSITE_REGIONAL_SUBDOMAIN} keep the
* dash form; everything after it uses the dot form. CloudFormation's own {@code WebsiteURL}
* example ends with a slash ({@code http://mystack-mybucket-kdwwxmddtr2g.s3-website-us-east-2.amazonaws.com/}).
*/
@ParameterizedTest
@CsvSource({
"us-east-1, b.s3-website-us-east-1.amazonaws.com",
"eu-west-1, b.s3-website-eu-west-1.amazonaws.com",
"us-west-1, b.s3-website-us-west-1.amazonaws.com",
"ap-southeast-1, b.s3-website-ap-southeast-1.amazonaws.com",
"ap-northeast-1, b.s3-website-ap-northeast-1.amazonaws.com",
"us-gov-west-1, b.s3-website-us-gov-west-1.amazonaws.com",
"us-west-2, b.s3-website-us-west-2.amazonaws.com",
"sa-east-1, b.s3-website-sa-east-1.amazonaws.com",
"ap-southeast-2, b.s3-website-ap-southeast-2.amazonaws.com",
"us-east-2, b.s3-website.us-east-2.amazonaws.com",
"eu-central-1, b.s3-website.eu-central-1.amazonaws.com",
"us-gov-east-1, b.s3-website.us-gov-east-1.amazonaws.com",
"cn-north-1, b.s3-website.cn-north-1.amazonaws.com.cn",
"us-iso-east-1, b.s3-website.us-iso-east-1.c2s.ic.gov",
"xx-nowhere-9, b.s3-website.xx-nowhere-9.amazonaws.com"})
void s3WebsiteHostUsesTheDashFormOnlyForTheNineLegacyRegions(String region, String host) {
assertEquals(host, AwsEndpoints.s3WebsiteHost("b", region));
assertEquals("http://" + host + "/", AwsEndpoints.s3WebsiteUrl("b", region));
}
@ParameterizedTest
@CsvSource({
"us-east-1, ec2-203-0-113-7.compute-1.amazonaws.com",
"us-west-2, ec2-203-0-113-7.us-west-2.compute.amazonaws.com",
"us-gov-west-1, ec2-203-0-113-7.us-gov-west-1.compute.amazonaws.com",
"cn-north-1, ec2-203-0-113-7.cn-north-1.compute.amazonaws.com.cn",
"eusc-de-east-1, ec2-203-0-113-7.eusc-de-east-1.compute.amazonaws.eu"})
void ec2PublicDnsIsComputeOneOnlyInVirginia(String region, String expected) {
assertEquals(expected, AwsEndpoints.ec2PublicDns("203.0.113.7", region));
}
@Test
void s3DualStackAvailabilityFollowsEndpointsJson() {
assertEquals(true, AwsPartitions.commercial().supportsS3DualStack("us-east-1"));
assertEquals(true, AwsPartitions.byId("aws-cn").supportsS3DualStack("cn-north-1"));
assertEquals(true, AwsPartitions.byId("aws-iso").supportsS3DualStack("us-iso-east-1"));
assertEquals(true, AwsPartitions.byId("aws-iso-b").supportsS3DualStack("us-isob-east-1"));
assertEquals(false, AwsPartitions.byId("aws-iso-b").supportsS3DualStack("us-isob-west-1"));
assertEquals(false, AwsPartitions.byId("aws-iso-e").supportsS3DualStack("eu-isoe-west-1"));
assertEquals(false, AwsPartitions.byId("aws-iso-f").supportsS3DualStack("us-isof-south-1"));
assertEquals(false, AwsPartitions.byId("aws-eusc").supportsS3DualStack("eusc-de-east-1"));
assertEquals(false, AwsPartitions.commercial().supportsS3DualStack(null));
}
}
@@ -14,6 +14,7 @@ import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.regex.Pattern;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
@@ -218,6 +219,23 @@ class AwsPartitionsTest {
assertTrue(AwsPartitions.stripKnownDnsSuffix(host).isEmpty());
}
@Test
void dnsSuffixHelpersRecogniseEveryPublishedSuffix() {
assertTrue(AwsPartitions.isDnsSuffix("amazonaws.com"));
assertTrue(AwsPartitions.isDnsSuffix("AMAZONAWS.COM.CN"));
assertTrue(AwsPartitions.isDnsSuffix("api.aws"));
assertTrue(AwsPartitions.isDnsSuffix("c2s.ic.gov"));
assertFalse(AwsPartitions.isDnsSuffix("localhost"));
assertFalse(AwsPartitions.isDnsSuffix("s3.amazonaws.com"));
assertFalse(AwsPartitions.isDnsSuffix(null));
Pattern host = Pattern.compile("^bucket\\.s3\\." + AwsPartitions.dnsSuffixRegex() + "$");
assertTrue(host.matcher("bucket.s3.amazonaws.com").matches());
assertTrue(host.matcher("bucket.s3.amazonaws.com.cn").matches());
assertTrue(host.matcher("bucket.s3.csp.hci.ic.gov").matches());
assertFalse(host.matcher("bucket.s3.amazonaws.com.evil").matches());
assertFalse(host.matcher("bucket.s3.amazonawsXcom").matches(), "the suffix dots are quoted");
}
@Test
void aMalformedCatalogFailsLoudly() {
assertThrows(IllegalStateException.class, () -> AwsPartitions.parse(
@@ -19,6 +19,7 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoInteractions;
@@ -43,7 +44,9 @@ class ApiGatewayDomainTlsServiceTest {
StorageFactory storageFactory = mock(StorageFactory.class);
when(storageFactory.create(anyString(), anyString(), any())).thenAnswer(invocation -> AccountAwareStorageBackend.inMemory("000000000000"));
certificateManager = mock(TlsCertificateManager.class);
service = new ApiGatewayService(storageFactory, mock(EmulatorConfig.class), certificateManager);
EmulatorConfig config = mock(EmulatorConfig.class, RETURNS_DEEP_STUBS);
when(config.services().cloudfront().domainSuffix()).thenReturn("cloudfront.net");
service = new ApiGatewayService(storageFactory, config, certificateManager);
}
private static Map<String, Object> regional(String domain) {
@@ -13,6 +13,7 @@ import org.mockito.ArgumentCaptor;
import java.util.Map;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
@@ -28,6 +29,7 @@ class S3CfnProvisionerTest {
private static final ObjectMapper MAPPER = new ObjectMapper();
private static final String REGION = "us-east-1";
private static final String NO_DUAL_STACK_REGION = "eu-isoe-west-1";
private S3Service s3;
private S3CfnProvisioner provisioner;
@@ -82,7 +84,9 @@ class S3CfnProvisionerTest {
"DomainName", "my-bucket.s3.amazonaws.com",
"RegionalDomainName", "my-bucket.s3.us-east-1.amazonaws.com",
"DualStackDomainName", "my-bucket.s3.dualstack.us-east-1.amazonaws.com",
"WebsiteURL", "http://my-bucket.s3-website.us-east-1.amazonaws.com",
// us-east-1 is one of the nine regions that keep the legacy dash form, and AWS's
// WebsiteURL ends with a slash (the AWS::S3::Bucket schema example).
"WebsiteURL", "http://my-bucket.s3-website-us-east-1.amazonaws.com/",
"BucketName", "my-bucket"), r.getAttributes());
}
@@ -121,6 +125,32 @@ class S3CfnProvisionerTest {
verify(s3).createBucket("renamed", REGION);
}
/** ISO-E publishes no S3 dual-stack endpoint, so the attribute is absent rather than invented. */
@Test
void aBucketInARegionWithoutS3DualStackHasNoDualStackDomainName() {
StackResource r = resource("Bucket", "AWS::S3::Bucket");
provisioner.provision(r, props("{\"BucketName\": \"my-bucket\"}"),
new ProvisionContext(ctx.engine(), NO_DUAL_STACK_REGION, "000000000000", "my-stack"));
assertEquals("my-bucket.s3.eu-isoe-west-1.cloud.adc-e.uk", r.getAttributes().get("RegionalDomainName"));
assertFalse(r.getAttributes().containsKey("DualStackDomainName"));
}
/**
* An update arrives with the prior attributes already on the resource, so a dual-stack host
* recorded before the region's availability was known has to be removed, not just not written.
*/
@Test
void anUpdateInARegionWithoutS3DualStackDropsAStaleDualStackDomainName() {
StackResource r = resource("Bucket", "AWS::S3::Bucket");
r.setPhysicalId("my-bucket");
r.getAttributes().put("DualStackDomainName", "my-bucket.s3.dualstack.eu-isoe-west-1.cloud.adc-e.uk");
provisioner.provision(r, props("{\"BucketName\": \"my-bucket\"}"),
new ProvisionContext(ctx.engine(), NO_DUAL_STACK_REGION, "000000000000", "my-stack", "my-bucket"));
assertFalse(r.getAttributes().containsKey("DualStackDomainName"), "attributes: " + r.getAttributes());
}
@Test
void anUnnamedBucketGetsALowerCasedStackScopedName() {
StackResource r = provisionBucket("{}");
@@ -225,6 +225,14 @@ class CloudFrontRequestRouterTest {
assertEquals("foo.s3-website-bar",
CloudFrontRequestRouter.bucketFromS3Domain(
"foo.s3-website-bar.s3.us-east-1.amazonaws.com"));
assertEquals("my-bucket",
CloudFrontRequestRouter.bucketFromS3Domain("my-bucket.s3.cn-north-1.amazonaws.com.cn"));
assertEquals("my-bucket",
CloudFrontRequestRouter.bucketFromS3Domain("my-bucket.s3.us-iso-east-1.c2s.ic.gov"));
assertEquals("my-bucket",
CloudFrontRequestRouter.bucketFromS3Domain("my-bucket.s3-fips.dualstack.us-gov-west-1.amazonaws.com"));
assertEquals("my-bucket",
CloudFrontRequestRouter.bucketFromS3Domain("my-bucket.s3-website.eusc-de-east-1.amazonaws.eu"));
assertNull(CloudFrontRequestRouter.bucketFromS3Domain("sensitive.attacker.invalid"));
assertNull(CloudFrontRequestRouter.bucketFromS3Domain("sensitive.s3.attacker.invalid"));
assertNull(CloudFrontRequestRouter.bucketFromS3Domain("sensitive.s3-attacker.invalid"));
@@ -2,11 +2,15 @@ package io.github.hectorvent.floci.services.cloudtrail;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.github.hectorvent.floci.testing.PartitionCleanup;
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
import io.github.hectorvent.floci.testutil.S3RequestSigner;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.response.Response;
import jakarta.inject.Inject;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import java.io.ByteArrayInputStream;
import java.util.ArrayList;
@@ -15,6 +19,8 @@ import java.util.UUID;
import java.util.zip.GZIPInputStream;
import static io.restassured.RestAssured.given;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
@@ -34,23 +40,68 @@ class CloudTrailSelfDeliveryTest {
@Inject
CloudTrailLogWriter writer;
@RegisterExtension
final PartitionCleanup cleanup = new PartitionCleanup();
@Test
void trailWithBlanketSelectorCapturesItsOwnLogDeliveryAsDataEvent() throws Exception {
List<JsonNode> selfDeliveries = selfDeliveryPutRecords("us-east-1", "arn:aws:s3:::");
assertFalse(selfDeliveries.isEmpty(),
"Expected a PutObject record for the trail's own CloudTrail log delivery "
+ "(self-referential / circular-logging reproduction) but found none");
}
/**
* The log writer emits its own deliveries from the flush thread, outside any request, so the
* record's hosts and ARNs must come from the event's region: a China trail's delivery names a
* China host and ARN, not the deployment default's.
*/
@Test
void selfDeliveryRecordNamesTheEventRegionsHostAndPartition() throws Exception {
List<JsonNode> selfDeliveries = selfDeliveryPutRecords("cn-north-1", "arn:aws-cn:s3:::");
assertFalse(selfDeliveries.isEmpty(), "no self-delivery record in cn-north-1");
for (JsonNode record : selfDeliveries) {
assertEquals("cn-north-1", record.path("awsRegion").asText());
String bucket = record.path("requestParameters").path("bucketName").asText();
assertEquals(bucket + ".s3.amazonaws.com.cn", record.path("requestParameters").path("Host").asText());
assertEquals(bucket + ".s3.amazonaws.com.cn",
record.path("tlsDetails").path("clientProvidedHostHeader").asText());
for (JsonNode resource : record.path("resources")) {
assertTrue(resource.path("ARN").asText().startsWith("arn:aws-cn:s3:::" + bucket),
"resource ARN: " + resource);
}
}
}
/**
* Creates a trail in {@code region} whose blanket S3 data-event selector matches its own
* destination bucket (the pathological "before" config, uc-build-loop: s3DataEvents true, no
* exclusions), flushes twice, and returns the PutObject records that describe the trail's own
* log-file writes. Delivery #1 writes a log file into the bucket; under the fix that write is
* itself a matching PutObject, so delivery #2 carries a record of it.
*/
private List<JsonNode> selfDeliveryPutRecords(String region, String selectorArnPrefix) throws Exception {
String suffix = UUID.randomUUID().toString().substring(0, 8);
String bucket = "loop-logs-" + suffix;
String trailName = "loop-trail-" + suffix;
S3RequestSigner s3 = S3RequestSigner.signedAs("test", "test").inRegion(region);
createBucket(bucket);
createBucket(bucket, s3);
// Runs last: the emulator is shared, and a leftover bucket shows up in every later
// cross-region listing (ResourceExplorer scans all resources).
cleanup.register(() -> deleteBucketAndObjects(bucket, s3));
invokeCloudTrail("CreateTrail", String.format("""
invokeCloudTrail(region, "CreateTrail", String.format("""
{"Name":"%s","S3BucketName":"%s"}
""", trailName, bucket))
.then().statusCode(200);
// Runs first, so the writer stops delivering into the bucket before it is emptied.
cleanup.register(() -> invokeCloudTrail(region, "DeleteTrail",
String.format("{\"Name\":\"%s\"}", trailName)).then().statusCode(200));
// Blanket selector: every S3 object in every bucket, including the
// trail's own delivery bucket. This is the pathological "before"
// config (uc-build-loop): s3DataEvents true, no exclusions.
invokeCloudTrail("PutEventSelectors", String.format("""
invokeCloudTrail(region, "PutEventSelectors", String.format("""
{
"TrailName": "%s",
"EventSelectors": [
@@ -58,90 +109,79 @@ class CloudTrailSelfDeliveryTest {
"ReadWriteType": "All",
"IncludeManagementEvents": false,
"DataResources": [
{"Type": "AWS::S3::Object", "Values": ["arn:aws:s3:::"]}
{"Type": "AWS::S3::Object", "Values": ["%s"]}
]
}
]
}
""", trailName))
""", trailName, selectorArnPrefix))
.then().statusCode(200);
invokeCloudTrail("StartLogging",
invokeCloudTrail(region, "StartLogging",
String.format("{\"Name\":\"%s\"}", trailName))
.then().statusCode(200);
// Seed one real data event so the first flush has something to
// deliver.
putObject(bucket, "seed.txt", "seed");
// Seed one real data event so the first flush has something to deliver.
putObject(bucket, "seed.txt", "seed", s3);
// Delivery #1: writes a log file into `bucket`. Under the fix, that
// write is itself a PutObject matching the blanket selector, so it
// must be queued for delivery #2.
writer.flushNow();
writer.flushNow();
// Delivery #2: should contain a record describing delivery #1's own
// log-file write, the self-referential loop.
writer.flushNow();
List<String> keys = new ArrayList<>();
for (String key : listKeys(bucket)) {
if (key.contains("/CloudTrail/") && key.endsWith(".json.gz")) {
keys.add(key);
}
}
assertTrue(keys.size() >= 2,
"Expected at least 2 delivered log files (seed delivery + self-referential delivery), got: "
+ keys);
boolean sawSelfReferentialPut = false;
ObjectMapper mapper = new ObjectMapper();
for (String key : keys) {
byte[] gz = given().when().get("/" + bucket + "/" + key)
List<JsonNode> selfDeliveries = new ArrayList<>();
for (String key : listKeys(bucket, s3)) {
if (!key.contains("/CloudTrail/") || !key.endsWith(".json.gz")) {
continue;
}
byte[] gz = given().filter(s3).when().get("/" + bucket + "/" + key)
.then().statusCode(200).extract().asByteArray();
byte[] json;
try (GZIPInputStream gzin = new GZIPInputStream(new ByteArrayInputStream(gz))) {
json = gzin.readAllBytes();
}
JsonNode records = mapper.readTree(json).get("Records");
for (JsonNode rec : records) {
String eventName = rec.path("eventName").asText();
String recBucket = rec.path("requestParameters").path("bucketName").asText(null);
String recKey = rec.path("requestParameters").path("key").asText("");
if ("PutObject".equals(eventName) && bucket.equals(recBucket)
for (JsonNode record : mapper.readTree(json).get("Records")) {
String recBucket = record.path("requestParameters").path("bucketName").asText(null);
String recKey = record.path("requestParameters").path("key").asText("");
if ("PutObject".equals(record.path("eventName").asText()) && bucket.equals(recBucket)
&& recKey.contains("/CloudTrail/")) {
sawSelfReferentialPut = true;
selfDeliveries.add(record);
}
}
}
assertTrue(sawSelfReferentialPut,
"Expected a PutObject record for the trail's own CloudTrail log delivery "
+ "(self-referential / circular-logging reproduction) but found none in "
+ keys.size() + " delivered files");
return selfDeliveries;
}
// --- Helpers ---
private static io.restassured.response.Response invokeCloudTrail(String action, String body) {
private static Response invokeCloudTrail(String region, String action, String body) {
return given()
.header("X-Amz-Target", CT_TARGET + action)
.header("Authorization", "AWS4-HMAC-SHA256 Credential=test/20260101/" + region
+ "/cloudtrail/aws4_request, SignedHeaders=host, Signature=abc")
.contentType(JSON11)
.body(body)
.when().post("/");
}
private static void createBucket(String name) {
given().when().put("/" + name).then().statusCode(200);
private static void createBucket(String name, S3RequestSigner signer) {
given().filter(signer).when().put("/" + name).then().statusCode(200);
}
private static void putObject(String bucket, String key, String body) {
given().body(body)
private static void putObject(String bucket, String key, String body, S3RequestSigner signer) {
given().filter(signer).body(body)
.when().put("/" + bucket + "/" + key)
.then().statusCode(200);
}
private static List<String> listKeys(String bucket) {
String xml = given().when().get("/" + bucket + "?list-type=2")
private static void deleteBucketAndObjects(String bucket, S3RequestSigner signer) {
for (String key : listKeys(bucket, signer)) {
given().filter(signer).when().delete("/" + bucket + "/" + key).then().statusCode(204);
}
given().filter(signer).when().delete("/" + bucket).then().statusCode(204);
}
private static List<String> listKeys(String bucket, S3RequestSigner signer) {
String xml = given().filter(signer).when().get("/" + bucket + "?list-type=2")
.then().statusCode(200).extract().asString();
List<String> keys = new ArrayList<>();
int from = 0;
@@ -82,6 +82,7 @@ class CognitoServiceTest {
groupStore,
revokedTokenStore,
"http://localhost:4566",
"cloudfront.net",
regionResolver,
null,
acmService
@@ -1798,6 +1799,7 @@ class CognitoServiceTest {
new InMemoryStorage<>(),
new InMemoryStorage<>(),
"http://localhost:4566",
"cloudfront.net",
regionResolver,
null,
acmService,
@@ -1838,6 +1840,7 @@ class CognitoServiceTest {
new InMemoryStorage<>(),
new InMemoryStorage<>(),
"http://localhost:4566",
"cloudfront.net",
regionResolver,
null,
acmService,
@@ -1959,6 +1962,7 @@ class CognitoServiceTest {
new InMemoryStorage<>(),
new InMemoryStorage<>(),
"http://localhost:4566",
"cloudfront.net",
regionResolver,
null,
acmService,
@@ -2022,6 +2026,7 @@ class CognitoServiceTest {
new InMemoryStorage<>(),
new InMemoryStorage<>(),
"http://localhost:4566",
"cloudfront.net",
regionResolver,
null,
acmService,
@@ -2132,6 +2137,7 @@ class CognitoServiceTest {
new InMemoryStorage<>(),
new InMemoryStorage<>(),
"http://localhost:4566",
"cloudfront.net",
regionResolver,
null,
acmService,
@@ -2660,6 +2666,7 @@ class CognitoServiceTest {
new InMemoryStorage<>(),
new InMemoryStorage<>(),
"http://localhost:4566",
"cloudfront.net",
regionResolver,
null,
acmService,
@@ -2715,6 +2722,7 @@ class CognitoServiceTest {
new InMemoryStorage<>(),
new InMemoryStorage<>(),
"http://localhost:4566",
"cloudfront.net",
regionResolver,
null,
acmService,
@@ -2772,6 +2780,7 @@ class CognitoServiceTest {
new InMemoryStorage<>(),
new InMemoryStorage<>(),
"http://localhost:4566",
"cloudfront.net",
regionResolver,
null,
acmService,
@@ -2824,6 +2833,7 @@ class CognitoServiceTest {
new InMemoryStorage<>(),
new InMemoryStorage<>(),
"http://localhost:4566",
"cloudfront.net",
regionResolver,
null,
acmService,
@@ -2865,6 +2875,7 @@ class CognitoServiceTest {
new InMemoryStorage<>(),
new InMemoryStorage<>(),
"http://localhost:4566",
"cloudfront.net",
regionResolver,
null,
acmService,
@@ -346,6 +346,16 @@ class EcrRegistryManagerTest {
assertEquals("http://floci-aws-run-one-test-ecr-registry:5000", manager.httpClient().baseUrl());
}
@Test
void rewriteImageUri_matchesAChinaEcrUri_rewritesToLocalRegistry() {
when(lifecycleManager.createAndStart(any())).thenReturn(
new ContainerLifecycleManager.ContainerInfo("container-id", Map.of()));
String rewritten = manager.rewriteImageUri("123456789012.dkr.ecr.cn-north-1.amazonaws.com.cn/backend-user:1");
assertEquals("123456789012.dkr.ecr.cn-north-1.localhost:4566/backend-user:1", rewritten);
}
@Test
void rewriteImageUri_matchesAwsEcrUri_rewritesToLocalRegistryAndStartsIt() {
when(lifecycleManager.createAndStart(any())).thenReturn(
@@ -2,6 +2,7 @@ package io.github.hectorvent.floci.services.resourceexplorer2;
import io.github.hectorvent.floci.core.common.AwsArnUtils;
import io.github.hectorvent.floci.core.common.AwsArnUtils.Arn;
import io.github.hectorvent.floci.core.common.AwsPartitions;
import io.github.hectorvent.floci.core.common.AwsRegions;
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
import io.quarkus.test.junit.QuarkusTest;
@@ -1507,8 +1508,13 @@ class ResourceExplorer2IntegrationTest {
String arn = (String) resource.get("Arn");
String service = (String) resource.get("Service");
Arn parsed = AwsArnUtils.parse(arn);
assertEquals(AwsRegions.partitionFor(parsed.region()), parsed.partition(),
"ARN partition must be the one its region belongs to, got: " + arn);
// A regionless ARN (an S3 bucket) is in the partition of the region the resource
// lives in, which the listing reports; a global one ("global") says nothing.
String region = parsed.region().isEmpty() ? (String) resource.get("Region") : parsed.region();
if (AwsPartitions.isPublishedRegion(region)) {
assertEquals(AwsRegions.partitionFor(region), parsed.partition(),
"ARN partition must be the one its region belongs to, got: " + arn);
}
assertTrue(arn.contains(service),
"ARN should contain service '" + service + "', got: " + arn);
}
@@ -131,7 +131,7 @@ class S3PartitionBucketPolicyIamEnforcementIntegrationTest {
.formParam("Action", action)
.header("Authorization", "AWS4-HMAC-SHA256 Credential=" + ACCOUNT
+ "/20260629/us-east-1/iam/aws4_request, SignedHeaders=host, Signature=abc");
for (int i = 0; i < params.length; i += 2) {
for (int i = 0; i + 1 < params.length; i += 2) {
request = request.formParam(params[i], params[i + 1]);
}
return request.when().post("/").then().statusCode(200).extract();
@@ -67,6 +67,12 @@ class S3VirtualHostFilterTest {
"my-bucket.s3.amazonaws.com:443, localhost, my-bucket",
"my-bucket.s3.us-east-1.amazonaws.com, localhost, my-bucket",
"my-bucket.s3.eu-west-1.amazonaws.com:443, localhost, my-bucket",
// The same in every other partition: the longest published suffix wins, so .cn survives
"my-bucket.s3.cn-north-1.amazonaws.com.cn, localhost, my-bucket",
"my-bucket.s3.amazonaws.com.cn, localhost, my-bucket",
"my-bucket.s3.us-gov-west-1.amazonaws.com, localhost, my-bucket",
"my-bucket.s3.us-iso-east-1.c2s.ic.gov, localhost, my-bucket",
"my-bucket.s3.eusc-de-east-1.amazonaws.eu, localhost, my-bucket",
// LocalStack-compatible domains (*.localhost.localstack.cloud resolves to 127.0.0.1 via public DNS)
"my-bucket.s3.localhost.localstack.cloud, localhost, my-bucket",
"my-bucket.s3.localhost.localstack.cloud:4566, localhost, my-bucket",