fix(s3vectors): route ListVectors instead of falling through to S3 (#2285)

* fix(s3vectors): add listVectors service method with cursor pagination

ListVectors had no backing service method. Add one modeled on
listCertificates' cursor-based pagination (base64 JSON cursor over the
last returned key), sorted by vector key for stable ordering across
pages.

* fix(s3vectors): route ListVectors instead of falling through to S3

S3VectorsController declared routes for twelve S3 Vectors operations
but not ListVectors, so requests fell through to the S3 REST-XML
controller and came back as a misleading S3 InvalidArgument XML error
instead of a ListVectors response.

Add the route, request/response records (modeled on GetVectors'
returnData/returnMetadata shape), and wire it to the new
S3VectorsService.listVectors.

Fixes #2161

* test(s3vectors): add regression tests for ListVectors

Reproduces #2161: before the route existed, ListVectors fell through
to the S3 controller and returned an XML InvalidArgument error instead
of a JSON ListVectors response. Covers the basic list (with
returnData/returnMetadata) and cursor pagination via maxResults +
nextToken across two pages.

* fix(s3vectors): resolve ListVectors by indexArn and fix cursor encoding

Two issues flagged in review on #2285:

- listVectors ignored indexArn and passed it through as an unused
  request field, so an ARN-only ListVectors call (a form the input
  contract explicitly allows) resolved a null bucket name and 404'd.
  Add resolveIndex to parse "<bucketArn>/index/<indexName>" and fall
  back to it when indexName is absent.
- encodeToken/decodeToken hand-built a JSON string around the cursor
  key without escaping, so a vector key containing a double quote
  truncated the cursor and repeated or skipped pages. Drop the JSON
  wrapping entirely — the cursor only ever holds one opaque value, so
  base64-encoding the raw key round-trips any key correctly.

* fix(s3vectors): pass indexArn through to listVectors

Wire ListVectorsRequest.indexArn() into the new
S3VectorsService.listVectors(bucketName, indexName, indexArn, ...)
signature so ARN-only requests actually resolve the index instead of
being silently dropped.

* test(s3vectors): add regression tests for indexArn and quoted keys

Reproduces both issues flagged in review on #2285: confirmed
listVectorsByIndexArnOnly failed with 404 and
listVectorsPaginationRoundTripsKeysWithQuotes returned the wrong page
against the prior code, before the resolveIndex and cursor-encoding
fixes.

* fix(s3vectors): resolve indexArn using its own region, not the request's

Flagged in review on #2285: resolveIndex parsed the bucket/index names
out of indexArn with manual substring slicing but discarded the ARN's
region entirely, doing the lookup in whatever region the ListVectors
request itself was signed for. A valid cross-region indexArn (or any
request not signed for the same region as the index) silently 404'd or
could resolve a same-named index in the wrong region.

Use AwsArnUtils.parse instead of manual slicing, validate the ARN is
an s3vectors ARN, and look up the index in the region encoded in the
ARN itself.

* test(s3vectors): add regression test for cross-region indexArn lookup

Reproduces the issue flagged in review on #2285: confirmed this test
failed with 404 against the prior region-ignoring resolveIndex, using
an index created under a us-west-2 credential scope and a ListVectors
request with no Authorization header (default region).
This commit is contained in:
Feyikemi Ogunsanya authored and GitHub committed 2026-08-15 19:09:13 -04:00
1 parent 78ad357eb8
commit 6c4d63b0a9
3 files changed
+435 -2

No files matched your search

@@ -248,6 +248,75 @@ class S3VectorsIntegrationTest {
@Test
@Order(11)
void listVectors() {
// Reproduces #2161: ListVectors previously had no route and fell through to the S3
// REST-XML controller, returning an S3 <Error>InvalidArgument</Error> instead of a
// ListVectors response.
given()
.contentType(JSON_CONTENT_TYPE)
.body("""
{
"vectorBucketName": "%s",
"indexName": "%s",
"returnData": true,
"returnMetadata": true
}
""".formatted(BUCKET_NAME, INDEX_NAME))
.when()
.post("/ListVectors")
.then()
.contentType(JSON_CONTENT_TYPE)
.statusCode(200)
.body("vectors", hasSize(2))
.body("vectors.find { it.key == 'v1' }.data.float32", contains(1.0f, 0.0f, 0.0f))
.body("vectors.find { it.key == 'v1' }.metadata.label", equalTo("first"))
.body("vectors.find { it.key == 'v2' }.metadata.label", equalTo("second"))
.body("nextToken", nullValue());
}
@Test
@Order(12)
void listVectorsPaginatesWithMaxResultsAndNextToken() {
String firstPageNextToken =
given()
.contentType(JSON_CONTENT_TYPE)
.body("""
{
"vectorBucketName": "%s",
"indexName": "%s",
"maxResults": 1
}
""".formatted(BUCKET_NAME, INDEX_NAME))
.when()
.post("/ListVectors")
.then()
.statusCode(200)
.body("vectors", hasSize(1))
.body("vectors[0].key", equalTo("v1"))
.body("nextToken", notNullValue())
.extract().path("nextToken");
given()
.contentType(JSON_CONTENT_TYPE)
.body("""
{
"vectorBucketName": "%s",
"indexName": "%s",
"maxResults": 1,
"nextToken": "%s"
}
""".formatted(BUCKET_NAME, INDEX_NAME, firstPageNextToken))
.when()
.post("/ListVectors")
.then()
.statusCode(200)
.body("vectors", hasSize(1))
.body("vectors[0].key", equalTo("v2"))
.body("nextToken", nullValue());
}
@Test
@Order(13)
void deleteVectors() {
given()
.contentType(JSON_CONTENT_TYPE)
@@ -282,7 +351,7 @@ class S3VectorsIntegrationTest {
}
@Test
@Order(12)
@Order(14)
void deleteIndex() {
given()
.contentType(JSON_CONTENT_TYPE)
@@ -313,7 +382,7 @@ class S3VectorsIntegrationTest {
}
@Test
@Order(13)
@Order(15)
void deleteVectorBucket() {
given()
.contentType(JSON_CONTENT_TYPE)
@@ -340,4 +409,229 @@ class S3VectorsIntegrationTest {
.then()
.statusCode(404);
}
// Self-contained: each test below creates its own bucket/index so it doesn't depend on the
// ordered setup/teardown sequence above.
@Test
@Order(16)
void listVectorsByIndexArnOnly() {
String bucketName = "arn-list-vectors-bucket";
String indexName = "arn-idx";
given()
.contentType(JSON_CONTENT_TYPE)
.body("""
{ "vectorBucketName": "%s" }
""".formatted(bucketName))
.when()
.post("/CreateVectorBucket")
.then()
.statusCode(200);
String indexArn =
given()
.contentType(JSON_CONTENT_TYPE)
.body("""
{
"vectorBucketName": "%s",
"indexName": "%s",
"dimension": 2,
"distanceMetric": "cosine",
"dataType": "float32"
}
""".formatted(bucketName, indexName))
.when()
.post("/CreateIndex")
.then()
.statusCode(200)
.extract().path("indexArn");
given()
.contentType(JSON_CONTENT_TYPE)
.body("""
{
"vectorBucketName": "%s",
"indexName": "%s",
"vectors": [{"key": "only", "data": {"float32": [1.0, 0.0]}}]
}
""".formatted(bucketName, indexName))
.when()
.post("/PutVectors")
.then()
.statusCode(200);
// ListVectors identified by indexArn alone (no vectorBucketName/indexName) must resolve
// to the same index rather than looking up a null bucket name.
given()
.contentType(JSON_CONTENT_TYPE)
.body("""
{ "indexArn": "%s" }
""".formatted(indexArn))
.when()
.post("/ListVectors")
.then()
.statusCode(200)
.body("vectors", hasSize(1))
.body("vectors[0].key", equalTo("only"));
}
@Test
@Order(17)
void listVectorsPaginationRoundTripsKeysWithQuotes() {
String bucketName = "quote-key-vector-bucket";
String indexName = "quote-idx";
given()
.contentType(JSON_CONTENT_TYPE)
.body("""
{ "vectorBucketName": "%s" }
""".formatted(bucketName))
.when()
.post("/CreateVectorBucket")
.then()
.statusCode(200);
given()
.contentType(JSON_CONTENT_TYPE)
.body("""
{
"vectorBucketName": "%s",
"indexName": "%s",
"dimension": 2,
"distanceMetric": "cosine",
"dataType": "float32"
}
""".formatted(bucketName, indexName))
.when()
.post("/CreateIndex")
.then()
.statusCode(200);
// One key contains a double quote — the pagination cursor must round-trip it intact
// rather than truncating at the quote.
given()
.contentType(JSON_CONTENT_TYPE)
.body("""
{
"vectorBucketName": "%s",
"indexName": "%s",
"vectors": [
{"key": "a\\"b", "data": {"float32": [1.0, 0.0]}},
{"key": "c", "data": {"float32": [0.0, 1.0]}}
]
}
""".formatted(bucketName, indexName))
.when()
.post("/PutVectors")
.then()
.statusCode(200);
String firstPageNextToken =
given()
.contentType(JSON_CONTENT_TYPE)
.body("""
{
"vectorBucketName": "%s",
"indexName": "%s",
"maxResults": 1
}
""".formatted(bucketName, indexName))
.when()
.post("/ListVectors")
.then()
.statusCode(200)
.body("vectors", hasSize(1))
.body("vectors[0].key", equalTo("a\"b"))
.body("nextToken", notNullValue())
.extract().path("nextToken");
given()
.contentType(JSON_CONTENT_TYPE)
.body("""
{
"vectorBucketName": "%s",
"indexName": "%s",
"maxResults": 1,
"nextToken": "%s"
}
""".formatted(bucketName, indexName, firstPageNextToken))
.when()
.post("/ListVectors")
.then()
.statusCode(200)
.body("vectors", hasSize(1))
.body("vectors[0].key", equalTo("c"))
.body("nextToken", nullValue());
}
@Test
@Order(18)
void listVectorsByIndexArnResolvesTheArnsOwnRegionNotTheRequestRegion() {
String bucketName = "cross-region-vector-bucket";
String indexName = "cross-region-idx";
String otherRegionAuth = "Credential=AKID/20260101/us-west-2/s3vectors/aws4_request";
// Create the bucket/index in us-west-2 (via the SigV4 credential scope region).
given()
.contentType(JSON_CONTENT_TYPE)
.header("Authorization", otherRegionAuth)
.body("""
{ "vectorBucketName": "%s" }
""".formatted(bucketName))
.when()
.post("/CreateVectorBucket")
.then()
.statusCode(200);
String indexArn =
given()
.contentType(JSON_CONTENT_TYPE)
.header("Authorization", otherRegionAuth)
.body("""
{
"vectorBucketName": "%s",
"indexName": "%s",
"dimension": 2,
"distanceMetric": "cosine",
"dataType": "float32"
}
""".formatted(bucketName, indexName))
.when()
.post("/CreateIndex")
.then()
.statusCode(200)
.body("indexArn", containsString(":us-west-2:"))
.extract().path("indexArn");
given()
.contentType(JSON_CONTENT_TYPE)
.header("Authorization", otherRegionAuth)
.body("""
{
"vectorBucketName": "%s",
"indexName": "%s",
"vectors": [{"key": "only", "data": {"float32": [1.0, 0.0]}}]
}
""".formatted(bucketName, indexName))
.when()
.post("/PutVectors")
.then()
.statusCode(200);
// No Authorization header here, so this request resolves to the default region — not
// us-west-2. The lookup must still succeed because it honors the region encoded in the
// ARN itself, not the region the ListVectors request happens to be signed for.
given()
.contentType(JSON_CONTENT_TYPE)
.body("""
{ "indexArn": "%s" }
""".formatted(indexArn))
.when()
.post("/ListVectors")
.then()
.statusCode(200)
.body("vectors", hasSize(1))
.body("vectors[0].key", equalTo("only"));
}
}