Files
commerce/api/checkout/sandbox_square_test.go
zooqueenandHanzo Dev 6c4f4d660b A sandbox read takes Square's sandbox names only
thirdparty/square.FromEnv is the one reader of the deployment's Square
account: SQUARE_SANDBOX_* for sandbox, SQUARE_* for production, never
mixed. The five readers (the org processor, the public tenant config,
the unified provider's env seed, the standalone init and payment links)
call it, so an empty sandbox set is an unconfigured processor and a
sandbox token is never paired with a production location.

The resolver tests now set the sandbox names they expect and keep the
production ones as hostile values a sandbox org must not show.

Co-authored-by: Hanzo Dev <[email protected]>
2026-10-16 07:27:17 -07:00

30 lines
1.1 KiB
Go

package checkout
import (
"testing"
"github.com/hanzoai/commerce/models/organization"
)
// A test-mode org with no Square account of its own, on a deployment with no
// sandbox account, mints no payment link: the production account is never its
// fallback, on the sandbox host or any other.
func TestSquareCheckoutClient_SandboxNeverBorrowsProduction(t *testing.T) {
t.Setenv("SQUARE_ENVIRONMENT", "production")
t.Setenv("SQUARE_ACCESS_TOKEN", "EAAA-prod-hostile")
t.Setenv("SQUARE_LOCATION_ID", "PRODLOC-hostile")
t.Setenv("SQUARE_SANDBOX_ACCESS_TOKEN", "")
t.Setenv("SQUARE_SANDBOX_LOCATION_ID", "")
if _, loc, err := squareCheckoutClientForOrg(&organization.Organization{}); err == nil {
t.Fatalf("sandbox org given a Square client at %q from production names", loc)
}
t.Setenv("SQUARE_SANDBOX_ACCESS_TOKEN", "EAAA-sandbox")
t.Setenv("SQUARE_SANDBOX_LOCATION_ID", "SBXLOC")
_, loc, err := squareCheckoutClientForOrg(&organization.Organization{})
if err != nil || loc != "SBXLOC" {
t.Fatalf("sandbox org: loc=%q err=%v, want the sandbox location", loc, err)
}
}