fix(athena): paginate ListWorkGroups (#6519)

* fix(athena): paginate ListWorkGroups

* fix(athena): use stable workgroup pagination cursors
This commit is contained in:
Jimmy Liu Jia authored and GitHub committed 2026-10-25 13:23:36 -04:00
1 parent 57889bbb45
commit 57257e198f
3 files changed
+238 -1

No files matched your search

@@ -8,6 +8,8 @@ import org.junit.jupiter.api.Test;
import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.nullValue;
@QuarkusTest
class AthenaCreateWorkGroupIntegrationTest {
@@ -101,6 +103,210 @@ class AthenaCreateWorkGroupIntegrationTest {
.body("WorkGroups.State", contains("ENABLED", "ENABLED"));
}
@Test
void listWorkGroupsPaginatesWithNextToken() {
String authorization = "AWS4-HMAC-SHA256 Credential=test/20261025/ap-south-2/athena/aws4_request";
for (String name : new String[] {"pagination-one", "pagination-two"}) {
given()
.header("Authorization", authorization)
.header("X-Amz-Target", "AmazonAthena.CreateWorkGroup")
.contentType(CONTENT_TYPE)
.body("{\"Name\":\"" + name + "\"}")
.when()
.post("/")
.then()
.statusCode(200);
}
String token = given()
.header("Authorization", authorization)
.header("X-Amz-Target", "AmazonAthena.ListWorkGroups")
.contentType(CONTENT_TYPE)
.body("{\"MaxResults\":1}")
.when()
.post("/")
.then()
.statusCode(200)
.body("WorkGroups.Name", contains("primary"))
.body("NextToken", notNullValue())
.extract().path("NextToken");
token = given()
.header("Authorization", authorization)
.header("X-Amz-Target", "AmazonAthena.ListWorkGroups")
.contentType(CONTENT_TYPE)
.body("{\"MaxResults\":1,\"NextToken\":\"" + token + "\"}")
.when()
.post("/")
.then()
.statusCode(200)
.body("WorkGroups.Name", contains("pagination-one"))
.body("NextToken", notNullValue())
.extract().path("NextToken");
given()
.header("Authorization", authorization)
.header("X-Amz-Target", "AmazonAthena.ListWorkGroups")
.contentType(CONTENT_TYPE)
.body("{\"MaxResults\":1,\"NextToken\":\"" + token + "\"}")
.when()
.post("/")
.then()
.statusCode(200)
.body("WorkGroups.Name", contains("pagination-two"))
.body("NextToken", nullValue());
}
@Test
void listWorkGroupsDoesNotRepeatEntriesInsertedBeforeCursor() {
String authorization = "AWS4-HMAC-SHA256 Credential=test/20261025/eu-central-2/athena/aws4_request";
for (String name : new String[] {"cursor-b", "cursor-c"}) {
given()
.header("Authorization", authorization)
.header("X-Amz-Target", "AmazonAthena.CreateWorkGroup")
.contentType(CONTENT_TYPE)
.body("{\"Name\":\"" + name + "\"}")
.when()
.post("/")
.then()
.statusCode(200);
}
String token = given()
.header("Authorization", authorization)
.header("X-Amz-Target", "AmazonAthena.ListWorkGroups")
.contentType(CONTENT_TYPE)
.body("{\"MaxResults\":2}")
.when()
.post("/")
.then()
.statusCode(200)
.body("WorkGroups.Name", contains("primary", "cursor-b"))
.extract().path("NextToken");
given()
.header("Authorization", authorization)
.header("X-Amz-Target", "AmazonAthena.CreateWorkGroup")
.contentType(CONTENT_TYPE)
.body("{\"Name\":\"cursor-a\"}")
.when()
.post("/")
.then()
.statusCode(200);
given()
.header("Authorization", authorization)
.header("X-Amz-Target", "AmazonAthena.ListWorkGroups")
.contentType(CONTENT_TYPE)
.body("{\"MaxResults\":2,\"NextToken\":\"" + token + "\"}")
.when()
.post("/")
.then()
.statusCode(200)
.body("WorkGroups.Name", contains("cursor-c"))
.body("NextToken", nullValue());
}
@Test
void listWorkGroupsDoesNotSkipEntriesAfterDeletion() {
String authorization = "AWS4-HMAC-SHA256 Credential=test/20261025/sa-east-1/athena/aws4_request";
for (String name : new String[] {"deleted-a", "deleted-b"}) {
given()
.header("Authorization", authorization)
.header("X-Amz-Target", "AmazonAthena.CreateWorkGroup")
.contentType(CONTENT_TYPE)
.body("{\"Name\":\"" + name + "\"}")
.when()
.post("/")
.then()
.statusCode(200);
}
String token = given()
.header("Authorization", authorization)
.header("X-Amz-Target", "AmazonAthena.ListWorkGroups")
.contentType(CONTENT_TYPE)
.body("{\"MaxResults\":2}")
.when()
.post("/")
.then()
.statusCode(200)
.body("WorkGroups.Name", contains("primary", "deleted-a"))
.extract().path("NextToken");
given()
.header("Authorization", authorization)
.header("X-Amz-Target", "AmazonAthena.DeleteWorkGroup")
.contentType(CONTENT_TYPE)
.body("{\"WorkGroup\":\"deleted-a\"}")
.when()
.post("/")
.then()
.statusCode(200);
given()
.header("Authorization", authorization)
.header("X-Amz-Target", "AmazonAthena.ListWorkGroups")
.contentType(CONTENT_TYPE)
.body("{\"MaxResults\":2,\"NextToken\":\"" + token + "\"}")
.when()
.post("/")
.then()
.statusCode(200)
.body("WorkGroups.Name", contains("deleted-b"))
.body("NextToken", nullValue());
}
@Test
void listWorkGroupsRejectsInvalidPageSizes() {
for (String maxResults : new String[] {"0", "-1", "51", "1.5", "2147483648", "\"1\""}) {
given()
.header("X-Amz-Target", "AmazonAthena.ListWorkGroups")
.contentType(CONTENT_TYPE)
.body("{\"MaxResults\":" + maxResults + "}")
.when()
.post("/")
.then()
.statusCode(400)
.body("__type", equalTo("InvalidRequestException"));
}
}
@Test
void listWorkGroupsRejectsMalformedAndCrossRegionTokens() {
String authorization = "AWS4-HMAC-SHA256 Credential=test/20261025/eu-west-3/athena/aws4_request";
given()
.header("Authorization", authorization)
.header("X-Amz-Target", "AmazonAthena.CreateWorkGroup")
.contentType(CONTENT_TYPE)
.body("{\"Name\":\"token-source\"}")
.when().post("/").then().statusCode(200);
String token = given()
.header("Authorization", authorization)
.header("X-Amz-Target", "AmazonAthena.ListWorkGroups")
.contentType(CONTENT_TYPE)
.body("{\"MaxResults\":1}")
.when()
.post("/")
.then()
.statusCode(200)
.body("NextToken", notNullValue())
.extract().path("NextToken");
for (String invalidToken : new String[] {"", "not-a-token!", token}) {
given()
.header("Authorization", "AWS4-HMAC-SHA256 Credential=test/20261025/ap-northeast-3/athena/aws4_request")
.header("X-Amz-Target", "AmazonAthena.ListWorkGroups")
.contentType(CONTENT_TYPE)
.body("{\"MaxResults\":1,\"NextToken\":\"" + invalidToken + "\"}")
.when()
.post("/")
.then()
.statusCode(400)
.body("__type", equalTo("InvalidRequestException"));
}
}
@Test
void createWorkGroupRejectsPrimaryWorkGroup() {
given()