mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(sqs): honor AttributeNames/MessageSystemAttributeNames on ReceiveMessage (#784)
* fix(sqs): honor AttributeNames/MessageSystemAttributeNames on ReceiveMessage ReceiveMessage previously emitted a fixed set of system attributes (ApproximateReceiveCount, SentTimestamp, plus FIFO fields when present) regardless of what the caller asked for. AWS instead returns exactly the attributes the request selects: - empty list -> no system attributes - ["SenderId"] -> only SenderId - ["All"] -> SenderId, SentTimestamp, ApproximateReceiveCount, ApproximateFirstReceiveTimestamp (and FIFO MessageGroupId, SequenceNumber, MessageDeduplicationId when applicable) Both the legacy AttributeName.N / AttributeNames parameter and the modern MessageSystemAttributeName.N / MessageSystemAttributeNames parameter are honored. SenderId derives from the account ID parsed from the queue URL (falling back to the configured default account), matching the multi-tenancy isolation introduced in #753. A new firstReceiveTimestamp field on Message backs ApproximateFirstReceiveTimestamp and is set on first claim. Refs #768. * test(sqs): cover legacy AttributeNames and Query-protocol filtering Adds Query-protocol receive-with-filter coverage and a legacy AttributeNames case to the JSON test, and clarifies the senderIdFor Javadoc to reflect actual fallback order (queue URL → request context → default).
This commit is contained in:
1 parent
e62fd09b6d
commit
ffd7779c5c
8 files changed
+258
-29
No files matched your search
@@ -111,6 +111,7 @@ class SqsFifoIntegrationTest {
|
||||
.formParam("Action", "ReceiveMessage")
|
||||
.formParam("QueueUrl", queueUrl)
|
||||
.formParam("MaxNumberOfMessages", "10")
|
||||
.formParam("AttributeName.1", "All")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
|
||||
@@ -468,4 +468,68 @@ class SqsIntegrationTest {
|
||||
.body(containsString("QueueDoesNotExist"))
|
||||
.body(not(containsString("AWS.SimpleQueueService.NonExistentQueue")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void receiveMessage_queryProtocol_attributeNameFiltersSystemAttributes() {
|
||||
String filterQueueName = "query-attr-filter-queue";
|
||||
String filterQueueUrl = given()
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.formParam("Action", "CreateQueue")
|
||||
.formParam("QueueName", filterQueueName)
|
||||
.when().post("/").then().statusCode(200)
|
||||
.extract().xmlPath().getString("CreateQueueResponse.CreateQueueResult.QueueUrl");
|
||||
|
||||
try {
|
||||
given()
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.formParam("Action", "SendMessage")
|
||||
.formParam("QueueUrl", filterQueueUrl)
|
||||
.formParam("MessageBody", "hi")
|
||||
.when().post("/").then().statusCode(200);
|
||||
|
||||
// No AttributeName.N requested: response must contain no <Attribute> entries
|
||||
given()
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.formParam("Action", "ReceiveMessage")
|
||||
.formParam("QueueUrl", filterQueueUrl)
|
||||
.formParam("MaxNumberOfMessages", "1")
|
||||
.formParam("VisibilityTimeout", "0")
|
||||
.when().post("/").then().statusCode(200)
|
||||
.body(containsString("<Message>"))
|
||||
.body(not(containsString("<Attribute>")));
|
||||
|
||||
// AttributeName.1=SenderId: only SenderId present, no SentTimestamp / ApproximateReceiveCount
|
||||
given()
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.formParam("Action", "ReceiveMessage")
|
||||
.formParam("QueueUrl", filterQueueUrl)
|
||||
.formParam("MaxNumberOfMessages", "1")
|
||||
.formParam("VisibilityTimeout", "0")
|
||||
.formParam("AttributeName.1", "SenderId")
|
||||
.when().post("/").then().statusCode(200)
|
||||
.body(containsString("<Name>SenderId</Name>"))
|
||||
.body(not(containsString("<Name>SentTimestamp</Name>")))
|
||||
.body(not(containsString("<Name>ApproximateReceiveCount</Name>")));
|
||||
|
||||
// MessageSystemAttributeName.1=All: full system-attribute set returned
|
||||
given()
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.formParam("Action", "ReceiveMessage")
|
||||
.formParam("QueueUrl", filterQueueUrl)
|
||||
.formParam("MaxNumberOfMessages", "1")
|
||||
.formParam("VisibilityTimeout", "0")
|
||||
.formParam("MessageSystemAttributeName.1", "All")
|
||||
.when().post("/").then().statusCode(200)
|
||||
.body(containsString("<Name>SenderId</Name>"))
|
||||
.body(containsString("<Name>SentTimestamp</Name>"))
|
||||
.body(containsString("<Name>ApproximateReceiveCount</Name>"))
|
||||
.body(containsString("<Name>ApproximateFirstReceiveTimestamp</Name>"));
|
||||
} finally {
|
||||
given()
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.formParam("Action", "DeleteQueue")
|
||||
.formParam("QueueUrl", filterQueueUrl)
|
||||
.when().post("/");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -204,6 +204,91 @@ class SqsJsonProtocolTest {
|
||||
.body("$", not(hasKey("Messages")));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(7)
|
||||
void receiveMessage_messageSystemAttributeNamesFiltersOutput() {
|
||||
String filterQueueName = QUEUE_NAME + "-filter";
|
||||
String filterQueueUrl = given()
|
||||
.contentType(CONTENT_TYPE)
|
||||
.header("X-Amz-Target", "AmazonSQS.CreateQueue")
|
||||
.body("{\"QueueName\":\"" + filterQueueName + "\"}")
|
||||
.when().post("/").then().statusCode(200)
|
||||
.extract().jsonPath().getString("QueueUrl");
|
||||
|
||||
given()
|
||||
.contentType(CONTENT_TYPE)
|
||||
.header("X-Amz-Target", "AmazonSQS.SendMessage")
|
||||
.body("{\"QueueUrl\":\"" + filterQueueUrl + "\",\"MessageBody\":\"hi\"}")
|
||||
.when().post("/").then().statusCode(200);
|
||||
|
||||
// Empty filter: no system attributes returned
|
||||
given()
|
||||
.contentType(CONTENT_TYPE)
|
||||
.header("X-Amz-Target", "AmazonSQS.ReceiveMessage")
|
||||
.body("{\"QueueUrl\":\"" + filterQueueUrl + "\","
|
||||
+ "\"MaxNumberOfMessages\":1,"
|
||||
+ "\"VisibilityTimeout\":0,"
|
||||
+ "\"MessageSystemAttributeNames\":[]}")
|
||||
.when().post("/").then().statusCode(200)
|
||||
.body("Messages", hasSize(1))
|
||||
.body("Messages[0]", not(hasKey("Attributes")));
|
||||
|
||||
// Only SenderId requested: returns only SenderId
|
||||
given()
|
||||
.contentType(CONTENT_TYPE)
|
||||
.header("X-Amz-Target", "AmazonSQS.ReceiveMessage")
|
||||
.body("{\"QueueUrl\":\"" + filterQueueUrl + "\","
|
||||
+ "\"MaxNumberOfMessages\":1,"
|
||||
+ "\"VisibilityTimeout\":0,"
|
||||
+ "\"MessageSystemAttributeNames\":[\"SenderId\"]}")
|
||||
.when().post("/").then().statusCode(200)
|
||||
.body("Messages[0].Attributes.SenderId", equalTo(ACCOUNT_ID))
|
||||
.body("Messages[0].Attributes", not(hasKey("SentTimestamp")))
|
||||
.body("Messages[0].Attributes", not(hasKey("ApproximateReceiveCount")));
|
||||
|
||||
// All: returns SenderId, SentTimestamp, ApproximateReceiveCount,
|
||||
// ApproximateFirstReceiveTimestamp
|
||||
given()
|
||||
.contentType(CONTENT_TYPE)
|
||||
.header("X-Amz-Target", "AmazonSQS.ReceiveMessage")
|
||||
.body("{\"QueueUrl\":\"" + filterQueueUrl + "\","
|
||||
+ "\"MaxNumberOfMessages\":1,"
|
||||
+ "\"VisibilityTimeout\":0,"
|
||||
+ "\"MessageSystemAttributeNames\":[\"All\"]}")
|
||||
.when().post("/").then().statusCode(200)
|
||||
.body("Messages[0].Attributes.SenderId", equalTo(ACCOUNT_ID))
|
||||
.body("Messages[0].Attributes.SentTimestamp", notNullValue())
|
||||
.body("Messages[0].Attributes.ApproximateReceiveCount", notNullValue())
|
||||
.body("Messages[0].Attributes.ApproximateFirstReceiveTimestamp", notNullValue());
|
||||
|
||||
// Legacy AttributeNames parameter (pre-2023 SDKs): SenderId-only filter
|
||||
given()
|
||||
.contentType(CONTENT_TYPE)
|
||||
.header("X-Amz-Target", "AmazonSQS.ReceiveMessage")
|
||||
.body("{\"QueueUrl\":\"" + filterQueueUrl + "\","
|
||||
+ "\"MaxNumberOfMessages\":1,"
|
||||
+ "\"VisibilityTimeout\":0,"
|
||||
+ "\"AttributeNames\":[\"SenderId\"]}")
|
||||
.when().post("/").then().statusCode(200)
|
||||
.body("Messages[0].Attributes.SenderId", equalTo(ACCOUNT_ID))
|
||||
.body("Messages[0].Attributes", not(hasKey("SentTimestamp")))
|
||||
.body("Messages[0].Attributes", not(hasKey("ApproximateReceiveCount")));
|
||||
|
||||
// Legacy AttributeNames=["All"]: same expansion as MessageSystemAttributeNames
|
||||
given()
|
||||
.contentType(CONTENT_TYPE)
|
||||
.header("X-Amz-Target", "AmazonSQS.ReceiveMessage")
|
||||
.body("{\"QueueUrl\":\"" + filterQueueUrl + "\","
|
||||
+ "\"MaxNumberOfMessages\":1,"
|
||||
+ "\"VisibilityTimeout\":0,"
|
||||
+ "\"AttributeNames\":[\"All\"]}")
|
||||
.when().post("/").then().statusCode(200)
|
||||
.body("Messages[0].Attributes.SenderId", equalTo(ACCOUNT_ID))
|
||||
.body("Messages[0].Attributes.SentTimestamp", notNullValue())
|
||||
.body("Messages[0].Attributes.ApproximateReceiveCount", notNullValue())
|
||||
.body("Messages[0].Attributes.ApproximateFirstReceiveTimestamp", notNullValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(8)
|
||||
void deleteQueueViaQueueUrlPath() {
|
||||
|
||||
Reference in new issue
Block a user