Repository navigation
fix(testkit): stripe listen forwards the webhook endpoint's events and reads the new secret format - #35
Merged
Conversation
…d reads the new secret format The Stripe test kit's `stripe listen` integration broke in two ways, and hid both: - Stripe CLI 1.51.0+ exits at startup when `listen --forward-to` has no event subscription. The kit now passes `--events` with the event types the webhook endpoint subscribes to. `--events` exists in every CLI version (verified on 1.21.0 and 1.55.12); `--all-snapshot` does not. - Stripe changed the CLI signing-secret format from 64 lowercase hex characters to 32 alphanumeric ones. The extraction pattern `whsec_[a-f0-9]+` truncated it (e.g. to `whsec_e`), so every forwarded webhook failed signature verification (HTTP 400). The kit now takes the whole token (`whsec_\S+`) and runs the CLI with `--color off`. - beforeAll no longer carries on silently: it aborts the suite when no secret is printed within 30s, when it looks truncated, or when it was not installed for the webhook route. The secret is masked in the logs. One shared list (`StripeApi.webhookEnabledEvents`) now drives the webhook endpoint's create and update parameters and the test listener's `--events`; a unit test pins it to the previously hard-coded events. Version 0.9.12. Closes #34 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #35 +/- ##
==========================================
- Coverage 41.07% 40.82% -0.25%
==========================================
Files 155 155
Lines 10898 10924 +26
Branches 1748 1826 +78
==========================================
- Hits 4476 4460 -16
- Misses 6422 6464 +42
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
Closes #34.
Why
StripePaymentRouteTestKitstartsstripe listenso that webhook-driven specs receive Stripe events. That has broken in two independent ways, and the kit hid both:listen --forward-tohas no event subscription:must specify events to forward using --events, --all-snapshot, or --all-thin.--events '*'is rejected too.whsec_[a-f0-9]+truncated it (for example towhsec_e), so every forwarded webhook failed signature verification with HTTP 400 (No signatures found matching the expected signature for payload).In both cases
beforeAllcarried on: it ignored the result of the 30-second wait and logged "secret saved" whatever it had captured. Webhook-driven tests then failed later with misleading timeouts and assertion errors. Details are in #34.What changes
stripe listen --color off --events <list> --forward-to <url>, passed as an argument list.--eventsexists in every CLI version;--all-snapshotonly from 1.51.0.--color offstops a forced-colour environment from wrapping the secret in ANSI codes.Secret extraction takes the whole token,
whsec_\S+, instead of guessing its character set.beforeAllfails loudly with anIllegalStateExceptionnaming the cause when:overrideWebHookSecretaccepts onlysk_test_keys).The CLI process is stopped on failure, and
afterAllis null-safe.The signing secret is masked (
whsec_***) in the test logs.One shared list:
StripeApi.webhookEnabledEventsnow drives the webhook endpoint's create and update parameters and the test listener's--events. A new unit test inStripeApiSpecpins both enum lists to the 9 previously hard-coded events, in the same order. The endpoint's behaviour is unchanged.Version 0.9.12. No new members on the
StripePaymentRouteTestKittrait, so classes compiled against 0.9.11 stay binary-compatible.Release notes
StripePaymentRouteTestKitnow aborts inbeforeAllwhen the Stripe CLI secret cannot be installed. Before, it continued without webhooks.Verification
sbt '+ Test/compile'(Scala 2.12 and 2.13) andscalafmtSbtCheck scalafmtCheck Test/scalafmtCheckboth pass.StripeApiSpec"same events" passes.--events, sign forwarded events with the printed secret (raw HMAC check: 2 of 2 deliveries each).--color off --events <the 9 events>. They print the banner with no ANSI codes even withCLICOLOR_FORCE=1, and the new pattern captures the full 38-character secret.38 chars), and 8 forwarded webhooks all got200, none4xx.stripe listenpath is therefore exercised only by consumers.🤖 Generated with Claude Code