Skip to content

Tests: billing/stripe_webhooks.py has only 18% coverage — subscription upgrade/downgrade flows untested #95

Description

@BHUVANSH855

Test Coverage Gap

Summary

app/billing/stripe_webhooks.py has only 18% test coverage
(75 of 92 statements untested). The Stripe webhook handler — which controls
plan upgrades and downgrades — is almost entirely untested.

Uncovered Lines

Lines 26–52 (verify_stripe_signature), 57–132 (full webhook handler)

Why This Matters

The Stripe webhook handler is a billing-critical security boundary:

  • It upgrades accounts to premium tier based on webhook payload
  • It downgrades accounts on subscription cancellation
  • Signature verification (verify_stripe_signature) is the only guard
    against forged upgrade requests

A bug here could allow free accounts to gain premium access or paying
accounts to be incorrectly downgraded. The signature verification function
itself (lines 26–52) has zero test coverage.

What Needs Tests

  • verify_stripe_signature — valid signature returns True
  • verify_stripe_signature — invalid signature returns False
  • verify_stripe_signature — expired timestamp (>5 min) returns False
  • POST /webhooks/stripecheckout.session.completed upgrades account to premium
  • POST /webhooks/stripecustomer.subscription.deleted downgrades to free
  • POST /webhooks/stripe — missing/invalid signature returns 400
  • POST /webhooks/stripe — unknown org_login in metadata is handled gracefully

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions