Files
commerce/api/billing/webhooks_org_test.go
zeekay 1943f1c093 Hanzo Commerce
Multi-tenant commerce and billing: orders, subscriptions, invoices, plans,
usage metering and a credit ledger. One Go binary. MIT OR Apache-2.0.

Claude-Session: https://claude.ai/code/session_01SAtaDFm8VDiWrhYHNNtxMw
2026-09-23 21:52:16 -07:00

33 lines
1.2 KiB
Go

// Copyright (c) 2014-present Hanzo AI, Inc.
// Licensed under MIT OR Apache-2.0. See LICENSE-MIT and LICENSE-APACHE.
package billing
import (
"testing"
"github.com/zap-proto/zip"
)
// TestResolveWebhookOrgSessionlessDoesNotPanic is the regression guard for the
// webhook-ingress 500: resolveWebhookOrg ran middleware.GetOrganization —
// gin MustGet — on requests that never passed the auth-token group, so every
// signature-VALID provider delivery panicked ("key organization does not
// exist") after passing HMAC verification. Sessionless resolution must fall
// through to header/env/default lookup instead.
func TestResolveWebhookOrgSessionlessDoesNotPanic(t *testing.T) {
app := zip.New(zip.Config{DisableStartupMessage: true})
c := app.TestCtx("POST", "/v1/billing/webhooks/square")
defer func() {
if r := recover(); r != nil {
t.Fatalf("resolveWebhookOrg panicked on a sessionless request: %v", r)
}
}()
// No "organization" key set — the sessionless webhook shape. The resolver
// may return nil here (no datastore in a bare test context); the contract
// under test is strictly "no panic", which the handler turns into an
// honest 503 rather than a recovered-panic 500.
_ = resolveWebhookOrg(c)
}