Skip to content

fix(sqs): store and return message attributes (#461) - #465

Merged
scttfrdmn merged 1 commit into
mainfrom
feat/461-sqs-message-attributes
Aug 2, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
feat/461-sqs-message-attributes

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

Closes #461

The defect

#454 parsed message attributes in order to measure them against MaximumMessageSize, and then dropped them on the floor:

  • SQSMessage.MessageAttributes existed in sqs_types.go and was never populated at any of the four message-construction sites.
  • receiveMessage had no attribute handling at all — no selector parsing, no response fields.

A consumer routing on an attribute — a messageType discriminator, a trace ID, a tenant key — saw every message fall to its default branch, with no error to explain why. The attribute was simply not there, which reads as "the producer didn't set it" rather than "the emulator dropped it."

What now works

SendMessage, SendMessageBatch and ReceiveMessage all carry attributes, under both the query and JSON protocols.

Attributes are returned only for the names a receive asks for. This is the trap in the permissive direction: a consumer whose production caller never sets MessageAttributeNames would pass against an emulator that volunteered them, then read none from real SQS. All documented selector forms work:

MessageAttributeName Returned
omitted nothing
All / .* every attribute
messageType that attribute, if present
trace.* every attribute named trace.…

A named attribute the message doesn't carry is absent rather than an error — the selector says what to return, not that it must exist.

MD5OfMessageAttributes

Implemented from the developer guide's "Calculating the MD5 message digest for message attributes": sort by name, then per attribute a 4-byte big-endian length + UTF-8 name, the same for the data type, one transport byte (1 String/Number, 2 Binary), then the value's length and bytes.

Pinned against three real-AWS digests, captured in moto's suite from recorded live responses. This is what makes #461's "verified against a known-good digest" acceptance criterion satisfiable with no network access — the vectors ship in the test file with their provenance, and they are not interchangeable:

Vector Digest What it pins
1 36655e7e9d7c0e8479fa3f3f42247ae7 minimal single-attribute case
2 b12289320bb6e494b18b645ef562b4a9 a custom data-type suffix is hashed in full — fails if Number.java.lang.Long is truncated to Number
3 049075255ebc53fb95f7f9f3cedf3c50 a binary value is hashed raw, not base64 — the base64 form of the same input digests to 5ff413c9dc7bd18abea88ca05643f902

Vector 3 is the same raw-versus-encoded distinction #454 drew for size measurement, except this time there's a hash to settle it rather than an argument from the docs. Base64 is what travels on the wire, so hashing it is the natural mistake.

Three further behaviours, each with its own test:

  • Omitted entirely for a message with no attributes, rather than reported as the MD5 of zero bytes (d41d8cd9…). A digest of nothing is a value a caller could compare against and "successfully" verify — worse than no value.
  • On a receive, the digest covers what is returned, not what was sent. A request naming a subset gets that subset's digest, because the digest exists to let a caller checksum the attributes in hand; replaying the send-time value would fail that check for a request that legitimately succeeded.
  • A deduplicated FIFO send reports its own request's digest, not the stored original's — same reasoning.

Attributes are emitted in name order. Real SQS promises no order, but a Go map iterates randomly, so map order would make two identical requests produce different responses — the one property this emulator exists to provide.

Mutation-tested

All six mutants compiled (go vet gate) and were caught:

Mutation Caught by
Hash binary as base64 vector 3
Return attributes unconditionally ReturnedOnlyWhenRequested/omitted_returns_none + subset-digest test
Drop the digest's sort vector 2, DigestIsOrderIndependent, subset-digest test
Replay send-time digest on receive ReceiveDigestCoversTheReturnedSubset
Strip the custom data-type suffix vector 2
Key binary off BinaryValue presence instead of DataType BinaryIsIdentifiedByDataType

The last one initially survived — my first attempt at that test asserted an inequality that held for the wrong reason. It's now pinned to a digest derived from the published algorithm (6f8879e6be14e9d1c45ef3e9631b86c9; the value-keyed variant yields e275a101bd238d68e457c2f49e1ad0e7), and the mutant fails. Noting it because the test's value is entirely in that distinction: an empty-valued Binary attribute is the only input where the two rules diverge, and real SQS rejects it outright, so there's no captured digest to compare against.

Tests

emulator/sqs_messageattributes_test.go — 10 tests, all bothProtocols where protocol-independent: the three known-good vectors, order-independence, omission with no attributes, full round-trip of String/Number/custom-Number/Binary (binary byte-identical after base64), the eight selection outcomes, receive-time subset digest, batch round-trip with per-entry digests, survival across redelivery, the Binary-by-data-type case, and a 10-attribute message accepted as the boundary.

Verification

From the repo root: gofmt -l . clean, go build ./..., go vet ./..., golangci-lint run ./... → 0 issues, make test (race) green, make docs-reference-check docs-versions green, test/e2e green.

Docs

docs/services.md gains §"Message attributes" with the selector table, the digest algorithm and both load-bearing details, the omission rule, the receive-subset rule, and the ordering note. The stale "substrate does not yet store them or return them from ReceiveMessage" line in §"Message size enforcement" is replaced with a pointer. The three SQS operation rows link to the new section.

Recorded as not enforced (follow-ups): the documented 10-attribute maximum, and the attribute-name character rules (no AWS./Amazon. prefix, no leading/trailing/sequential periods). Both are newly reachable now that attributes are stored.

#454 parsed message attributes in order to measure them against
`MaximumMessageSize` and then discarded them: `SQSMessage.MessageAttributes`
existed and was never populated, and `receiveMessage` had no attribute handling
at all. A consumer routing on an attribute -- a `messageType` discriminator, a
trace ID, a tenant key -- saw every message fall to its default branch, with no
error to explain why, because the attribute was simply not there.

`SendMessage`, `SendMessageBatch` and `ReceiveMessage` now carry them under both
the query and JSON protocols. Attributes are returned only for the names a
receive asks for: `All` and `.*` for everything, a bare name for one, and the
documented `prefix.*` form. Returning them unconditionally would fail in the
permissive direction -- a consumer whose production caller never sets
`MessageAttributeNames` would pass against substrate and read nothing from real
SQS.

`MD5OfMessageAttributes` is computed with the algorithm published in the
developer guide and pinned against three real-AWS digests, each failing on a
different mistake: the minimal single-attribute case, a custom data-type suffix
hashed in full (`Number.java.lang.Long`, not its `Number` base), and a binary
value hashed raw rather than base64 -- base64 yields
5ff413c9dc7bd18abea88ca05643f902 where AWS yields 049075255ebc53fb95f7f9f3cedf3c50.
That makes #461's known-good-digest criterion satisfiable with no network
access.

The field is omitted entirely for a message with no attributes rather than
reported as the MD5 of zero bytes, which a caller could compare against and
"successfully" verify. On a receive the digest covers what is returned, not what
was sent, so a named subset gets that subset's digest. A deduplicated FIFO send
reports its own request's digest rather than the stored original's. Attributes
are emitted in name order, since a Go map iterates randomly and two identical
requests must not produce different responses.

The 10-attribute maximum and the attribute-name character rules remain
unenforced and are tracked separately; a 10-attribute message is accepted and
pinned as the boundary.

Closes #461
@codecov

codecov Bot commented Aug 2, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.89119% with 6 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
emulator/sqs_plugin.go 94.87% 5 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

@scttfrdmn
scttfrdmn merged commit fec5756 into main Aug 2, 2026
16 checks passed
@scttfrdmn
scttfrdmn deleted the feat/461-sqs-message-attributes branch August 2, 2026 22:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SQS: message attributes are measured but not stored or returned

1 participant