test(kms): isolate one-key pagination from shared account state (#7427)

This commit is contained in:
Jackson Price authored and GitHub committed 2026-11-03 14:32:38 -04:00
1 parent 0454c354f7
commit 61d2a92373
4 files changed
+36 -27

No files matched your search

@@ -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;
}
@@ -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);
@@ -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<String> 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<String> allKeyIds = unpaged.getList("Keys.KeyId");
assertTrue(allKeyIds.size() >= 2);
assertEquals(new HashSet<>(expectedKeyIds), new HashSet<>(allKeyIds));
assertEquals(expectedKeyIds.size(), allKeyIds.size());
List<String> 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))
@@ -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));
}
}