Repository navigation
fix(sns): a topic operation checks that its topic exists, and DeleteTopic stops checking (#926, #992) - #994
Merged
Merged
Conversation
…opic stops checking (#926, #992) Subscribe, Publish, PublishBatch and ListSubscriptionsByTopic parsed the TopicArn, derived a state key from it, and then read only the subscription index — so an absent topic was indistinguishable from a real topic with no subscribers and all four answered 200. Every one of the four pages publishes NotFound at 404. Subscribe was the worst of them because it writes: a subscription record and two index entries survived the call. All six operations that resolve a TopicArn to a topic record now go through one helper, on the #961/#969 precedent that a per-handler existence check drifts. The load is keyed by the ARN's own account and Region, so the check cannot reintroduce what #925 fixed, and it runs after the parse so a malformed ARN is still InvalidParameter/400. PublishBatch answers at the top level rather than per entry, argued from the page's own structure. Unsubscribe answers NotFound/404 where it answered 200 behind an unsourced "idempotent" comment. DeleteTopic is the inverse and is fixed in the same pass, so every SNS topic operation's existence behaviour matches its own page: API_DeleteTopic's description states the action is idempotent, and substrate answered NotFound/404. The same page also publishes NotFound in its error list; the description sentence governs, and the contradiction is recorded rather than silently resolved. Closes #926. Closes #992.
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.
Four SNS operations never checked that the topic they addressed exists, and a fifth checked where AWS documents that it must not. The two are one audit run in both directions, so they ship together: after this change every SNS topic operation's existence behaviour matches its own reference page.
#926 — four operations that answered 200 for a topic that does not exist
Subscribe,Publish,PublishBatchandListSubscriptionsByTopicparsed theTopicArn, derived a state key from it, and then read only the subscription index. An absent topic was therefore indistinguishable from a real topic with no subscribers, and all four answered200:PublishandPublishBatchminted aMessageIdfor a message no topic had accepted,Subscribehanded back a subscription ARN, andListSubscriptionsByTopicreported an empty list. Each of the four pages publishesNotFoundat 404, glossed "Indicates that the requested resource does not exist."The consequence went beyond the code name. A
CreateTopic→Publish→DeleteTopic→Publishsequence — a producer's teardown, or a test asserting that one surfaces an error once its topic is gone — could not be written at all, because the secondPublishsucceeded. An empty subscription list and an absent topic are now different answers rather than the same one, which is asserted in both directions.Subscribewas the worst of the four because it is the one that writes: a subscription record and two index entries survived the refused call, reported byListSubscriptionsever after, and would have started receiving messages had a topic of that name later been created. That is the assertion that failed hardest before the fix.One helper, six call sites
All six operations that resolve a
TopicArnto a topic record — the four above plusGetTopicAttributesandSetTopicAttributes, which already checked — go through the new(*SNSPlugin).requireTopic. That is the #961/#969 precedent: each of those issues found one operation refusing nothing its siblings refused, which is what a per-handler existence check invites.TestSNSExistence_OneHelperAnswersForEverySiteasserts the code, the status and the message text are identical across the six, so a seventh operation added later that hand-rolls its own check shows up as a difference.The load is keyed by the ARN's own account and Region, never the caller's, so the check cannot reintroduce the resolution defect #925 fixed.
snsParseTopicARNtakes no*RequestContext, so a cross-account or cross-Region ARN builds a state key nothing is stored at and the topic reads as absent — the Region half is independently required byAPI_Publish("you can publish messages only to topics and endpoints in the same AWS Region"), and the account half needs no guard of its own.TestSNSExistence_TheCheckIsKeyedByTheARNsAccountAndRegioncreates one topic namedsharedin us-west-2 only and asserts, for each of the six, that its own ARN is served while a same-named us-east-1 ARN and a same-named ARN in another account are both refused.The check runs after the parse, so a string that is not an ARN still answers
InvalidParameter/400 rather than being reported as a topic that does not exist — asserted for four malformed forms across all six operations.PublishBatchanswers at the top level#926 explicitly declined to guess this one.
API_PublishBatchhas two failure shapes — a top-level error, and a per-entryBatchResultErrorEntryinside a200— and the page does not say which applies to an absent topic. It is the top level:TopicArnis a request-level parameter, so every entry addresses the same topic and a per-entry rendering would report the identical failure on each of them while still answering 200;NotFoundappears in the operation's top-levelErrorslist; and the batch-scoped codes the page publishes —BatchEntryIdsNotDistinct,InvalidBatchEntryId,ParameterValueInvalid— are each about an individual message. This reading is substrate's. The test sends a three-entry batch, so a per-entry implementation would be visible as threeFailedmembers, and asserts the body carries noSuccessful, noFailedand noMessageId.UnsubscribeAnswers
NotFound/404 for a subscription ARN naming no subscription, where substrate answered200behind an unsourced "Idempotent — silently succeed" comment.API_Unsubscribepublishes the code and states no idempotence anywhere, andSubscriptionArnis the operation's only request parameter and only named resource, so the published code can only be about the subscription. A previously discardedDeleteerror is now checked.#992 —
DeleteTopicwent the other wayAPI_DeleteTopic's description, verbatim: "Deletes a topic and all its subscriptions. … This action is idempotent, so deleting a topic that does not exist does not result in an error." Substrate answeredNotFound/404, so a teardown helper that deletes unconditionally, or a rollback that retries a delete, was broken here and correct in production — the reverse of the usual direction.The same page also publishes
NotFound/404 in itsErrorslist, alongsideConcurrentAccess,InvalidState,StaleTagandTagPolicy, so it contradicts itself. The description sentence governs: it names the condition, names the outcome and calls the property by name, while the error-list entry names no condition at all. Recording the contradiction rather than silently resolving it is the house rule; the resolution is corroborated byAPI_Unsubscribepublishing the same code with no such sentence — AWS states idempotence where it means it. A malformed ARN still answersInvalidParameter/400: idempotence licenses a topic that does not exist, not a string that is not an ARN. Two errors the handler previously discarded on the delete path are now checked, and a test asserts the idempotent path leaves the owning Region's topic index alone rather than rewriting it to itself.Deliberately out of scope
The subscription record and the two subscription indexes stay keyed by the calling account rather than the topic's, as
docs/services.mdalready explains: a cross-account subscription is not modeled at all, so moving them would put the index under an account the subscriptions are not stored in andPublishwould silently stop delivering.GetTopicAttributes' attribute set is wrong in a way this PR does not touch — it reports an inventedSubscriptionsCounthardcoded to"0"and none of AWS's three subscription counts — filed as #993 rather than folded in.Provenance
NotFound/404 entry and its gloss onAPI_Subscribe,API_Publish,API_PublishBatch,API_ListSubscriptionsByTopic,API_GetTopicAttributesandAPI_SetTopicAttributes;API_Publish's same-Region requirement;API_DeleteTopic's idempotence sentence and its contradictingErrorslist;API_Unsubscribe'sNotFoundand its silence on idempotence;API_PublishBatch's top-level error list and its batch-scoped codes.PublishBatchrenders the refusal top-level rather than per entry; thatAPI_DeleteTopic's description governs over its own error list; thatNotFoundrather thanResourceNotFoundis the code for the topic operations (only the three tagging pages publish the latter, per fix(sns): a topic ARN resolves to the caller's own account, and a subscription ARN resolves to its own UUID #925).Compatibility
Subscribe,Publish,PublishBatchandListSubscriptionsByTopicagainst a topic that does not exist — including one in another account or Region — now answerNotFound/404 where they answered200;Unsubscribeof an absent subscription likewise.DeleteTopicagainst a topic that does not exist now answers200where it answered404. A test that relied on any of those old answers will need updating; none in this tree did.Verification
The nine-command gate passes:
gofmt/build/vet,golangci-lint(0 issues),make test,GOTOOLCHAIN=go1.26.6 make test,GOTOOLCHAIN=go1.26.6 make coverage(84.5% emulator / 84.0% total, up from 84.4/83.9),make docs-reference docs-reference-check docs-versions authz-reference-check,npm --prefix docs run build, and the e2e vet + suite. Every assertion in the new file goes over the wire throughemulator.StartTestServerwith the topic created byCreateTopic(#765), and each asserts the HTTP status alongside the code (#923) — the status matters more than usual here, because the defect was a status.Closes #926.
Closes #992.