mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
test(partition): smoke-test ARN minting across partitions and gate new minting services (#5282)
* test(partition): smoke-test ARN minting across partitions and gate new minting services Partition behaviour was proven in the emulator for a few services only. PartitionCrossServiceSmokeIntegrationTest creates one resource in each of the seven non-commercial partitions for SNS, Kinesis, Firehose, API Gateway V2, ELBv2, Glue, IoT, ACM, CodeBuild, Batch and EFS and asserts the ARN or host carries the request's partition, skipping only where the vendored data says the partition does not offer the service. PartitionSmokeInventoryTest scans the service packages that mint ARNs or AWS hosts and fails unless each is covered by the smoke test or listed with a reason in src/test/resources/partition/smoke-exemptions.tsv, so a new minting service cannot arrive without a partition check. The file starts with 92 rows: 10 covered by an existing partition test, 82 not yet covered. AGENTS.md adds the step to the new-service checklist. * test(partition): count direct Arn construction as minting and pin the HTTP API host The inventory scan did not match new AwsArnUtils.Arn(...), so ssoadmin, which mints its instance ARNs that way, was neither covered nor exempted. The scan now matches the constructor, and ssoadmin is exempt with its reason: one Identity Center instance per account, minted in its primary region's partition, so a request signed in another partition sees that ARN (BL-243). AGENTS.md names the constructor too. The HTTP API case checked only the DNS suffix, so an endpoint minted with another region of the same partition passed. It now asserts the whole <apiId>.execute-api.<region>.<suffix> host.
This commit is contained in:
1 parent
a3027c07cf
commit
2c2ac5dbfa
4 files changed
+498
-3
No files matched your search
+269
@@ -0,0 +1,269 @@
|
||||
package io.github.hectorvent.floci.core.common;
|
||||
|
||||
import io.github.hectorvent.floci.testing.PartitionCleanup;
|
||||
import io.github.hectorvent.floci.testing.PartitionMatrix;
|
||||
import io.github.hectorvent.floci.testing.PartitionMatrix.PartitionCase;
|
||||
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.response.Response;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assumptions.assumeTrue;
|
||||
|
||||
/**
|
||||
* One resource per service, created by a request signed in each non-commercial partition, must
|
||||
* come back with an ARN (or a host) of that partition and region. The literal gate only catches
|
||||
* {@code arn:aws:} written in source; this catches a service that mints through the shared
|
||||
* helpers with the wrong region source. A service is skipped only in a partition the published
|
||||
* data says does not offer it.
|
||||
*
|
||||
* <p>{@link #COVERED_PACKAGES} names the service packages this class covers;
|
||||
* {@code PartitionSmokeInventoryTest} requires every package that mints ARNs or hosts to be here
|
||||
* or in {@code partition/smoke-exemptions.tsv}.
|
||||
*/
|
||||
@QuarkusTest
|
||||
class PartitionCrossServiceSmokeIntegrationTest {
|
||||
|
||||
static final Set<String> COVERED_PACKAGES = Set.of(
|
||||
"acm", "apigatewayv2", "batch", "codebuild", "efs", "elbv2", "firehose", "glue", "iot",
|
||||
"kinesis", "sns");
|
||||
|
||||
private static final String JSON_1_1 = "application/x-amz-json-1.1";
|
||||
private static final String JSON = "application/json";
|
||||
|
||||
@RegisterExtension
|
||||
final PartitionCleanup cleanup = new PartitionCleanup();
|
||||
|
||||
@BeforeAll
|
||||
static void configureRestAssured() {
|
||||
RestAssuredJsonUtils.configureAwsContentTypes();
|
||||
}
|
||||
|
||||
static Stream<PartitionCase> nonCommercialCases() {
|
||||
return PartitionMatrix.cases().filter(c -> !"aws".equals(c.partition()));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("nonCommercialCases")
|
||||
void snsTopicArn(PartitionCase partitionCase) {
|
||||
String region = offered(partitionCase, "sns");
|
||||
String name = unique("smoke-topic", partitionCase);
|
||||
String arn = signed(region, "sns")
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.formParam("Action", "CreateTopic")
|
||||
.formParam("Name", name)
|
||||
.when().post("/").then().statusCode(200)
|
||||
.extract().xmlPath().getString("CreateTopicResponse.CreateTopicResult.TopicArn");
|
||||
cleanup.register(() -> signed(region, "sns")
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.formParam("Action", "DeleteTopic")
|
||||
.formParam("TopicArn", arn)
|
||||
.when().post("/"));
|
||||
PartitionMatrix.assertArnIn(partitionCase, arn);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("nonCommercialCases")
|
||||
void kinesisStreamArn(PartitionCase partitionCase) {
|
||||
String region = offered(partitionCase, "kinesis");
|
||||
String name = unique("smoke-stream", partitionCase);
|
||||
json11(region, "kinesis", "Kinesis_20131202.CreateStream",
|
||||
"{\"StreamName\":\"" + name + "\",\"ShardCount\":1}")
|
||||
.when().post("/").then().statusCode(200);
|
||||
cleanup.register(() -> json11(region, "kinesis", "Kinesis_20131202.DeleteStream",
|
||||
"{\"StreamName\":\"" + name + "\"}").when().post("/"));
|
||||
String arn = json11(region, "kinesis", "Kinesis_20131202.DescribeStreamSummary",
|
||||
"{\"StreamName\":\"" + name + "\"}")
|
||||
.when().post("/").then().statusCode(200)
|
||||
.extract().jsonPath().getString("StreamDescriptionSummary.StreamARN");
|
||||
PartitionMatrix.assertArnIn(partitionCase, arn);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("nonCommercialCases")
|
||||
void firehoseDeliveryStreamArn(PartitionCase partitionCase) {
|
||||
String region = offered(partitionCase, "firehose");
|
||||
String name = unique("smoke-firehose", partitionCase);
|
||||
String arn = json11(region, "firehose", "Firehose_20150804.CreateDeliveryStream",
|
||||
"{\"DeliveryStreamName\":\"" + name + "\"}")
|
||||
.when().post("/").then().statusCode(200)
|
||||
.extract().jsonPath().getString("DeliveryStreamARN");
|
||||
cleanup.register(() -> json11(region, "firehose", "Firehose_20150804.DeleteDeliveryStream",
|
||||
"{\"DeliveryStreamName\":\"" + name + "\"}").when().post("/"));
|
||||
PartitionMatrix.assertArnIn(partitionCase, arn);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("nonCommercialCases")
|
||||
void httpApiEndpointHost(PartitionCase partitionCase) {
|
||||
String region = offered(partitionCase, "apigateway");
|
||||
String name = unique("smoke-http-api", partitionCase);
|
||||
Response created = signed(region, "apigateway")
|
||||
.contentType(JSON)
|
||||
.body("{\"name\":\"" + name + "\",\"protocolType\":\"HTTP\"}")
|
||||
.when().post("/v2/apis").then().statusCode(201).extract().response();
|
||||
String apiId = created.jsonPath().getString("apiId");
|
||||
cleanup.register(() -> signed(region, "apigateway").when().delete("/v2/apis/" + apiId));
|
||||
String host = URI.create(created.jsonPath().getString("apiEndpoint")).getHost();
|
||||
PartitionMatrix.assertHostIn(partitionCase, host);
|
||||
assertEquals(apiId + ".execute-api." + region + "." + partitionCase.dnsSuffix(), host);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("nonCommercialCases")
|
||||
void elbv2TargetGroupArn(PartitionCase partitionCase) {
|
||||
String region = offered(partitionCase, "elasticloadbalancing");
|
||||
String name = unique("smoke-tg", partitionCase);
|
||||
String arn = signed(region, "elasticloadbalancing")
|
||||
.formParam("Action", "CreateTargetGroup")
|
||||
.formParam("Version", "2015-12-01")
|
||||
.formParam("Name", name)
|
||||
.formParam("Protocol", "HTTP")
|
||||
.formParam("Port", "80")
|
||||
.formParam("VpcId", "vpc-00000001")
|
||||
.formParam("TargetType", "ip")
|
||||
.when().post("/").then().statusCode(200)
|
||||
.extract().xmlPath()
|
||||
.getString("CreateTargetGroupResponse.CreateTargetGroupResult.TargetGroups.member.TargetGroupArn");
|
||||
cleanup.register(() -> signed(region, "elasticloadbalancing")
|
||||
.formParam("Action", "DeleteTargetGroup")
|
||||
.formParam("Version", "2015-12-01")
|
||||
.formParam("TargetGroupArn", arn)
|
||||
.when().post("/"));
|
||||
PartitionMatrix.assertArnIn(partitionCase, arn);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("nonCommercialCases")
|
||||
void glueSchemaRegistryArn(PartitionCase partitionCase) {
|
||||
String region = offered(partitionCase, "glue");
|
||||
String name = unique("smoke-registry", partitionCase);
|
||||
String arn = json11(region, "glue", "AWSGlue.CreateRegistry", "{\"RegistryName\":\"" + name + "\"}")
|
||||
.when().post("/").then().statusCode(200)
|
||||
.extract().jsonPath().getString("RegistryArn");
|
||||
cleanup.register(() -> json11(region, "glue", "AWSGlue.DeleteRegistry",
|
||||
"{\"RegistryId\":{\"RegistryName\":\"" + name + "\"}}").when().post("/"));
|
||||
PartitionMatrix.assertArnIn(partitionCase, arn);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("nonCommercialCases")
|
||||
void iotThingArn(PartitionCase partitionCase) {
|
||||
String region = offered(partitionCase, "iot");
|
||||
String name = unique("smoke-thing", partitionCase);
|
||||
String arn = signed(region, "iot")
|
||||
.contentType(JSON)
|
||||
.body("{}")
|
||||
.when().post("/things/" + name).then().statusCode(200)
|
||||
.extract().jsonPath().getString("thingArn");
|
||||
cleanup.register(() -> signed(region, "iot").when().delete("/things/" + name));
|
||||
PartitionMatrix.assertArnIn(partitionCase, arn);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("nonCommercialCases")
|
||||
void acmCertificateArn(PartitionCase partitionCase) {
|
||||
String region = offered(partitionCase, "acm");
|
||||
String domain = unique("smoke-cert", partitionCase) + ".example.com";
|
||||
String arn = json11(region, "acm", "CertificateManager.RequestCertificate",
|
||||
"{\"DomainName\":\"" + domain + "\"}")
|
||||
.when().post("/").then().statusCode(200)
|
||||
.extract().jsonPath().getString("CertificateArn");
|
||||
cleanup.register(() -> json11(region, "acm", "CertificateManager.DeleteCertificate",
|
||||
"{\"CertificateArn\":\"" + arn + "\"}").when().post("/"));
|
||||
PartitionMatrix.assertArnIn(partitionCase, arn);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("nonCommercialCases")
|
||||
void codeBuildProjectArn(PartitionCase partitionCase) {
|
||||
String region = offered(partitionCase, "codebuild");
|
||||
String name = unique("smoke-project", partitionCase);
|
||||
String body = """
|
||||
{
|
||||
"name": "%s",
|
||||
"source": {"type": "S3", "location": "smoke-bucket/source.zip"},
|
||||
"artifacts": {"type": "NO_ARTIFACTS"},
|
||||
"environment": {"type": "LINUX_CONTAINER", "image": "aws/codebuild/standard:7.0",
|
||||
"computeType": "BUILD_GENERAL1_SMALL"},
|
||||
"serviceRole": "arn:%s:iam::000000000000:role/codebuild-role"
|
||||
}
|
||||
""".formatted(name, partitionCase.partition());
|
||||
String arn = json11(region, "codebuild", "CodeBuild_20161006.CreateProject", body)
|
||||
.when().post("/").then().statusCode(200)
|
||||
.extract().jsonPath().getString("project.arn");
|
||||
cleanup.register(() -> json11(region, "codebuild", "CodeBuild_20161006.DeleteProject",
|
||||
"{\"name\":\"" + name + "\"}").when().post("/"));
|
||||
PartitionMatrix.assertArnIn(partitionCase, arn);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("nonCommercialCases")
|
||||
void batchComputeEnvironmentArn(PartitionCase partitionCase) {
|
||||
String region = offered(partitionCase, "batch");
|
||||
String name = unique("smoke-ce", partitionCase);
|
||||
String arn = signed(region, "batch")
|
||||
.contentType(JSON)
|
||||
.body("{\"computeEnvironmentName\":\"" + name + "\",\"type\":\"MANAGED\","
|
||||
+ "\"computeResources\":{\"type\":\"FARGATE\",\"maxvCpus\":4}}")
|
||||
.when().post("/v1/createcomputeenvironment").then().statusCode(200)
|
||||
.extract().jsonPath().getString("computeEnvironmentArn");
|
||||
cleanup.register(() -> {
|
||||
signed(region, "batch")
|
||||
.contentType(JSON)
|
||||
.body("{\"computeEnvironment\":\"" + name + "\",\"state\":\"DISABLED\"}")
|
||||
.when().post("/v1/updatecomputeenvironment");
|
||||
signed(region, "batch")
|
||||
.contentType(JSON)
|
||||
.body("{\"computeEnvironment\":\"" + name + "\"}")
|
||||
.when().post("/v1/deletecomputeenvironment");
|
||||
});
|
||||
PartitionMatrix.assertArnIn(partitionCase, arn);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("nonCommercialCases")
|
||||
void efsFileSystemArn(PartitionCase partitionCase) {
|
||||
String region = offered(partitionCase, "elasticfilesystem");
|
||||
Response created = signed(region, "elasticfilesystem")
|
||||
.contentType(JSON)
|
||||
.body("{\"CreationToken\":\"" + unique("smoke-efs", partitionCase) + "\"}")
|
||||
.when().post("/2015-02-01/file-systems").then().statusCode(201).extract().response();
|
||||
String fileSystemId = created.jsonPath().getString("FileSystemId");
|
||||
cleanup.register(() -> signed(region, "elasticfilesystem")
|
||||
.when().delete("/2015-02-01/file-systems/" + fileSystemId));
|
||||
PartitionMatrix.assertArnIn(partitionCase, created.jsonPath().getString("FileSystemArn"));
|
||||
}
|
||||
|
||||
/** The case's region, or the test is skipped where the partition does not publish the service. */
|
||||
private static String offered(PartitionCase partitionCase, String signingName) {
|
||||
assumeTrue(AwsPartitions.byId(partitionCase.partition()).offersSigningName(signingName),
|
||||
partitionCase.partition() + " does not offer " + signingName);
|
||||
return partitionCase.region();
|
||||
}
|
||||
|
||||
private static String unique(String prefix, PartitionCase partitionCase) {
|
||||
return prefix + "-" + partitionCase.partition() + "-" + Long.toString(System.nanoTime(), 36);
|
||||
}
|
||||
|
||||
private static RequestSpecification signed(String region, String signingName) {
|
||||
return given().header("Authorization", PartitionMatrix.sigV4Auth(region, signingName));
|
||||
}
|
||||
|
||||
private static RequestSpecification json11(String region, String signingName, String target, String body) {
|
||||
return signed(region, signingName)
|
||||
.header("X-Amz-Target", target)
|
||||
.contentType(JSON_1_1)
|
||||
.body(body);
|
||||
}
|
||||
}
|
||||
+125
@@ -0,0 +1,125 @@
|
||||
package io.github.hectorvent.floci.core.common;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.UncheckedIOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.TreeMap;
|
||||
import java.util.TreeSet;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
/**
|
||||
* Every service package that mints ARNs or AWS hosts is either exercised in each non-commercial
|
||||
* partition by {@link PartitionCrossServiceSmokeIntegrationTest} or listed, with a reason, in
|
||||
* {@code partition/smoke-exemptions.tsv}. A new service that mints through the shared helpers
|
||||
* therefore has to make that choice visibly: the literal gate cannot see a wrong region source,
|
||||
* only a test signed in another partition can.
|
||||
*/
|
||||
class PartitionSmokeInventoryTest {
|
||||
|
||||
private static final Path SERVICES = Path.of("src/main/java/io/github/hectorvent/floci/services");
|
||||
private static final Path EXEMPTIONS = Path.of("src/test/resources/partition/smoke-exemptions.tsv");
|
||||
private static final Pattern MINTS = Pattern.compile(
|
||||
"buildArn\\(|buildGlobalArn\\(|\\bArn\\.of\\(|\\bArn\\.global\\(|\\bnew (AwsArnUtils\\.)?Arn\\("
|
||||
+ "|dnsSuffixFor\\(|AwsEndpoints\\.\\w+\\(");
|
||||
|
||||
@Test
|
||||
void everyMintingPackageIsCoveredOrExempted() {
|
||||
Set<String> missing = new TreeSet<>(mintingPackages());
|
||||
missing.removeAll(PartitionCrossServiceSmokeIntegrationTest.COVERED_PACKAGES);
|
||||
missing.removeAll(readExemptions().keySet());
|
||||
|
||||
assertTrue(missing.isEmpty(), "Service packages that mint ARNs or hosts with no partition smoke case: "
|
||||
+ missing + ". Add a case to PartitionCrossServiceSmokeIntegrationTest and its COVERED_PACKAGES, "
|
||||
+ "or a row with a reason to " + EXEMPTIONS + ".");
|
||||
}
|
||||
|
||||
@Test
|
||||
void exemptionsAreNotStale() {
|
||||
Set<String> minting = mintingPackages();
|
||||
Set<String> stale = new TreeSet<>();
|
||||
for (String exempted : readExemptions().keySet()) {
|
||||
if (!minting.contains(exempted)
|
||||
|| PartitionCrossServiceSmokeIntegrationTest.COVERED_PACKAGES.contains(exempted)) {
|
||||
stale.add(exempted);
|
||||
}
|
||||
}
|
||||
|
||||
assertTrue(stale.isEmpty(), "Rows in " + EXEMPTIONS + " whose package no longer mints ARNs or hosts, "
|
||||
+ "or is now covered by the smoke test: " + stale + ". Remove them.");
|
||||
}
|
||||
|
||||
@Test
|
||||
void exemptionFileIsSortedAndFreeOfDuplicates() {
|
||||
List<String> packages = exemptionLines().stream().map(line -> line.split("\t", 2)[0]).toList();
|
||||
|
||||
assertEquals(packages.stream().distinct().toList(), packages, "Duplicate rows in " + EXEMPTIONS);
|
||||
assertEquals(packages.stream().sorted().toList(), packages, "Keep " + EXEMPTIONS + " sorted by package.");
|
||||
}
|
||||
|
||||
@Test
|
||||
void coveredPackagesExist() {
|
||||
Set<String> unknown = new TreeSet<>(PartitionCrossServiceSmokeIntegrationTest.COVERED_PACKAGES);
|
||||
unknown.removeAll(mintingPackages());
|
||||
|
||||
assertTrue(unknown.isEmpty(), "COVERED_PACKAGES names packages that do not mint ARNs or hosts: " + unknown);
|
||||
}
|
||||
|
||||
private static Set<String> mintingPackages() {
|
||||
Set<String> packages = new TreeSet<>();
|
||||
try (Stream<Path> dirs = Files.list(SERVICES)) {
|
||||
for (Path dir : dirs.filter(Files::isDirectory).toList()) {
|
||||
if (mints(dir)) {
|
||||
packages.add(dir.getFileName().toString());
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new UncheckedIOException(e);
|
||||
}
|
||||
assertTrue(packages.size() > 50, "the source scan found almost no minting packages; is "
|
||||
+ SERVICES + " the right path?");
|
||||
return packages;
|
||||
}
|
||||
|
||||
private static boolean mints(Path dir) throws IOException {
|
||||
try (Stream<Path> files = Files.walk(dir)) {
|
||||
for (Path file : files.filter(f -> f.toString().endsWith(".java")).toList()) {
|
||||
if (MINTS.matcher(Files.readString(file, StandardCharsets.UTF_8)).find()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static Map<String, String> readExemptions() {
|
||||
Map<String, String> exemptions = new TreeMap<>();
|
||||
for (String line : exemptionLines()) {
|
||||
String[] columns = line.split("\t", 2);
|
||||
assertEquals(2, columns.length, "expected package<TAB>reason in " + EXEMPTIONS + ": " + line);
|
||||
assertTrue(!columns[1].isBlank(), "an exemption needs a reason: " + line);
|
||||
exemptions.put(columns[0], columns[1]);
|
||||
}
|
||||
return exemptions;
|
||||
}
|
||||
|
||||
private static List<String> exemptionLines() {
|
||||
try {
|
||||
return Files.readAllLines(EXEMPTIONS, StandardCharsets.UTF_8).stream()
|
||||
.filter(line -> !line.isBlank() && !line.startsWith("#"))
|
||||
.toList();
|
||||
} catch (IOException e) {
|
||||
throw new UncheckedIOException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user