feat: 新增接口22生发控制与测试页

This commit is contained in:
xsl
2026-11-09 21:19:39 +08:00
parent c800822d54
commit b84a506b9b
21 changed files with 770 additions and 175 deletions
+10 -14
View File
@@ -66,22 +66,21 @@ def test_rewritten_peer_or_invalid_policy_fail_closed(policy):
assert not access.check_access(request("127.0.0.1"))[0]
def test_worker_guard_covers_all_interfaces_before_auth(policy, monkeypatch):
def test_worker_guard_covers_all_interfaces(policy):
import app as worker
monkeypatch.setattr(worker, "ACCEPT_PASSWORDS", ["access-test"])
headers = {"X-Internal-Token": "access-test"}
with TestClient(worker.app, client=("203.0.113.9", 50000)) as client:
assert client.post('/api/v1/hairline/generate-52').status_code == 403
assert client.post('/api/v1/hairline/generate-52/', headers=headers).status_code == 403
assert client.post('/api/v1/hairline/generate-52/').status_code == 403
assert client.post('/api/v1/debug/hairline-height-compare').status_code == 403
assert client.post('/api/v1/hairline/generate', headers=headers).status_code == 403
assert client.post('/api/v1/face/measure', headers=headers).status_code == 403
assert client.post('/api/v1/redraw', headers=headers).status_code == 403
assert client.post('/api/v1/hairline/generate').status_code == 403
assert client.post('/api/v1/face/measure').status_code == 403
assert client.post('/api/v1/redraw').status_code == 403
assert client.post('/api/v1/hair/grow-22').status_code == 403
assert client.get('/health').status_code == 403
assert client.get('/openapi.json').status_code == 403
policy.write_text('{"allowed_ips": ["203.0.113.9"]}')
assert client.post('/api/v1/hairline/generate-52', headers=headers).json()['code'] == 1004
assert client.post('/api/v1/hairline/generate-52').status_code == 401
assert client.post('/api/v1/hairline/generate-52').json()['code'] == 1004
assert client.post('/api/v1/hair/grow-22').status_code == 422
def test_gateway_does_not_apply_worker_ip_policy(policy, monkeypatch):
@@ -105,16 +104,13 @@ def test_gateway_does_not_apply_worker_ip_policy(policy, monkeypatch):
("/api/v1/hairline/generate-52", 1004),
("/api/v1/face/b-end-points", 1007),
])
def test_52_and_72_use_worker_transport_auth_not_client_bearer(policy, monkeypatch, path, expected_code):
def test_52_and_72_accept_allowlisted_peer_without_token(policy, path, expected_code):
import app as worker
policy.write_text('{"allowed_ips": ["49.232.51.171"]}')
monkeypatch.setattr(worker, "ACCEPT_PASSWORDS", ["access-test"])
client = TestClient(worker.app, client=("49.232.51.171", 50000))
try:
denied = client.post(path, headers={"Authorization": "Bearer client-access-token"})
assert denied.status_code == 401 and denied.json()["code"] == 1009
accepted = client.post(path, headers={"X-Internal-Token": "access-test"})
accepted = client.post(path)
assert accepted.status_code == 200 and accepted.json()["code"] == expected_code
finally:
client.close()