fix(gateway): 补齐鉴权测试页并保持旧接口兼容
This commit is contained in:
@@ -13,6 +13,7 @@ gateway = importlib.import_module("gateway.app")
|
||||
LOGIN = "/api/v1/auth/login"
|
||||
REFRESH = "/api/v1/auth/refresh"
|
||||
FEATURES_42 = "/api/v1/face/features-42"
|
||||
CHECK = "/api/v1/auth/check"
|
||||
PROTECTED = [FEATURES_42, "/api/v1/hairline/generate-52", "/api/v1/face/b-end-points"]
|
||||
|
||||
|
||||
@@ -58,10 +59,13 @@ def test_login_expiry_tampering_and_refresh(client, monkeypatch):
|
||||
access, refresh = data["access_token"], data["refresh_token"]
|
||||
headers = {"Authorization": f"Bearer {access}"}
|
||||
assert client.post(path, headers=headers).status_code == 200
|
||||
assert client.get(CHECK).status_code == 401
|
||||
assert client.get(CHECK, headers=headers).json()["code"] == 0
|
||||
assert client.post(path, headers={"Authorization": f"Bearer {access}x"}).status_code == 401
|
||||
assert client.post(REFRESH, json={"refresh_token": access}).status_code == 401
|
||||
clock.now += data["expires_in"]
|
||||
assert client.post(path, headers=headers).status_code == 401
|
||||
assert client.get(CHECK, headers=headers).status_code == 401
|
||||
response = client.post(REFRESH, json={"refresh_token": refresh})
|
||||
assert response.status_code == 200 and response.headers["cache-control"] == "no-store"
|
||||
refreshed = response.json()["data"]
|
||||
@@ -92,4 +96,27 @@ def test_features42_combines_processed_photo_with_main_features(client, monkeypa
|
||||
"zygoma_expansion": True, "temple_hollowing": True,
|
||||
}
|
||||
prepared.assert_awaited_once_with(b"raw", None)
|
||||
analyzer.assert_called_once_with(b"processed", None)
|
||||
analyzer.assert_called_once_with(b"processed", None, accept_age_alias=True)
|
||||
|
||||
|
||||
def test_bearer_requirement_is_scoped_to_three_business_routes_and_check(client):
|
||||
schema = client.get("/openapi.json").json()
|
||||
protected = {
|
||||
path
|
||||
for path, methods in schema["paths"].items()
|
||||
for method in methods.values()
|
||||
if isinstance(method, dict) and {"ClientBearer": []} in method.get("security", [])
|
||||
}
|
||||
assert protected == {*PROTECTED, CHECK}
|
||||
|
||||
|
||||
def test_original_features_needs_no_bearer_and_preserves_legacy_analysis(client, monkeypatch):
|
||||
analyzer = Mock(return_value={"face_shape": "鹅蛋脸", "contour_type": "轮廓适中"})
|
||||
monkeypatch.setattr("face_features.analyze_features", analyzer)
|
||||
prepared = AsyncMock()
|
||||
monkeypatch.setattr(gateway, "_prepare_features_42", prepared)
|
||||
response = client.post("/api/v1/face/features", files={"image_file": ("face.jpg", b"raw")})
|
||||
assert response.status_code == 200 and response.json()["code"] == 0
|
||||
assert json.loads(response.json()["data"]["features"]) == analyzer.return_value
|
||||
analyzer.assert_called_once_with(b"raw", None)
|
||||
prepared.assert_not_awaited()
|
||||
|
||||
Reference in New Issue
Block a user