Skip to content

fix(sns): clear subscription RedrivePolicy and FilterPolicy like AWS - #350

Merged
kibertoad merged 5 commits into
mainfrom
fix/sns-empty-redrive-policy
Oct 1, 2026
Merged

kibertoad merged 5 commits into
mainfrom
fix/sns-empty-redrive-policy

Conversation

@kibertoad

@kibertoad kibertoad commented Oct 1, 2026 •

Copy link
Copy Markdown
Owner

fauxqs clears subscription policies differently from real AWS. It accepts SetSubscriptionAttributes with RedrivePolicy: "", which AWS rejects with InvalidParameter. It also keeps returning FilterPolicy: "" after that value is set, while AWS drops the attribute. This PR makes both follow AWS.

Evidence

  • The Terraform AWS provider special-cases exactly this in putSubscriptionAttribute: "The AWS API requires a non-empty string value or nil for the RedrivePolicy attribute, else throws an InvalidParameter error." Its acceptance test TestAccSNSTopicSubscription_redrivePolicy removes the policy against real AWS by sending no value.
  • The API reference marks AttributeValue as optional.
  • For FilterPolicy, LocalStack's test_filter_policy is marked aws.validated, meaning it was also run against real AWS. It sets AttributeValue: "" and waits until FilterPolicy is gone from GetSubscriptionAttributes.

This came up in message-queue-toolkit#618, where clearing with "" passed on fauxqs and would have failed on AWS.

Changes

  • validateSubscriptionRedrivePolicy no longer allows "", so it fails with the existing "unable to parse RedrivePolicy as JSON" error. This also applies to a RedrivePolicy: "" passed to Subscribe.
  • SetSubscriptionAttributes for RedrivePolicy without an AttributeValue deletes the attribute, so GetSubscriptionAttributes no longer returns it. Before, the missing value was turned into "" and stored.
  • SetSubscriptionAttributes with an empty or omitted FilterPolicy deletes the attribute instead of storing "". Delivery is unchanged, as an empty value already meant no filter.
  • Other attributes keep the current handling of a missing value.

Not covered

  • What real AWS returns from GetSubscriptionAttributes after a RedrivePolicy removal (absent or "") is not documented. Absent matches how a subscription that never had a policy looks.
  • FilterPolicy: "{}" is still stored as given. The SNS docs use it to remove a filter policy, but what GetSubscriptionAttributes returns afterwards is not documented.
  • SQS SetQueueAttributes with an empty RedrivePolicy is unchanged. That one is valid on AWS.

Summary by CodeRabbit

  • Bug Fixes
    • Omitting an attribute value now removes the subscription attribute. This applies to RedrivePolicy; setting FilterPolicy to an empty string also removes it.
    • An empty RedrivePolicy value is now rejected as invalid.

…ed value

Real AWS rejects SetSubscriptionAttributes with RedrivePolicy set to an
empty string; the policy is removed by leaving AttributeValue out.
fauxqs accepted the empty string and stored it, so code that worked
against fauxqs failed on AWS.
@coderabbitai

coderabbitai Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 39 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: abfcc26a-7134-4b2c-bb1e-6377a2ed9dab

📥 Commits

Reviewing files that changed from the base of the PR and between fd8f3ff and 2903644.

📒 Files selected for processing (8)
  • .github/workflows/publish.yml
  • README.md
  • src/persistence.ts
  • src/sns/actions/setSubscriptionAttributes.ts
  • src/sns/actions/subscribe.ts
  • src/sns/snsStore.ts
  • test/persistence/persistence.test.ts
  • test/sns/subscription-attribute-validation.test.ts

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: 75566c12-7c5a-4794-9ff8-d2278a5ab33b

📥 Commits

Reviewing files that changed from the base of the PR and between e62260e and fd8f3ff.

📒 Files selected for processing (4)
  • src/sns/actions/setSubscriptionAttributes.ts
  • src/sns/snsStore.ts
  • src/sns/subscriptionRedrivePolicy.ts
  • test/sns/subscription-attribute-validation.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

SNS subscription attribute updates now resolve omitted and empty policy values by attribute name. Undefined values remove stored attributes. Empty RedrivePolicy values are rejected.

Changes

Redrive policy updates

Layer / File(s) Summary
RedrivePolicy value handling
src/sns/actions/setSubscriptionAttributes.ts, src/sns/subscriptionRedrivePolicy.ts, test/sns/subscription-attribute-validation.test.ts
The action resolves values according to the attribute name and validates RedrivePolicy only when a value is present. Empty RedrivePolicy input fails JSON parsing.
Omitted value removes the attribute
src/sns/snsStore.ts, test/sns/subscription-attribute-validation.test.ts
The store deletes an attribute when its value is undefined. Tests cover removing RedrivePolicy by omitting AttributeValue and removing FilterPolicy with an empty value.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Merge Risk: ⚪ Minimal · up to fd8f3

This change aligns SNS subscription attribute clearing with the AWS behavior it targets. No merge-blocking risk was identified in the supplied changes.

Architecture Summary

Architecture risk: 🟡 Medium · up to fd8f3

The change affects 2 systems.

Changed systems: src, test

Architecture concerns
No architecture-level concerns identified.

Review details

Systems and components

  • observed — src (service) was modified; 3 changed files map to changed impact.
  • observed — test (service) was modified; 1 changed file maps to changed impact.

Before / after behavior

  • observed — Modified behavior in src/sns/actions/setSubscriptionAttributes.ts: The handler now resolves AttributeValue according to the attribute name instead of defaulting every omitted value to an empty string.
  • observed — Modified behavior in src/sns/actions/setSubscriptionAttributes.ts: Redrive-policy validation now runs only when the resolved value is not undefined; previously it ran for every RedrivePolicy request.
  • observed — Modified behavior in src/sns/actions/setSubscriptionAttributes.ts: Adds a local resolver that preserves omitted RedrivePolicy values as undefined, maps empty or omitted FilterPolicy values to undefined, and defaults other omitted values to "".
  • observed — Modified behavior in src/sns/snsStore.ts: setSubscriptionAttribute now accepts an optional value: undefined deletes the named attribute, while a defined string assigns it.

Reliability and maintainability

  • inferred — Risk-relevant change factors for src: blast_radius_1; direct_dependents_1
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 4 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the main change: matching AWS behavior when clearing subscription RedrivePolicy and FilterPolicy attributes.
✨ Finishing Touches 💡 2
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
🛠️ Fix failing CI checks 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Autopilot is currently an internal CodeRabbit preview.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

AWS drops FilterPolicy from GetSubscriptionAttributes after it is set
to an empty string; fauxqs kept returning "". Delivery already treated
the empty value as no filter.
@kibertoad kibertoad changed the title fix(sns): reject empty subscription RedrivePolicy, remove it on omitted value fix(sns): clear subscription RedrivePolicy and FilterPolicy like AWS Oct 1, 2026
@kibertoad kibertoad added the patch label Oct 1, 2026
…moval

Pin the parse error in the empty RedrivePolicy tests, add a Subscribe case
for the empty value, and document in the README that the subscription
policy is removed by omitting AttributeValue.
…ibuteName

- Subscribe validation and normalization moved into SnsStore.subscribe, so
  server.subscribe() and init config reject an empty or malformed
  RedrivePolicy like the Subscribe API does.
- Subscribe with FilterPolicy "" stores no policy, matching
  SetSubscriptionAttributes, so a later Subscribe without attributes is
  idempotent instead of failing with "different attributes".
- SetSubscriptionAttributes without AttributeName now fails with
  InvalidParameter, as on AWS, instead of returning success.
- Empty FilterPolicy and RedrivePolicy values persisted by earlier versions
  are dropped on load and the row is rewritten.
zizmor 1.30 adds the self-repository audit, which fails on uses: ./...
for in-repo reusable workflows. The $/ form is resolved by GitHub rather
than from the runner's checkout.
@kibertoad
kibertoad merged commit 4002c19 into main Oct 1, 2026
9 checks passed
@kibertoad
kibertoad deleted the fix/sns-empty-redrive-policy branch October 1, 2026 16:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants