diff --git a/compatibility-tests/sdk-test-awscli/test/payment-cryptography-multi-region.bats b/compatibility-tests/sdk-test-awscli/test/payment-cryptography-multi-region.bats index a3512dd7aa..7c0125cc71 100644 --- a/compatibility-tests/sdk-test-awscli/test/payment-cryptography-multi-region.bats +++ b/compatibility-tests/sdk-test-awscli/test/payment-cryptography-multi-region.bats @@ -57,13 +57,20 @@ aws_cmd_in() { # The attributes of the key the tests create. KEY_ATTRIBUTES='KeyAlgorithm=AES_256,KeyClass=SYMMETRIC_KEY,KeyUsage=TR31_D0_SYMMETRIC_DATA_ENCRYPTION_KEY,KeyModesOfUse={Encrypt=true,Decrypt=true}' -# The key that leaves the service, replicated to the regions named. -create_replicated_key() { +# The command that creates a key replicated to the region named. +create_replicated_key_command() { + local region="$1" + shift aws_cmd payment-cryptography create-key \ --key-attributes "$KEY_ATTRIBUTES" \ --exportable \ - --replication-regions "$1" \ - --query 'Key.KeyArn' --output text + --replication-regions "$region" \ + "$@" +} + +# The key that leaves the service, replicated to the regions named. +create_replicated_key() { + create_replicated_key_command "$1" --query 'Key.KeyArn' --output text } @test "Payment Cryptography multi-region: the default replication regions are read and set" { @@ -151,10 +158,7 @@ create_replicated_key() { @test "Payment Cryptography multi-region: a region of another partition is refused" { # A key is replicated within the partition it is in, as the reference says, so a # region of another partition is refused. - run aws_cmd payment-cryptography create-key \ - --key-attributes "$KEY_ATTRIBUTES" \ - --exportable \ - --replication-regions cn-north-1 + run create_replicated_key_command cn-north-1 assert_failure [[ "$output" == *"cn-north-1"* ]] } @@ -162,10 +166,7 @@ create_replicated_key() { @test "Payment Cryptography multi-region: the region of the request is not a region to replicate to" { # The key is in the region of the request already, so naming that region is a request # that cannot be carried out. - run aws_cmd payment-cryptography create-key \ - --key-attributes "$KEY_ATTRIBUTES" \ - --exportable \ - --replication-regions us-east-1 + run create_replicated_key_command us-east-1 assert_failure [[ "$output" == *"us-east-1"* ]] } diff --git a/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/PaymentCryptographyTest.java b/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/PaymentCryptographyTest.java index d5b1e3764b..d239485d28 100644 --- a/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/PaymentCryptographyTest.java +++ b/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/PaymentCryptographyTest.java @@ -313,16 +313,27 @@ class PaymentCryptographyTest { return createKey(algorithm, KeyUsage.TR31_D0_SYMMETRIC_DATA_ENCRYPTION_KEY); } - /** A key of the given algorithm and usage, for a variant that binds a purpose. */ - private static Key createKey(KeyAlgorithm algorithm, KeyUsage usage) { - Key key = client.createKey(r -> r + /** + * The request that creates a key of the given algorithm and usage. + * + * @param algorithm the key's algorithm + * @param usage the key's usage + * @param exportable whether the key may leave the service + */ + private static Consumer keyRequest(KeyAlgorithm algorithm, KeyUsage usage, + boolean exportable) { + return r -> r .keyAttributes(a -> a .keyAlgorithm(algorithm) .keyClass(KeyClass.SYMMETRIC_KEY) .keyUsage(usage) .keyModesOfUse(m -> m.encrypt(true).decrypt(true))) - .exportable(true)) - .key(); + .exportable(exportable); + } + + /** A key of the given algorithm and usage, for a variant that binds a purpose. */ + private static Key createKey(KeyAlgorithm algorithm, KeyUsage usage) { + Key key = client.createKey(keyRequest(algorithm, usage, true)).key(); keyArns.add(key.keyArn()); return key; } @@ -336,14 +347,11 @@ class PaymentCryptographyTest { */ private static Consumer replicatedKeyRequest(boolean exportable, String... regions) { - return r -> r - .keyAttributes(a -> a - .keyAlgorithm(KeyAlgorithm.AES_256) - .keyClass(KeyClass.SYMMETRIC_KEY) - .keyUsage(KeyUsage.TR31_D0_SYMMETRIC_DATA_ENCRYPTION_KEY) - .keyModesOfUse(m -> m.encrypt(true).decrypt(true))) - .exportable(exportable) - .replicationRegions(regions); + return r -> { + keyRequest(KeyAlgorithm.AES_256, KeyUsage.TR31_D0_SYMMETRIC_DATA_ENCRYPTION_KEY, exportable) + .accept(r); + r.replicationRegions(regions); + }; } /** diff --git a/src/test/java/io/floci/aws/services/paymentcryptography/PaymentCryptographyIntegrationTest.java b/src/test/java/io/floci/aws/services/paymentcryptography/PaymentCryptographyIntegrationTest.java index fd7f31b110..f274a99f81 100644 --- a/src/test/java/io/floci/aws/services/paymentcryptography/PaymentCryptographyIntegrationTest.java +++ b/src/test/java/io/floci/aws/services/paymentcryptography/PaymentCryptographyIntegrationTest.java @@ -59,11 +59,13 @@ class PaymentCryptographyIntegrationTest { .when().post("/"); } - private static final String CREATE_KEY = """ + private static final String CREATE_KEY_BODY = """ {"KeyAttributes":{"KeyAlgorithm":"AES_256","KeyClass":"SYMMETRIC_KEY", "KeyUsage":"TR31_D0_SYMMETRIC_DATA_ENCRYPTION_KEY", "KeyModesOfUse":{"Encrypt":true,"Decrypt":true}}, - "Exportable":true}"""; + "Exportable":true%s}"""; + + private static final String CREATE_KEY = CREATE_KEY_BODY.formatted(""); private static final String CREATE_WRAPPING_KEY = """ {"KeyAttributes":{"KeyAlgorithm":"AES_256","KeyClass":"SYMMETRIC_KEY", @@ -380,11 +382,7 @@ class PaymentCryptographyIntegrationTest { * @param regions the member that names the regions, as the request spells it */ private static String createReplicatedKeyBody(String regions) { - return """ - {"KeyAttributes":{"KeyAlgorithm":"AES_256","KeyClass":"SYMMETRIC_KEY", - "KeyUsage":"TR31_D0_SYMMETRIC_DATA_ENCRYPTION_KEY", - "KeyModesOfUse":{"Encrypt":true,"Decrypt":true}}, - "Exportable":true,"ReplicationRegions":%s}""".formatted(regions); + return CREATE_KEY_BODY.formatted(",\"ReplicationRegions\":" + regions); } /** The ARN of a key the request may name. */