From 61d2a923739dbd4377f77c554edf3ae258b329a7 Mon Sep 17 00:00:00 2001 From: Jackson Price <59149601+jprice8@users.noreply.github.com> Date: Tue, 3 Nov 2026 12:32:38 -0600 Subject: [PATCH] test(kms): isolate one-key pagination from shared account state (#7427) --- .../DynamoDbLocalBackendIntegrationTest.java | 12 +++---- .../ElbV2SubnetDependencyIntegrationTest.java | 4 +-- .../services/kms/KmsIntegrationTest.java | 33 +++++++++---------- .../floci/testing/TestAccounts.java | 14 ++++++++ 4 files changed, 36 insertions(+), 27 deletions(-) create mode 100644 src/test/java/io/github/hectorvent/floci/testing/TestAccounts.java diff --git a/src/test/java/io/github/hectorvent/floci/services/dynamodb/backend/DynamoDbLocalBackendIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/dynamodb/backend/DynamoDbLocalBackendIntegrationTest.java index 01d2d2c812..0a0f61d70f 100644 --- a/src/test/java/io/github/hectorvent/floci/services/dynamodb/backend/DynamoDbLocalBackendIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/dynamodb/backend/DynamoDbLocalBackendIntegrationTest.java @@ -10,6 +10,7 @@ import io.github.hectorvent.floci.services.dynamodb.backend.DynamoDbStreamReader import io.github.hectorvent.floci.services.dynamodb.backend.DynamoDbStreamReader.Shard; import io.github.hectorvent.floci.services.dynamodb.backend.DynamoDbStreamReader.Stream; import io.github.hectorvent.floci.testing.RestAssuredJsonUtils; +import io.github.hectorvent.floci.testing.TestAccounts; import io.quarkus.test.junit.QuarkusTest; import io.quarkus.test.junit.QuarkusTestProfile; import io.quarkus.test.junit.TestProfile; @@ -27,7 +28,6 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.UUID; -import java.util.concurrent.ThreadLocalRandom; import static io.restassured.RestAssured.given; import static org.awaitility.Awaitility.await; @@ -72,7 +72,7 @@ class DynamoDbLocalBackendIntegrationTest { private record CreatedTable(Caller caller, String name) {} private static final String CONTENT_TYPE = "application/x-amz-json-1.0"; - private static final String ACCOUNT_A = randomAccount(); + private static final String ACCOUNT_A = TestAccounts.randomId(); private static final String ACCOUNT_B = otherAccountThan(ACCOUNT_A); private static final Caller A_EAST = new Caller(ACCOUNT_A, "us-east-1"); private static final Caller A_WEST = new Caller(ACCOUNT_A, "eu-west-1"); @@ -374,14 +374,10 @@ class DynamoDbLocalBackendIntegrationTest { return "local-it-" + purpose + "-" + UUID.randomUUID(); } - private static String randomAccount() { - return Long.toString(ThreadLocalRandom.current().nextLong(100_000_000_000L, 1_000_000_000_000L)); - } - private static String otherAccountThan(String account) { - String other = randomAccount(); + String other = TestAccounts.randomId(); while (other.equals(account)) { - other = randomAccount(); + other = TestAccounts.randomId(); } return other; } diff --git a/src/test/java/io/github/hectorvent/floci/services/elbv2/ElbV2SubnetDependencyIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/elbv2/ElbV2SubnetDependencyIntegrationTest.java index a629d998b3..8ea0944870 100644 --- a/src/test/java/io/github/hectorvent/floci/services/elbv2/ElbV2SubnetDependencyIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/elbv2/ElbV2SubnetDependencyIntegrationTest.java @@ -2,6 +2,7 @@ package io.github.hectorvent.floci.services.elbv2; import io.github.hectorvent.floci.services.ec2.Ec2Service; import io.github.hectorvent.floci.services.ec2.model.Subnet; +import io.github.hectorvent.floci.testing.TestAccounts; import io.quarkus.test.junit.QuarkusTest; import io.quarkus.test.junit.mockito.InjectSpy; import io.restassured.response.ValidatableResponse; @@ -17,7 +18,6 @@ import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.Future; -import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; import java.util.concurrent.atomic.AtomicBoolean; @@ -107,7 +107,7 @@ class ElbV2SubnetDependencyIntegrationTest { */ @Test void referencesInAnotherAccountDoNotPinTheSameDefaultSubnetId() { - String otherAccount = Long.toString(ThreadLocalRandom.current().nextLong(100_000_000_000L, 1_000_000_000_000L)); + String otherAccount = TestAccounts.randomId(); String first = Ec2Service.defaultSubnetId(REGION, "a"); String second = Ec2Service.defaultSubnetId(REGION, "b"); String arn = loadBalancer("application", first, second); diff --git a/src/test/java/io/github/hectorvent/floci/services/kms/KmsIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/kms/KmsIntegrationTest.java index b6f16cbf85..6046882adf 100644 --- a/src/test/java/io/github/hectorvent/floci/services/kms/KmsIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/kms/KmsIntegrationTest.java @@ -1,6 +1,7 @@ package io.github.hectorvent.floci.services.kms; import io.github.hectorvent.floci.testing.RestAssuredJsonUtils; +import io.github.hectorvent.floci.testing.TestAccounts; import io.quarkus.test.junit.QuarkusTest; import io.restassured.path.json.JsonPath; import io.restassured.response.Response; @@ -870,37 +871,35 @@ class KmsIntegrationTest { @Test void listKeysPagesWithLimitAndMarker() { + String account = TestAccounts.randomId(); + String authorization = "AWS4-HMAC-SHA256 Credential=" + account + + "/20261103/us-east-1/kms/aws4_request"; + JsonPath initial = kmsAs(authorization, "ListKeys", "{}") + .then().statusCode(200) + .extract().jsonPath(); + List expectedKeyIds = new ArrayList<>(initial.getList("Keys.KeyId")); for (int i = 0; i < 2; i++) { - given() - .header("X-Amz-Target", "TrentService.CreateKey") - .contentType(KMS_CONTENT_TYPE) - .body("{}") - .when().post("/") - .then().statusCode(200); + String keyId = kmsAs(authorization, "CreateKey", "{}") + .then().statusCode(200) + .extract().path("KeyMetadata.KeyId"); + expectedKeyIds.add(keyId); } - JsonPath unpaged = given() - .header("X-Amz-Target", "TrentService.ListKeys") - .contentType(KMS_CONTENT_TYPE) - .body("{}") - .when().post("/") + JsonPath unpaged = kmsAs(authorization, "ListKeys", "{}") .then() .statusCode(200) .body("Truncated", equalTo(false)) .body("$", not(hasKey("NextMarker"))) .extract().jsonPath(); List allKeyIds = unpaged.getList("Keys.KeyId"); - assertTrue(allKeyIds.size() >= 2); + assertEquals(new HashSet<>(expectedKeyIds), new HashSet<>(allKeyIds)); + assertEquals(expectedKeyIds.size(), allKeyIds.size()); List pagedKeyIds = new ArrayList<>(); String marker = null; do { String body = marker == null ? "{\"Limit\":1}" : "{\"Limit\":1,\"Marker\":\"" + marker + "\"}"; - JsonPath page = given() - .header("X-Amz-Target", "TrentService.ListKeys") - .contentType(KMS_CONTENT_TYPE) - .body(body) - .when().post("/") + JsonPath page = kmsAs(authorization, "ListKeys", body) .then() .statusCode(200) .body("Keys.size()", equalTo(1)) diff --git a/src/test/java/io/github/hectorvent/floci/testing/TestAccounts.java b/src/test/java/io/github/hectorvent/floci/testing/TestAccounts.java new file mode 100644 index 0000000000..73c0e9a79a --- /dev/null +++ b/src/test/java/io/github/hectorvent/floci/testing/TestAccounts.java @@ -0,0 +1,14 @@ +package io.github.hectorvent.floci.testing; + +import java.util.concurrent.ThreadLocalRandom; + +/** Random account IDs for tests with isolated account state. */ +public final class TestAccounts { + + private TestAccounts() { + } + + public static String randomId() { + return Long.toString(ThreadLocalRandom.current().nextLong(100_000_000_000L, 1_000_000_000_000L)); + } +}