Skip to content

fix(#993): GetTopicAttributes derives the four attributes AWS publishes, and stops inventing one - #1068

Merged
scttfrdmn merged 1 commit into
mainfrom
feat/993-sns-topic-attributes
Sep 18, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
feat/993-sns-topic-attributes

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

GetTopicAttributes reported a SubscriptionsCount member that appears nowhere on API_GetTopicAttributes — not in the attribute list, not in the sample response, not in any SDK's shape — hardcoded to "0", and reported none of the three subscription counts the page does publish. A caller reading the attribute AWS documents got nothing back; a caller reading the invented one got a constant no writer ever touched. Owner was missing too, where AWS's own three-entry sample carries it.

What the answer looks like now

Four attributes are derived on every read — TopicArn, Owner, SubscriptionsConfirmed, SubscriptionsPending — and the remaining twelve published names are reported only if CreateTopic or SetTopicAttributes stored them.

SubscriptionsPending is 0 as a fact rather than a placeholder: there is no ConfirmSubscription anywhere in the tree, and Subscribe hands back a real subscription ARN rather than the "pending confirmation" string API_Subscribe documents for one awaiting it.

SubscriptionsDeleted is omitted rather than reported as 0. A monotonic counter in Unsubscribe would have been three lines, but the page publishes only "The number of deleted subscriptions for the topic" and says nothing about how long a deleted subscription stays counted — so a never-decaying counter would have been an invention in the same shape as the member this PR removes.

The keying decision, and why it is assertable

The topic record is keyed by the ARN's own account and Region (the rule #925 made structural) while all seven per-topic subscription index sites are keyed by the caller's, which Subscribe's own comment records deliberately. The count follows the index, so GetTopicAttributes and ListSubscriptionsByTopic read the same entries under the same key and cannot disagree about the same topic — the test asserts both at every step of two Subscribe calls and an Unsubscribe. Keying the count by the ARN's target instead would have made them disagree by construction: 0 from the count while the list returned the subscriptions.

A finding the issue missed, and it reversed two lines

setTopicAttributes writes any AttributeName into the topic's stored map unchecked, and the handler merged that map after its own literals. So a caller could set TopicArn and have GetTopicAttributes report it — and once the counts became derived could have set SubscriptionsConfirmed to any value it liked. The derived members are now written last and a test pins the order. Refusing the write is the fix at the right layer, filed as #1067.

Verification

Four tests over the wire through StartTestServer, reading the raw XML entry keys as an ordered slice. Not because a map[string]string cannot tell an absent key from one carrying "0" — it can, and the constant survived because no test read the attribute at all — but because a map cannot see a duplicated <entry>, which is the failure mode the new merge order could have introduced.

gofmt/go vet/golangci-lint clean, go test -race ./... green on both toolchains, coverage 85.4% emulator / 84.9% total, docs build and e2e green.

Provenance

The sixteen published attribute names, the three subscription-count glosses, Owner, Policy, the SignatureVersion absence rule and the three-entry sample response are quoted from API_GetTopicAttributes. Omitting SubscriptionsDeleted and keying the count by the caller are both substrate's readings, and both are recorded as such in docs/services.md.

Closes #993.

…es, and stops inventing one

SubscriptionsCount appears nowhere on API_GetTopicAttributes — not in the attribute
list, not in the sample response, not in any SDK's shape — and substrate reported it
hardcoded to "0" while reporting none of the three subscription counts the page does
publish. So a caller reading the attribute AWS documents got nothing back and a caller
reading the invented one got a constant no writer ever touched. Owner was missing too,
where AWS's own three-entry sample carries it.

Four attributes are now derived on every read and the remaining twelve published names
are reported only if something stored them. SubscriptionsPending is 0 as a fact rather
than a placeholder: there is no ConfirmSubscription anywhere in the tree, and Subscribe
hands back a real subscription ARN rather than the "pending confirmation" string
API_Subscribe documents, so every subscription this emulator mints is confirmed the
moment Subscribe returns.

SubscriptionsDeleted is omitted rather than reported as 0, which is substrate's reading.
Nothing tracks a deletion — Unsubscribe deletes the record and filters both indexes —
and a monotonic counter would have been three lines, but the page says only "The number
of deleted subscriptions for the topic" and nothing about how long a deleted
subscription stays counted. A never-decaying counter would have been an invention in the
same shape as the SubscriptionsCount this removes. Omitting the member claims nothing.

The count is keyed by the caller's account and Region. That is the one decision here and
the property that decided it is assertable: all seven per-topic index sites are keyed by
the caller while the topic record is keyed by the ARN's own account and Region, so
following the index means GetTopicAttributes and ListSubscriptionsByTopic read the same
entries under the same key and cannot disagree about the same topic. The test asserts
both at every step of two Subscribes and an Unsubscribe. Keying by the ARN's target
would have made them disagree by construction.

The merge order is reversed so a stored attribute cannot shadow a derived one.
setTopicAttributes writes any AttributeName unchecked and the stored map was merged
after the handler's literals, so a caller could set TopicArn and have it reported — and
once the counts became derived could have set SubscriptionsConfirmed to any value it
liked. Filed as #1067; until that refuses the write, this ordering is what stands
between a caller and a fabricated subscription count.

Assertions read the raw XML entry keys as an ordered slice. Not because a map cannot
tell an absent key from one carrying "0" — it can, and the constant survived because no
test read the attribute at all — but because a map cannot see a duplicated <entry>,
which is the failure mode the new merge order could have introduced.

Coverage 85.4% emulator / 84.9% total.

Closes #993.
@codecov

codecov Bot commented Sep 18, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 88.88889% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
emulator/sns_plugin.go 87.50% 1 Missing ⚠️
emulator/sns_topic_attributes.go 90.00% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@scttfrdmn
scttfrdmn merged commit 3cef4c8 into main Sep 18, 2026
17 checks passed
@scttfrdmn
scttfrdmn deleted the feat/993-sns-topic-attributes branch September 18, 2026 19:35
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.

sns: GetTopicAttributes reports an invented SubscriptionsCount hardcoded to 0, and none of the three subscription counts AWS publishes

1 participant