Repository navigation
fix(#993): GetTopicAttributes derives the four attributes AWS publishes, and stops inventing one - #1068
Merged
Conversation
…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 Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
GetTopicAttributesreported aSubscriptionsCountmember that appears nowhere onAPI_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.Ownerwas 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 ifCreateTopicorSetTopicAttributesstored them.SubscriptionsPendingis0as a fact rather than a placeholder: there is noConfirmSubscriptionanywhere in the tree, andSubscribehands back a real subscription ARN rather than the"pending confirmation"stringAPI_Subscribedocuments for one awaiting it.SubscriptionsDeletedis omitted rather than reported as0. A monotonic counter inUnsubscribewould 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, soGetTopicAttributesandListSubscriptionsByTopicread the same entries under the same key and cannot disagree about the same topic — the test asserts both at every step of twoSubscribecalls and anUnsubscribe. Keying the count by the ARN's target instead would have made them disagree by construction:0from the count while the list returned the subscriptions.A finding the issue missed, and it reversed two lines
setTopicAttributeswrites anyAttributeNameinto the topic's stored map unchecked, and the handler merged that map after its own literals. So a caller could setTopicArnand haveGetTopicAttributesreport it — and once the counts became derived could have setSubscriptionsConfirmedto 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 amap[string]stringcannot 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-lintclean,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, theSignatureVersionabsence rule and the three-entry sample response are quoted fromAPI_GetTopicAttributes. OmittingSubscriptionsDeletedand keying the count by the caller are both substrate's readings, and both are recorded as such indocs/services.md.Closes #993.