Bind stove API keys to configured client IP
This commit is contained in:
@@ -28,6 +28,19 @@ def test_invalid_key_wins_over_invalid_body(monkeypatch):
|
||||
assert response.json()["request_id"] == response.headers["X-Request-Id"]
|
||||
|
||||
|
||||
def test_other_ip_returns_403_before_opening_history_or_parsing_body(monkeypatch):
|
||||
seen = []
|
||||
monkeypatch.setattr(stove_api.stove_keys, "authenticate",
|
||||
lambda secret, ip: seen.append((secret, ip)) or {"status": "ip_not_allowed"})
|
||||
monkeypatch.setattr(stove_api.stove_history, "open_request",
|
||||
lambda **kw: seen.append("opened"))
|
||||
response = _client().post("/api/v1/stove-estimate", content="not-json",
|
||||
headers={"Content-Type": "application/json", "X-API-Key": "wrong-ip"})
|
||||
assert response.status_code == 403
|
||||
assert response.json()["code"] == "ip_not_allowed"
|
||||
assert seen == [("wrong-ip", "testclient")]
|
||||
|
||||
|
||||
def test_estimate_success_and_history(monkeypatch):
|
||||
calls = []
|
||||
key = {"id": 7, "limit_day": 1000, "ai_budget_rub_day": 300}
|
||||
|
||||
Reference in New Issue
Block a user