fix: accept legacy Huihui callback path for org orders
This commit is contained in:
@@ -111,17 +111,23 @@ def test_huihui_org_callback_verifies_provider_before_granting_points(authorizat
|
||||
"productId": "Basic", "userId": context["owner"].huihui_user_id,
|
||||
}
|
||||
|
||||
def send(body_payload, *, signature=True):
|
||||
def send(body_payload, *, signature=True, callback_path=path):
|
||||
body = json.dumps(body_payload, separators=(",", ":")).encode()
|
||||
headers = _huihui_virtual_headers(secret, body) if signature else {"X-Huihui-Signature": "bad"}
|
||||
return client.post(path, content=body, headers=headers)
|
||||
return client.post(callback_path, content=body, headers=headers)
|
||||
|
||||
with patch.dict(os.environ, {"HUIHUI_ORG_CALLBACK_SECRET": secret}), patch(
|
||||
with patch.dict(os.environ, {
|
||||
"HUIHUI_ORG_CALLBACK_SECRET": secret,
|
||||
"HUIHUI_VIRTUAL_CALLBACK_SECRET": "",
|
||||
}), patch(
|
||||
"routers.tokens.HuihuiOrgPaymentClient"
|
||||
) as client_factory:
|
||||
provider = client_factory.return_value
|
||||
provider.get_order.return_value = provider_data
|
||||
assert send(payload, signature=False).status_code == 401
|
||||
legacy_path = "/api/token/payment/huihui/virtual/notify"
|
||||
assert send(payload, signature=False, callback_path=legacy_path).status_code == 401
|
||||
assert send({**payload, "orderNo": "unknown"}, callback_path=legacy_path).status_code == 404
|
||||
assert send({**payload, "amountCents": 99}).status_code == 422
|
||||
assert send(payload).status_code == 409
|
||||
provider.get_order.return_value = {**provider_data, "payStatus": 2}
|
||||
@@ -129,7 +135,7 @@ def test_huihui_org_callback_verifies_provider_before_granting_points(authorizat
|
||||
provider.get_order.return_value = {**provider_data, "payStatus": 2, "chargeAmount": 2}
|
||||
assert send(payload).status_code == 422
|
||||
provider.get_order.return_value = {**provider_data, "payStatus": 2}
|
||||
first = send(payload)
|
||||
first = send(payload, callback_path=legacy_path)
|
||||
second = send(payload)
|
||||
|
||||
assert first.status_code == 200
|
||||
|
||||
Reference in New Issue
Block a user