Skip to content

fix(testkit): stripe listen forwards the webhook endpoint's events and reads the new secret format - #35

Merged
fupelaqu merged 1 commit into
mainfrom
fix/34-testkit-stripe-listen
Nov 18, 2026
Merged

fupelaqu merged 1 commit into
mainfrom
fix/34-testkit-stripe-listen

Conversation

@fupelaqu

Copy link
Copy Markdown
Contributor

Closes #34.

⚠️ Merging publishes 0.9.12. release.yml runs sbt '+ publish' on every push to main, and this PR bumps the version to 0.9.12.

Why

StripePaymentRouteTestKit starts stripe listen so that webhook-driven specs receive Stripe events. That has broken in two independent ways, and the kit hid both:

  1. Stripe CLI ≥ 1.51.0 exits at startup when listen --forward-to has no event subscription: must specify events to forward using --events, --all-snapshot, or --all-thin. --events '*' is rejected too.
  2. 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 (for example to whsec_e), so every forwarded webhook failed signature verification with HTTP 400 (No signatures found matching the expected signature for payload).

In both cases beforeAll carried 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.

    • --events exists in every CLI version; --all-snapshot only from 1.51.0.
    • --color off stops 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.

  • beforeAll fails loudly with an IllegalStateException naming the cause when:

    • no secret is printed within 30 seconds (the message says whether the CLI is still running or has exited);
    • installing the secret throws;
    • the secret looks truncated (fewer than 22 characters);
    • it was not installed for the webhook route (overrideWebHookSecret accepts only sk_test_ keys).

    The CLI process is stopped on failure, and afterAll is null-safe.

  • The signing secret is masked (whsec_***) in the test logs.

  • One shared list: StripeApi.webhookEnabledEvents now drives the webhook endpoint's create and update parameters and the test listener's --events. A new unit test in StripeApiSpec pins 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 StripePaymentRouteTestKit trait, so classes compiled against 0.9.11 stay binary-compatible.

Release notes

  • Behaviour change: a suite using StripePaymentRouteTestKit now aborts in beforeAll when the Stripe CLI secret cannot be installed. Before, it continued without webhooks.
  • The Stripe CLI now receives only the 9 event types the webhook endpoint subscribes to, instead of every event.

Verification

  • sbt '+ Test/compile' (Scala 2.12 and 2.13) and scalafmtSbtCheck scalafmtCheck Test/scalafmtCheck both pass. StripeApiSpec "same events" passes.
  • Stripe CLI behaviour, checked against the test sandbox:
    • 1.50.4, and 1.55.12 with --events, sign forwarded events with the printed secret (raw HMAC check: 2 of 2 deliveries each).
    • 1.21.0 and 1.55.12 accept --color off --events <the 9 events>. They print the banner with no ANSI codes even with CLICOLOR_FORCE=1, and the new pattern captures the full 38-character secret.
  • Downstream check: a consumer's Stripe integration specs (subscription → webhook activation → cancellation; notification flows) ran against this branch published locally. 22 of 22 passed with CLI 1.21.0: the secret was installed (38 chars), and 8 forwarded webhooks all got 200, none 4xx.
  • No spec in this repository starts the Stripe CLI, and CI doesn't install it. The stripe listen path is therefore exercised only by consumers.

🤖 Generated with Claude Code

…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

codecov Bot commented Nov 17, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 2.70270% with 36 lines in your changes missing coverage. Please review.
✅ Project coverage is 40.82%. Comparing base (e49de74) to head (a25131e).

Files with missing lines Patch % Lines
.../payment/scalatest/StripePaymentRouteTestKit.scala 0.00% 36 Missing ⚠️
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     
Flag Coverage Δ
unittests 40.82% <2.70%> (-0.25%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@fupelaqu
fupelaqu merged commit 65334ce into main Nov 18, 2026
5 of 8 checks passed
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.

testkit: stripe listen exits on Stripe CLI >= 1.51.0 (no event subscription) and the failure is swallowed

1 participant