test(tradein): add auth header to /houses test broken by IDOR guard (#690)
CI test-job красный на main с мержа #690 (#702): IDOR-guard навесил обязательный X-Authenticated-User на /houses, но существующий тест звал эндпоинт без заголовка → _assert_estimate_access_by_id доходит до auth → 401 вместо 200 → deploy skipped. Добавлен header X-Authenticated-User: admin (admin байпасит ownership → 200 []). Заодно # noqa: E402 на module-level импорты (после weasyprint-мока — pre-existing lint, всплыл при правке).
This commit is contained in:
parent
9d94beae4f
commit
5aae790729
1 changed files with 10 additions and 4 deletions
|
|
@ -18,9 +18,9 @@ sys.modules.setdefault("weasyprint", _wp_mock)
|
||||||
sys.modules.setdefault("weasyprint.CSS", _wp_mock)
|
sys.modules.setdefault("weasyprint.CSS", _wp_mock)
|
||||||
sys.modules.setdefault("weasyprint.HTML", _wp_mock)
|
sys.modules.setdefault("weasyprint.HTML", _wp_mock)
|
||||||
|
|
||||||
import pytest
|
import pytest # noqa: E402 — импорт после weasyprint-мока (намеренно, см. выше)
|
||||||
from fastapi import FastAPI
|
from fastapi import FastAPI # noqa: E402
|
||||||
from fastapi.testclient import TestClient
|
from fastapi.testclient import TestClient # noqa: E402
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
|
|
@ -77,7 +77,13 @@ def test_get_estimate_houses_returns_empty_when_no_coords(app):
|
||||||
|
|
||||||
app.dependency_overrides[get_db] = override_db_no_coords
|
app.dependency_overrides[get_db] = override_db_no_coords
|
||||||
client = TestClient(app)
|
client = TestClient(app)
|
||||||
r = client.get("/api/v1/trade-in/estimate/00000000-0000-0000-0000-000000000000/houses")
|
# #690: /houses теперь скоупится по владельцу (X-Authenticated-User). Мок отдаёт
|
||||||
|
# непустой row (fake_target) → guard доходит до auth-проверки и без заголовка
|
||||||
|
# вернул бы 401. admin байпасит ownership → эндпоинт исполняется как раньше.
|
||||||
|
r = client.get(
|
||||||
|
"/api/v1/trade-in/estimate/00000000-0000-0000-0000-000000000000/houses",
|
||||||
|
headers={"X-Authenticated-User": "admin"},
|
||||||
|
)
|
||||||
assert r.status_code == 200
|
assert r.status_code == 200
|
||||||
assert r.json() == []
|
assert r.json() == []
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue