feat(gateway): 新增接口11和61的鉴权与测试页
This commit is contained in:
@@ -14,7 +14,11 @@ 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", "/api/v1/hair/grow-22"]
|
||||
MEASURE_ROUTES = {
|
||||
"/api/v1/face/measure-11": "/api/v1/face/measure",
|
||||
"/api/v1/face/measure-61": "/api/v1/face/measure-v2",
|
||||
}
|
||||
PROTECTED = [*MEASURE_ROUTES, FEATURES_42, "/api/v1/hairline/generate-52", "/api/v1/face/b-end-points", "/api/v1/hair/grow-22"]
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@@ -39,7 +43,8 @@ def test_protected_routes_reject_missing_static_and_refresh_tokens(client, monke
|
||||
monkeypatch.setattr(gateway, "_proxy", proxy)
|
||||
monkeypatch.setattr(gateway, "_face_features_response", features)
|
||||
refresh_token = login(client)["refresh_token"]
|
||||
for headers in ({}, {"X-API-Token": "yonghe1999"}, {"Authorization": "Bearer " + refresh_token}):
|
||||
for headers in ({}, {"X-API-Token": "yonghe1999"}, {"Authorization": "Bearer invalid"},
|
||||
{"Authorization": "Bearer " + refresh_token}):
|
||||
result = client.post(path, headers=headers)
|
||||
assert result.status_code == 401
|
||||
assert result.json()["code"] == 1009
|
||||
@@ -47,6 +52,20 @@ def test_protected_routes_reject_missing_static_and_refresh_tokens(client, monke
|
||||
features.assert_not_awaited()
|
||||
|
||||
|
||||
@pytest.mark.parametrize("path,legacy_path", MEASURE_ROUTES.items())
|
||||
def test_measure_alias_uses_legacy_path_and_preserves_legacy_access(client, monkeypatch, path, legacy_path):
|
||||
proxy = AsyncMock(return_value={"code": 0, "data": {"annotated_image_url": "/static/annotations/face.png"}})
|
||||
monkeypatch.setattr(gateway, "_proxy", proxy)
|
||||
headers = {"Authorization": "Bearer " + login(client)["access_token"]}
|
||||
photo = {"image_file": ("face.png", b"raw", "image/png")}
|
||||
|
||||
authenticated = client.post(path, headers=headers, files=photo)
|
||||
legacy = client.post(legacy_path, files=photo)
|
||||
assert authenticated.status_code == legacy.status_code == 200
|
||||
assert authenticated.json() == legacy.json() == proxy.return_value
|
||||
assert [call.args[1] for call in proxy.await_args_list] == [legacy_path, legacy_path]
|
||||
|
||||
|
||||
def test_login_expiry_tampering_and_refresh(client, monkeypatch):
|
||||
clock = SimpleNamespace(now=1_000_000)
|
||||
monkeypatch.setattr(client_auth, "time", SimpleNamespace(time=lambda: clock.now))
|
||||
|
||||
Reference in New Issue
Block a user