mirror of
https://github.com/corazoncp/zoom-sched-poc.git
synced 2026-12-01 12:50:31 +00:00
fix(r30/CR-01): require Zoom credential verification on confirmed pay
- Call zoom.get_access_token(body.credentials) before returning zoom_start_url on confirmed branches in pay_appointment - Add test_pay_confirmed_appointment_rejects_invalid_credentials verifying 401 on invalid credentials and idempotent 200 on valid credentials
This commit is contained in:
1 parent
cb96461073
commit
202fcc14ee
2 files changed
+61
No files matched your search
@@ -139,6 +139,7 @@ def create_app(test_config: dict | None = None) -> Flask:
|
||||
|
||||
# Idempotent: return existing confirmed session without creating a duplicate meeting
|
||||
if row["status"] == "confirmed":
|
||||
zoom.get_access_token(body.credentials)
|
||||
return jsonify(AppointmentResponse.model_validate(row).model_dump()), 200
|
||||
if row["status"] == "payment_processing":
|
||||
return jsonify({"error": "El pago ya está siendo procesado."}), 409
|
||||
@@ -146,6 +147,7 @@ def create_app(test_config: dict | None = None) -> Flask:
|
||||
if not db.claim_appointment_for_payment(row["session_id"], db_path=db_path):
|
||||
latest = db.get_appointment_by_lookup(row["session_id"], db_path=db_path)
|
||||
if latest and latest["status"] == "confirmed":
|
||||
zoom.get_access_token(body.credentials)
|
||||
return jsonify(AppointmentResponse.model_validate(latest).model_dump()), 200
|
||||
return jsonify({"error": "El pago ya está siendo procesado."}), 409
|
||||
|
||||
|
||||
@@ -160,6 +160,65 @@ def test_pay_appointment_is_idempotent(client, monkeypatch):
|
||||
assert len(create_calls) == 1
|
||||
|
||||
|
||||
def test_pay_confirmed_appointment_rejects_invalid_credentials(client, monkeypatch):
|
||||
test_client, _ = client
|
||||
create_calls = []
|
||||
_mock_zoom_happy_path(monkeypatch, create_calls=create_calls)
|
||||
|
||||
c_resp = test_client.post(
|
||||
"/api/appointments",
|
||||
json={
|
||||
"credentials": SAMPLE_CREDS,
|
||||
"client_name": "María Perez",
|
||||
"start_time_local": "2026-11-25T15:00",
|
||||
},
|
||||
)
|
||||
assert c_resp.status_code == 201
|
||||
sid = c_resp.get_json()["session_id"]
|
||||
|
||||
first = test_client.post(
|
||||
f"/api/appointments/{sid}/pay",
|
||||
json={"credentials": SAMPLE_CREDS},
|
||||
)
|
||||
assert first.status_code == 200
|
||||
assert first.get_json()["zoom_start_url"] == "https://zoom.us/s/987654321?zak=abc"
|
||||
assert len(create_calls) == 1
|
||||
|
||||
def fake_post_invalid_on_bad_creds(url, **kwargs):
|
||||
if url == "https://zoom.us/oauth/token":
|
||||
if kwargs.get("params", {}).get("account_id") != SAMPLE_CREDS["account_id"]:
|
||||
return FakeResponse(401, {"reason": "Invalid client_id or client_secret"})
|
||||
return FakeResponse(200, {"access_token": "mock_token"})
|
||||
if url == "https://api.zoom.us/v2/users/me/meetings":
|
||||
create_calls.append(kwargs.get("json"))
|
||||
raise AssertionError("create_meeting must not be called for already-confirmed appointment")
|
||||
raise AssertionError(f"Unexpected POST URL: {url}")
|
||||
|
||||
monkeypatch.setattr(zoom.requests, "post", fake_post_invalid_on_bad_creds)
|
||||
|
||||
bad_resp = test_client.post(
|
||||
f"/api/appointments/{sid}/pay",
|
||||
json={
|
||||
"credentials": {
|
||||
"account_id": "wrong_acc",
|
||||
"client_id": "wrong_id",
|
||||
"client_secret": "wrong_secret",
|
||||
}
|
||||
},
|
||||
)
|
||||
assert bad_resp.status_code == 401
|
||||
assert "zoom_start_url" not in bad_resp.get_json()
|
||||
assert len(create_calls) == 1
|
||||
|
||||
good_resp = test_client.post(
|
||||
f"/api/appointments/{sid}/pay",
|
||||
json={"credentials": SAMPLE_CREDS},
|
||||
)
|
||||
assert good_resp.status_code == 200
|
||||
assert good_resp.get_json()["zoom_start_url"] == "https://zoom.us/s/987654321?zak=abc"
|
||||
assert len(create_calls) == 1
|
||||
|
||||
|
||||
def test_booking_flow_never_persists_zoom_credentials(client, monkeypatch):
|
||||
test_client, db_file = client
|
||||
_mock_zoom_happy_path(monkeypatch)
|
||||
|
||||
Reference in new issue
Block a user