fix(paymentcryptography): accept a key ARN in every partition's regions (#7485)

CreateKey minted an ARN that the next request naming it was refused for in
GovCloud, EUSC and the ISO partitions. The vendored patterns widened the
partition the model writes but kept its region segment, which only fits a
two-letter prefix and one further part, so us-gov-west-1 and eusc-de-east-1
failed the full match.

The generator now widens the region on every pattern that carries it,
including the bare Region shape, to [a-z]{2,4}(-[a-z]{1,16})+-[0-9]+. The
pattern is slightly looser than the model, as the partition segment already
is, and still refuses a malformed ARN. Every region in partitions.json is
checked against it on both the Python and the Java side.

Signed-off-by: Hector Ventura <hectorvent@gmail.com>
This commit is contained in:
Hector Ventura authored and GitHub committed 2026-11-04 05:22:17 -04:00
1 parent 06fa276bec
commit 49f0837fd8
5 files changed
+179 -13

No files matched your search

@@ -1,10 +1,16 @@
package io.github.hectorvent.floci.services.paymentcryptography;
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 org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import java.util.List;
@@ -28,6 +34,9 @@ class PaymentCryptographyIntegrationTest {
private static final String CONTENT_TYPE = "application/x-amz-json-1.0";
private static final String TARGET = "PaymentCryptographyControlPlane.";
@RegisterExtension
final PartitionCleanup cleanup = new PartitionCleanup();
@BeforeAll
static void configureRestAssured() {
RestAssuredJsonUtils.configureAwsContentTypes();
@@ -41,6 +50,15 @@ class PaymentCryptographyIntegrationTest {
.when().post("/");
}
private static Response callIn(String region, String action, String body) {
return given()
.header("Authorization", PartitionMatrix.sigV4Auth(region, "payment-cryptography"))
.header("X-Amz-Target", TARGET + action)
.contentType(CONTENT_TYPE)
.body(body)
.when().post("/");
}
private static final String CREATE_KEY = """
{"KeyAttributes":{"KeyAlgorithm":"AES_256","KeyClass":"SYMMETRIC_KEY",
"KeyUsage":"TR31_D0_SYMMETRIC_DATA_ENCRYPTION_KEY",
@@ -441,4 +459,60 @@ class PaymentCryptographyIntegrationTest {
.then().statusCode(200)
.body("Keys", hasSize(1));
}
@ParameterizedTest
@MethodSource(PartitionMatrix.NON_COMMERCIAL_CASES)
void aKeyOutsideTheCommercialPartitionIsNamedByTheArnItWasMintedWith(PartitionCase partitionCase) {
String region = partitionCase.region();
String arn = callIn(region, "CreateKey", CREATE_KEY)
.then().statusCode(200)
.extract().path("Key.KeyArn");
cleanup.register(() -> callIn(region, "DeleteKey", "{\"KeyIdentifier\":\"" + arn + "\"}"));
PartitionMatrix.assertArnIn(partitionCase, arn);
callIn(region, "GetKey", "{\"KeyIdentifier\":\"" + arn + "\"}")
.then().statusCode(200)
.body("Key.KeyArn", equalTo(arn));
callIn(region, "TagResource", "{\"ResourceArn\":\"" + arn + "\","
+ "\"Tags\":[{\"Key\":\"Origin\",\"Value\":\"PRIMARY\"}]}")
.then().statusCode(200);
callIn(region, "ListTagsForResource", "{\"ResourceArn\":\"" + arn + "\"}")
.then().statusCode(200)
.body("Tags.Key", contains(equalTo("Origin")));
callIn(region, "CreateAlias", "{\"AliasName\":\"alias/team/partition\",\"KeyArn\":\"" + arn + "\"}")
.then().statusCode(200)
.body("Alias.KeyArn", equalTo(arn));
cleanup.register(() -> callIn(region, "DeleteAlias", "{\"AliasName\":\"alias/team/partition\"}"));
callIn(region, "GetAlias", "{\"AliasName\":\"alias/team/partition\"}")
.then().statusCode(200)
.body("Alias.KeyArn", equalTo(arn));
String aliasArn = arn.substring(0, arn.lastIndexOf(":key/")) + ":alias/team/partition";
callIn(region, "GetKey", "{\"KeyIdentifier\":\"" + aliasArn + "\"}")
.then().statusCode(200)
.body("Key.KeyArn", equalTo(arn));
}
@Test
void anArnWhoseRegionIsNotARegionIsRefusedByEveryMemberThatTakesOne() {
for (String region : List.of("us-gov", "us-gov-west-", "u-gov-west-1", "europe-de-east-1", "US-GOV-WEST-1")) {
String arn = "arn:aws-us-gov:payment-cryptography:" + region + ":000000000000:key/"
+ "0123456789abcdef0123456789abcdef";
call("GetKey", "{\"KeyIdentifier\":\"" + arn + "\"}")
.then().statusCode(400)
.body("__type", containsString("ValidationException"))
.body("message", containsString("regular expression"));
call("CreateAlias", "{\"AliasName\":\"alias/team/refused\",\"KeyArn\":\"" + arn + "\"}")
.then().statusCode(400)
.body("__type", containsString("ValidationException"))
.body("message", containsString("regular expression"));
call("ListTagsForResource", "{\"ResourceArn\":\"" + arn + "\"}")
.then().statusCode(400)
.body("__type", containsString("ValidationException"))
.body("message", containsString("regular expression"));
}
}
}
@@ -0,0 +1,46 @@
package io.github.hectorvent.floci.services.paymentcryptography;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import io.github.hectorvent.floci.core.common.AwsPartition;
import io.github.hectorvent.floci.core.common.AwsPartitions;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertFalse;
/** The members that name a key or a region, checked against the vendored constraints in every published region. */
class PaymentCryptographyRequestShapesTest {
private static final ObjectMapper MAPPER = new ObjectMapper();
private static final String KEY_ID = "0123456789abcdef0123456789abcdef";
private static ObjectNode request(String member, String value) {
return MAPPER.createObjectNode().put(member, value);
}
@Test
void everyPublishedRegionIsTaken() {
assertFalse(AwsPartitions.allRegionIds().isEmpty());
for (String region : AwsPartitions.allRegionIds()) {
AwsPartition partition = AwsPartitions.forRegion(region).orElseThrow();
String prefix = "arn:" + partition.id() + ":payment-cryptography:" + region + ":000000000000:";
String key = prefix + "key/" + KEY_ID;
assertDoesNotThrow(() -> PaymentCryptographyRequestShapes.check("GetKey", request("KeyIdentifier", key)), key);
assertDoesNotThrow(() -> PaymentCryptographyRequestShapes.check("GetKey",
request("KeyIdentifier", prefix + "alias/team/card-key")), region);
assertDoesNotThrow(() -> PaymentCryptographyRequestShapes.check("ListTagsForResource",
request("ResourceArn", key)), region);
ObjectNode create = MAPPER.createObjectNode();
create.putObject("KeyAttributes")
.put("KeyAlgorithm", "AES_256")
.put("KeyClass", "SYMMETRIC_KEY")
.put("KeyUsage", "TR31_D0_SYMMETRIC_DATA_ENCRYPTION_KEY")
.putObject("KeyModesOfUse").put("Encrypt", true);
create.put("Exportable", true);
create.putArray("ReplicationRegions").add(region);
assertDoesNotThrow(() -> PaymentCryptographyRequestShapes.check("CreateKey", create), region);
}
}
}