mirror of
https://github.com/nethunterzist/trendyol-analiz
synced 2026-08-29 21:38:00 +00:00
fix(auth): CiroMarket kategori 401 kalıcı düzeltme — router-based auth
Ne yaptık: - PUBLIC_PATHS whitelist tamamen kaldırıldı - protected_router = APIRouter(dependencies=[Depends(verify_api_key)]) eklendi - 33 korunan route @protected_router.*'a taşındı - 6 public route (/health, /, category-tree×4) @app.*'de kaldı - verify_api_key sadeleşti: request.url.path artık kontrol edilmiyor - test_auth_routing.py: regresyon guard — PUBLIC_PATHS geri gelirse CI fail eder Neden yaptık: - PUBLIC_PATHS her deploy/merge'de kayboluyordu → tekrarlayan 401 - Yapısal çözüm: ayrım kod mimarisinde, whitelist config'de değil
This commit is contained in:
@@ -63,6 +63,28 @@ def client(test_db):
|
||||
app.dependency_overrides.clear()
|
||||
|
||||
|
||||
@pytest.fixture(scope="function")
|
||||
def authed_client(test_db):
|
||||
"""Test client with valid API key — use for protected routes."""
|
||||
test_key = "test-api-key-for-pytest"
|
||||
os.environ["API_KEY"] = test_key
|
||||
|
||||
def override_get_db():
|
||||
try:
|
||||
yield test_db
|
||||
finally:
|
||||
pass
|
||||
|
||||
app.dependency_overrides[get_db] = override_get_db
|
||||
|
||||
with TestClient(app) as test_client:
|
||||
test_client.headers.update({"X-API-Key": test_key})
|
||||
yield test_client
|
||||
|
||||
app.dependency_overrides.clear()
|
||||
os.environ.pop("API_KEY", None)
|
||||
|
||||
|
||||
# Sample test data fixtures
|
||||
@pytest.fixture
|
||||
def sample_categories():
|
||||
|
||||
Reference in New Issue
Block a user