""" 本地资格 E2E(INV-011:本地资格佐证不得被未授权方读取)。 打真实活栈:新用户经 mock 微信登录,走真实的声明/查询链路。 """ import pytest pytestmark = pytest.mark.e2e # 生产 local_eligibility 的 eligibility_type CHECK 白名单内的合规取值。 ELIGIBILITY_TYPE = "household_registration" REGION_CODE = "321181" # 丹阳 def test_new_user_is_not_declared(api, user_token): data = api.ok("GET", "/local-eligibility", token=user_token) assert data["verificationStatus"] == "not_declared", f"新用户初始状态异常:{data}" def test_declaration_is_persisted(api, user_token): """声明后应能查回声明内容(真实落库,不是内存态)。""" api.ok( "POST", "/local-eligibility/declaration", token=user_token, json={"eligibilityType": ELIGIBILITY_TYPE, "regionCode": REGION_CODE}, ) data = api.ok("GET", "/local-eligibility", token=user_token) assert data["eligibilityType"] == ELIGIBILITY_TYPE, f"声明未落库:{data}" assert data["verificationStatus"] != "not_declared", f"声明后状态未推进:{data}" def test_other_user_cannot_read_my_declaration(api, new_user): """ INV-011(数据侧):资格查询是 userId 自限定的, 另一个用户读到的必须是**他自己的**空状态,绝不能看到 A 的声明。 """ user_a = new_user() api.ok( "POST", "/local-eligibility/declaration", token=user_a["token"], json={"eligibilityType": ELIGIBILITY_TYPE, "regionCode": REGION_CODE}, ) mine = api.ok("GET", "/local-eligibility", token=user_a["token"]) assert mine["eligibilityType"] == ELIGIBILITY_TYPE user_b = new_user() other = api.ok("GET", "/local-eligibility", token=user_b["token"]) assert other["userId"] == user_b["user_id"], "返回了他人 userId(越权)" assert other["userId"] != user_a["user_id"] assert other["eligibilityType"] is None, f"B 看到了 A 的资格声明(越权):{other}" assert other["verificationStatus"] == "not_declared"