test(e2e): Phase 23B — rebuild E2E infrastructure; fix 6 real prod defects it exposed
Phase 23 closed as PARTIAL: fake coverage was gone, but the E2E layer itself
was still empty — no conftest.py anywhere, ~15 fixtures that never existed,
6 files crashing at import on os.environ["E2E_PASSWORD"], and CI never ran E2E.
STATUS's "10 E2E files / ~80+ cases ✅" described files that had never executed.
Infrastructure delivered:
- tests/e2e/conftest.py: ApiClient (trust_env=False — a host http_proxy turns
localhost calls into 502), operator_token(username) / new_user / admin_token
fixtures, and a session probe that calls pytest.exit(4) when the stack is
unreachable. NOT skip: skip would launder "did not run" into "passed".
- pytest.ini, tests/e2e/requirements.txt, and tests/e2e/sql/
seed_e2e_operators.sql — migrations contain NO operator seed at all, so a
fresh database has zero logins; the seed creates 6 e2e accounts with role
bindings, idempotent, password injected via `psql -v pwd`.
- CI job `e2e`: compose up -> poll /health/live (timeout = fail) -> seed ->
pytest -> always teardown. Gate D-23-D is now closed.
- 8 E2E files migrated off import-time env reads; tautological assertions
(`x == t or not x`), a counselor token standing in for content_editor, and a
bare `status_code == 200` claiming to prove INV-020 were replaced with real
permission/behavior assertions.
Six real production defects found only by running against real PostgreSQL
(H2 has zero coverage for all of them):
- D-23B-A (Critical): stale V042__add_appointment_operator_register_permission.sql
left in target/classes; src had replaced it with V042__add_service_location_
announcements.sql. Packing without clean put two V042 in the jar -> Flyway
"Found more than one migration with version 042" -> app would not start.
Guard added: testBuildOutputHasNoDuplicateMigrationVersions scans build output
(src is clean, so only this catches it).
- D-23B-B (High): non-UUID path variable reached the DB -> 500 + leaked
`invalid input syntax for type uuid`. Now rejected at the controller.
- D-23B-C (High): 6 E2E files raised KeyError at import -> never collected.
- D-23B-E (Critical): permissions = 48, role_permissions for super_admin = 18,
matchmaker = 0. V015's "grant all to super_admin" was a point-in-time snapshot;
the 30 permissions added later were never granted. On a fresh stack an admin
cannot create a service station and matchmakers can do nothing. V044 restores
super_admin to its documented definition (not an expansion); the matchmaker
permission set needs a product decision and is left as a residual.
- D-23B-I (Medium): IllegalArgumentException (e.g. invalid activity type) was
unmapped -> 500. Now BAD_REQUEST.
- D-23B-J (High): `operator does not exist: uuid = character varying` — Java
ids are String, columns are uuid, PostgreSQL does not implicitly cast in
comparisons. Fixed at the source with JDBC `stringtype=unspecified` (docker
profile); production datasource comes from deploy env and needs the same.
One judgement retracted: an initial read suggested service_appointment.register
was missing. It is not — the endpoint uses service.assisted_registration, seeded
in V029, and the code deliberately avoids a duplicate permission. Nothing was
changed on that basis.
Verification: 33 E2E passed against a live stack; unreachable stack and a
missing operator password both exit 4 (never skip/pass); backend regression
656 / 0 failures / 0 errors / 3 skipped (baseline 655, +1 guard, negatively
validated by injecting a duplicate V042 -> exactly one test turned red).
This commit is contained in:
@@ -1,41 +1,75 @@
|
||||
"""
|
||||
V1.1 咨询 / 服务站 / 内容编辑员权限 E2E —— 空壳已移除(Phase 23 KEEP-VERIFY,2026-09-18)
|
||||
婚恋咨询权限 E2E(INV-012 只能访问分配的咨询 / INV-013 红娘不能读咨询正文)。
|
||||
|
||||
历史问题
|
||||
--------
|
||||
原文件 10 个测试函数**全部**为 `pass` 空壳(注释「TODO: P13A / P17 / P19 实现后完善」),
|
||||
依赖不存在的 `counselor_client` / `counseling_service_factory` / `content_editor_client`
|
||||
等 fixture(全局无 `conftest.py`),从未执行过,
|
||||
却在 `docs/STATUS.md` 中被计为 P23-T07「咨询权限 ✅」。
|
||||
|
||||
计划 Phase 23 Gate:「**不允许 skip/pass 空壳**」。
|
||||
|
||||
当前状态
|
||||
--------
|
||||
本文件现**不含任何测试函数**,pytest 收集 0 个用例。
|
||||
|
||||
仍待真实实现的场景(需求不因移除空壳而丢失)
|
||||
------------------------------------------
|
||||
1. Counselor 只能看到被分配给自己的咨询(INV-012)
|
||||
2. Counselor 不可查看其他咨询师的服务
|
||||
3. 红娘不可查看咨询正文(INV-013)
|
||||
4. 普通管理员默认不可查看咨询敏感备注
|
||||
5. 咨询管理员可分配咨询人员
|
||||
6. 咨询过程中可转交风控
|
||||
7. 服务站人员不能浏览全平台用户(INV-018)
|
||||
8. 服务站人员可处理本服务站预约
|
||||
9. 内容编辑员不能访问用户婚恋档案(INV-019)
|
||||
10. 内容编辑员可管理文章内容
|
||||
|
||||
现状补充(Phase 23 实测)
|
||||
------------------------
|
||||
- INV-012 已由 `CounselingPhase13ATest` 的 4 个真实用例覆盖;
|
||||
- INV-013 / INV-019 已由 Phase 23 新增的真实行为用例覆盖
|
||||
(`V11InvariantsTest#inv013MatchmakerCannotReadCounselingBody`、
|
||||
`V11InvariantsTest#inv019ContentEditorHasNoUserDataPermission`,
|
||||
走真实 `CounselingService.getDetail`,已通过负向注入验证);
|
||||
- INV-018 已由 `ServiceAppointmentDataScopeTest` 覆盖。
|
||||
即:E2E 层待补,但不变量本身已有真实覆盖。
|
||||
|
||||
真实可执行的 V1.1 E2E 见:`tests/e2e/run_v11_tests.py`
|
||||
关键设计:**先证明本人能读到正文**,再证明他人读不到。
|
||||
只断言"他人读不到"会被"全局脱敏/接口全量报错"轻易蒙混过关——
|
||||
那证明的不是 INV-013,而是接口坏了。
|
||||
"""
|
||||
import pytest
|
||||
|
||||
pytestmark = pytest.mark.e2e
|
||||
|
||||
SENSITIVE = "SENSITIVE-BODY-MARKER"
|
||||
|
||||
|
||||
def _create_counseling(api, token: str) -> str:
|
||||
data = api.ok(
|
||||
"POST",
|
||||
"/counseling/services",
|
||||
token=token,
|
||||
json={
|
||||
"serviceType": "relationship_guidance",
|
||||
"requestSource": "user_self",
|
||||
"userRequestSummary": SENSITIVE,
|
||||
"preferredServiceMode": "online",
|
||||
"preferredTime": "morning",
|
||||
},
|
||||
)
|
||||
assert data["status"] == "pending", f"咨询初始状态异常:{data}"
|
||||
return data["id"]
|
||||
|
||||
|
||||
def test_owner_can_read_own_request_summary(api, user_token):
|
||||
"""反证:接口确实会返回正文,"读不到"才可能是权限生效而非接口失效。"""
|
||||
service_id = _create_counseling(api, user_token)
|
||||
data = api.ok("GET", f"/counseling/services/{service_id}", token=user_token)
|
||||
assert data["userRequestSummary"] == SENSITIVE, f"本人竟读不到自己的咨询正文:{data}"
|
||||
|
||||
|
||||
def test_matchmaker_has_no_counseling_view(api, user_token, operator_token):
|
||||
"""INV-013:红娘不具备 counseling.service.view,读取咨询详情必须被拒。"""
|
||||
service_id = _create_counseling(api, user_token)
|
||||
resp = api.call(
|
||||
"GET",
|
||||
f"/counseling/services/operator/{service_id}",
|
||||
token=operator_token("e2e_matchmaker"),
|
||||
)
|
||||
assert resp.status_code == 403, (
|
||||
f"红娘竟被允许访问咨询详情:HTTP {resp.status_code} {resp.text[:200]}"
|
||||
)
|
||||
assert SENSITIVE not in resp.text, "响应体泄漏了咨询正文"
|
||||
|
||||
|
||||
def test_counselor_cannot_read_unassigned_service(api, user_token, operator_token):
|
||||
"""INV-012:咨询师只能访问明确分配给自己的服务。"""
|
||||
service_id = _create_counseling(api, user_token)
|
||||
resp = api.call(
|
||||
"GET",
|
||||
f"/counseling/services/operator/{service_id}",
|
||||
token=operator_token("e2e_counselor"),
|
||||
)
|
||||
body = resp.json()
|
||||
assert body.get("success") is False, f"未分配的咨询竟被咨询师读到:{body}"
|
||||
assert SENSITIVE not in resp.text, "响应体泄漏了咨询正文"
|
||||
|
||||
|
||||
def test_non_uuid_service_id_is_rejected_not_500(api, user_token):
|
||||
"""
|
||||
非 UUID 的 path 参数应被判为 400,而不是打到数据库抛出
|
||||
`operator does not exist: uuid = character varying` 变成 500。
|
||||
"""
|
||||
resp = api.call("GET", "/counseling/services/not-a-uuid", token=user_token)
|
||||
assert resp.status_code != 500, (
|
||||
f"非法 ID 触发了 500(数据库类型异常外泄):HTTP {resp.status_code}"
|
||||
)
|
||||
assert 400 <= resp.status_code < 500, f"非法 ID 应返回 4xx,实际 {resp.status_code}"
|
||||
|
||||
Reference in New Issue
Block a user