fix(пополнение): тестовая пара ключей и приёмочный список учёток
Тестовый режим берёт ROBOKASSA_TEST_PASS1/2, боевые не использует; TOPUP_WHITELIST открывает кнопку и создание только названным учёткам, включая владельца, — общий приём остаётся выключенным до чека. Receipt проверен на проводном виде, уведомление и ack защищены от пустого тела. План дополнен шагами приёмки. Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
@@ -39,6 +39,8 @@ def rk(monkeypatch):
|
||||
monkeypatch.setenv("ROBOKASSA_PASS2", P2)
|
||||
monkeypatch.setenv("ROBOKASSA_TEST", "0")
|
||||
monkeypatch.setenv("ROBOKASSA_HASH", "sha256")
|
||||
monkeypatch.setenv("ROBOKASSA_TEST_PASS1", "test-pass-one")
|
||||
monkeypatch.setenv("ROBOKASSA_TEST_PASS2", "test-pass-two")
|
||||
import pay_robokassa
|
||||
importlib.reload(pay_robokassa)
|
||||
return pay_robokassa
|
||||
@@ -84,6 +86,8 @@ def test_create_url_and_signature_by_docs(rk, monkeypatch, algo):
|
||||
assert q["SuccessUrl2Method"] == "GET" and q["FailUrl2Method"] == "GET"
|
||||
assert len(q["ExpirationDate"]) == 16 and q["ExpirationDate"][10] == "T"
|
||||
assert "IsTest" not in q
|
||||
assert parts.query.startswith("MerchantLogin=")
|
||||
assert "Receipt=%7B%22items%22%3A" in parts.query
|
||||
receipt = _receipt(100_000)
|
||||
assert q["Receipt"] == receipt
|
||||
base = (f"{LOGIN}:1000.00:1012:{quote(receipt, safe='')}:"
|
||||
@@ -106,6 +110,14 @@ def test_receipt_has_service_nomenclature_and_amount(rk):
|
||||
assert "sno" not in data
|
||||
|
||||
|
||||
def test_test_mode_uses_test_password_pair(rk, monkeypatch):
|
||||
"""Тестовый режим берёт отдельную пару; боевая даёт ошибку 29."""
|
||||
monkeypatch.setenv("ROBOKASSA_TEST", "1")
|
||||
assert rk.creds()["pass1"] == "test-pass-one"
|
||||
monkeypatch.setenv("ROBOKASSA_TEST_PASS1", "")
|
||||
assert rk.creds() is None
|
||||
|
||||
|
||||
def test_create_test_mode_adds_istest_not_in_signature(rk, monkeypatch):
|
||||
"""Тестовый режим — IsTest=1 в адресе, в подписи его нет (testing-mode).
|
||||
Порча: включить IsTest в подпись."""
|
||||
@@ -115,7 +127,7 @@ def test_create_test_mode_adds_istest_not_in_signature(rk, monkeypatch):
|
||||
receipt = _receipt(50_050)
|
||||
assert q["Receipt"] == receipt
|
||||
base = (f"{LOGIN}:500.50:1012:{quote(receipt, safe='')}:"
|
||||
f"{quote(RET, safe='')}:GET:{quote(RET, safe='')}:GET:{P1}")
|
||||
f"{quote(RET, safe='')}:GET:{quote(RET, safe='')}:GET:test-pass-one")
|
||||
assert q["SignatureValue"] == hashlib.sha256(base.encode()).hexdigest()
|
||||
|
||||
|
||||
|
||||
@@ -42,6 +42,8 @@ def env(tmp_path, monkeypatch):
|
||||
monkeypatch.setenv("ROBOKASSA_LOGIN", "shop")
|
||||
monkeypatch.setenv("ROBOKASSA_PASS1", "test-pass-one")
|
||||
monkeypatch.setenv("ROBOKASSA_PASS2", P2)
|
||||
monkeypatch.setenv("ROBOKASSA_TEST_PASS1", "test-pass-one")
|
||||
monkeypatch.setenv("ROBOKASSA_TEST_PASS2", P2)
|
||||
monkeypatch.setenv("ROBOKASSA_TEST", "1")
|
||||
monkeypatch.setenv("ROBOKASSA_HASH", "sha256")
|
||||
# Stand in test mode: its order numbers must not reach the live range (OpStateExt code 4).
|
||||
@@ -386,3 +388,17 @@ def test_payment_result_page_has_all_states(env):
|
||||
assert text in r.text, text
|
||||
for word in ("robokassa", "webhook"):
|
||||
assert word not in r.text.lower()
|
||||
|
||||
|
||||
def test_whitelist_trial_opens_only_named_user(env, monkeypatch):
|
||||
"""Приёмочный платёж: глобальный флаг 0, но именованная учётка видит кнопку и платит."""
|
||||
import topup
|
||||
db, auth, main, client, robo = env
|
||||
monkeypatch.setenv("TOPUP_ENABLED", "0")
|
||||
monkeypatch.setenv("TOPUP_WHITELIST", USER)
|
||||
assert topup.person_block(USER)["enabled"] is True
|
||||
assert topup.person_block(OTHER) is None
|
||||
r = client.post("/api/topups", headers=_h(auth), json={"amount": "1000"})
|
||||
assert r.status_code == 200
|
||||
r2 = client.post("/api/topups", headers=_h(auth, OTHER), json={"amount": "1000"})
|
||||
assert r2.status_code == 503
|
||||
|
||||
Reference in New Issue
Block a user