security: verify OC orders, fail-closed revoke, per-IP rate buckets, escaped guest email
ci/woodpecker/push/woodpecker Pipeline failed
ci/woodpecker/push/woodpecker Pipeline failed
This commit is contained in:
1 parent
5a0a3decbe
commit
c9726f4029
6 files changed
+264
-104
No files matched your search
@@ -69,7 +69,7 @@ def grant_once(email, amount, ref):
|
||||
|
||||
# --- reference building: per-order, non-empty, distinct per purchase ---
|
||||
check("reference keyed on the order id",
|
||||
credit_pack_reference("caseyg", {"idV2": "or_abc123"}), "oc:caseyg:or_abc123")
|
||||
credit_pack_reference("caseyg", {"idV2": "or_abc123"}), "oc:or_abc123")
|
||||
check("two purchases differ even from one member",
|
||||
credit_pack_reference("caseyg", {"idV2": "or_1"}) != credit_pack_reference("caseyg", {"idV2": "or_2"}),
|
||||
True)
|
||||
|
||||
@@ -38,6 +38,7 @@ def check(cond, msg):
|
||||
|
||||
def order(freq, status, amount, created="2026-11-17T01:52:56.450Z"):
|
||||
return {"frequency": freq, "status": status,
|
||||
"amount": {"value": amount, "currency": "USD"},
|
||||
"totalAmount": {"value": amount, "currency": "USD"},
|
||||
"createdAt": created, "lastChargedAt": created}
|
||||
|
||||
@@ -76,11 +77,11 @@ check(_current_dues([{"frequency": "MONTHLY", "status": "ACTIVE",
|
||||
"totalAmount": {"value": "not-a-number"}}]) == (None, None),
|
||||
"an unparseable amount -> (None, None)")
|
||||
|
||||
print("6. the most recent live recurrence wins when a member has history")
|
||||
print("6. stacked live monthlies are summed (not newest-only)")
|
||||
old = order("MONTHLY", "ACTIVE", 5, "2024-01-01T00:00:00.000Z")
|
||||
new = order("MONTHLY", "ACTIVE", 10, "2026-11-17T01:52:56.450Z")
|
||||
check(_current_dues([new, old]) == (10.0, "MONTHLY"),
|
||||
"the newest live monthly ($10) wins over an older $5 monthly")
|
||||
check(_current_dues([new, old]) == (15.0, "MONTHLY"),
|
||||
"two live monthly subscriptions are summed ($5 + $10 = $15)")
|
||||
|
||||
print()
|
||||
if FAILS:
|
||||
|
||||
@@ -113,7 +113,7 @@ m.OC_PERSONAL_TOKEN = "test-token"
|
||||
|
||||
print("4. the webhook branch: the fix is present, and its silent-fallthrough shape is gone")
|
||||
src = (ROOT / "app" / "main.py").read_text()
|
||||
branch = src[src.index('if slug and "membership" in tier_name.lower()'):]
|
||||
branch = src[src.index('if "membership" in verified_tier.lower()'):]
|
||||
branch = branch[:branch.index("elif slug and first_payment")]
|
||||
check("fetch_account_by_slug(slug)" in branch,
|
||||
"the branch resolves an unknown payer by account email")
|
||||
|
||||
@@ -101,6 +101,20 @@ async def order_amount_ok(_order_id_v2=None):
|
||||
return 5000
|
||||
|
||||
|
||||
async def order_details_ok(_order_id_v2=None):
|
||||
"""Verified OC order for the credit-pack fixture (2026-11-19 hardening)."""
|
||||
return {
|
||||
"id": "or_testOrderId123",
|
||||
"status": "PAID",
|
||||
"frequency": "ONETIME",
|
||||
"amount": {"valueInCents": 5000},
|
||||
"platformTipAmount": {"valueInCents": 0},
|
||||
"fromAccount": {"slug": MEMBER_SLUG},
|
||||
"toAccount": {"slug": m.OC_COLLECTIVE_SLUG},
|
||||
"tier": {"name": "Credit pack"},
|
||||
}
|
||||
|
||||
|
||||
async def budget_noop(_email):
|
||||
return 0.0
|
||||
|
||||
@@ -118,6 +132,7 @@ async def main():
|
||||
|
||||
m.sync_team_budget_from_balance = budget_noop # no LiteLLM calls in a test
|
||||
m.get_order_amount = order_amount_ok
|
||||
m.get_order_details = order_details_ok
|
||||
|
||||
async with REAL_ASYNC_CLIENT(transport=transport, base_url="http://test") as c:
|
||||
# --- 1. AUTH: a wrong token is still a 401. ---
|
||||
@@ -181,7 +196,7 @@ async def main():
|
||||
m.get_credit_balance(MEMBER_EMAIL) == 50.0)
|
||||
ref = m.credit_pack_reference(MEMBER_SLUG, {"idV2": ORDER_ID})
|
||||
check("grant: the ledger row is keyed on the OC order (idempotence key)",
|
||||
ref == f"oc:{MEMBER_SLUG}:{ORDER_ID}" and m.credit_reference_exists(ref))
|
||||
ref == f"oc:{ORDER_ID}" and m.credit_reference_exists(ref))
|
||||
|
||||
# --- 4. Re-delivery moves no money. ---
|
||||
r = await c.post(url, json=PAYLOAD)
|
||||
|
||||
Reference in new issue
Block a user