feat(integration-connector): 绑定参数映射与凭据 DB 加密落库模式
- 绑定新增 param_mapping_json:域参数→接口参数声明式映射(map_response 规范),空对象同名直通 - 凭据引用新增 db 维护模式:secret_ciphertext Fernet 加密落库,主密钥 INTEGRATION_CREDENTIAL_KEY 仅环境注入,与 env 引用模式并存 - 新增 credential_types 凭据形态注册表:代码注册各类型字段清单,UI 动态渲染与 API 组装校验的唯一事实来源 - 移除绑定 context_source_code 独立列,路由条件统一 context_selector_json - 管理端表单 Modal 重构为 Drawer,新增 JSON 编辑字段组件与页面级测试 - 迁移 rd1/re1 重挂当前唯一 head dd22ee33ff44,维持单 head 链 - settings 移除 IN_TRANSIT_TRANSFER_ERP_* 配置,外部端点/凭据移交连接器客户端实例管理
This commit is contained in:
1 parent
5df204fdea
commit
31591e663e
35 files changed
+4345
-750
No files matched your search
@@ -146,6 +146,69 @@ def test_client_instance_test_connection(app, client, admin_headers, fake_gatewa
|
||||
assert response.get_json()["data"]["ok"] is True
|
||||
|
||||
|
||||
class ProbeSpyTransport:
|
||||
"""记录 probe 收到的 client 配置,验证独立列(endpoint/timeout)已拼回 config_json。"""
|
||||
|
||||
connector_type = "soap"
|
||||
|
||||
def __init__(self):
|
||||
self.seen = None
|
||||
|
||||
def probe(self, *, client):
|
||||
self.seen = client
|
||||
return {"ok": True, "code": "HTTP_200", "message": "wsdl root <definitions>"}
|
||||
|
||||
def call(self, *, client, interface, request): # pragma: no cover — 走到即失败
|
||||
self.seen = {"unexpected_call": True}
|
||||
|
||||
|
||||
def test_client_instance_test_connection_merges_endpoint_column(app, client, admin_headers, fake_gateway):
|
||||
"""连接测试回归:endpoint 存独立列(config_json 为空)时必须拼回配置再探测。
|
||||
|
||||
曾因测试端点只透传 config_json,SOAP 客户端误报
|
||||
'SOAP contract not frozen (missing wsdl/endpoint)'。
|
||||
"""
|
||||
created = client.post(f"{API_PREFIX}/client-instances", headers=admin_headers, json={
|
||||
"code": "CLI-SOAP", "name": "soap client", "connector_type": "soap", "environment": "prod",
|
||||
"endpoint": "https://erp.invalid/wsdl", "timeout_seconds": 45,
|
||||
"config_json": {},
|
||||
})
|
||||
assert created.status_code == 201
|
||||
|
||||
spy = ProbeSpyTransport()
|
||||
fake_gateway.transports["soap"] = spy
|
||||
response = client.post(f"{API_PREFIX}/client-instances/CLI-SOAP/test", headers=admin_headers)
|
||||
|
||||
assert response.status_code == 200
|
||||
data = response.get_json()["data"]
|
||||
assert data["ok"] is True
|
||||
# 独立列值必须出现在传给 transport 的 config_json 里(关键断言)。
|
||||
assert spy.seen["config_json"]["endpoint"] == "https://erp.invalid/wsdl"
|
||||
assert spy.seen["config_json"]["timeout_seconds"] == 45
|
||||
|
||||
|
||||
def test_client_instance_test_connection_reports_unreachable(app, client, admin_headers, fake_gateway):
|
||||
"""probe 探测不通 → 仍 200 但 ok=False(探测结果是业务结果,不是请求错误)。"""
|
||||
client.post(f"{API_PREFIX}/client-instances", headers=admin_headers, json={
|
||||
"code": "CLI-DOWN", "name": "down", "connector_type": "rest", "environment": "prod",
|
||||
"endpoint": "https://down.invalid",
|
||||
})
|
||||
|
||||
class DownTransport:
|
||||
connector_type = "rest"
|
||||
|
||||
def probe(self, *, client):
|
||||
return {"ok": False, "code": "CONNECTION_FAILED", "message": "connection refused"}
|
||||
|
||||
fake_gateway.transports["rest"] = DownTransport()
|
||||
response = client.post(f"{API_PREFIX}/client-instances/CLI-DOWN/test", headers=admin_headers)
|
||||
assert response.status_code == 200
|
||||
data = response.get_json()["data"]
|
||||
assert data["ok"] is False
|
||||
assert data["status"] == "failed"
|
||||
assert data["result"]["code"] == "CONNECTION_FAILED"
|
||||
|
||||
|
||||
def test_update_client_instance(app, client, admin_headers):
|
||||
"""PUT /client-instances/<code> → 200,更新 name/config/enabled。"""
|
||||
client.post(f"{API_PREFIX}/client-instances", headers=admin_headers, json={
|
||||
@@ -162,13 +225,13 @@ def test_update_client_instance(app, client, admin_headers):
|
||||
|
||||
|
||||
def test_update_interface_definition(app, client, admin_headers):
|
||||
"""PUT /interface-definitions/<code> → 200,更新模板/回传映射/状态。"""
|
||||
"""PUT /interface-definitions/<code> → 200,更新模板/回传映射;body 里的 status 被忽略。"""
|
||||
client.post(f"{API_PREFIX}/client-instances", headers=admin_headers, json={
|
||||
"code": "CLI-I", "name": "cli", "connector_type": "rest", "environment": "prod",
|
||||
"config_json": {},
|
||||
})
|
||||
client.post(f"{API_PREFIX}/interface-definitions", headers=admin_headers, json={
|
||||
"code": "IF-U", "name": "iface", "client_instance_code": "CLI-I", "connector_type": "rest",
|
||||
"code": "IF-U", "name": "iface", "client_instance_code": "CLI-I",
|
||||
"request_spec_json": {"path": "/v1/old"}, "status": "draft",
|
||||
})
|
||||
response = client.put(f"{API_PREFIX}/interface-definitions/IF-U", headers=admin_headers, json={
|
||||
@@ -177,12 +240,86 @@ def test_update_interface_definition(app, client, admin_headers):
|
||||
})
|
||||
assert response.status_code == 200
|
||||
data = response.get_json()["data"]
|
||||
assert data["status"] == "published"
|
||||
# 状态只能经生命周期动作端点流转:PUT 携带 status 不生效,仍为创建时的 draft
|
||||
assert data["status"] == "draft"
|
||||
assert data["request_spec_json"] == {"path": "/v1/new"}
|
||||
assert data["response_mapping_json"] == {"qty": "data.quantity"}
|
||||
|
||||
|
||||
def test_interface_connector_type_derived_from_client(app, client, admin_headers):
|
||||
"""连接器类型由所属客户端实例服务端推导:创建/换绑客户端均以客户端为准,body 传值被忽略。"""
|
||||
client.post(f"{API_PREFIX}/client-instances", headers=admin_headers, json={
|
||||
"code": "CLI-D1", "name": "soap cli", "connector_type": "soap", "environment": "prod",
|
||||
"config_json": {},
|
||||
})
|
||||
client.post(f"{API_PREFIX}/client-instances", headers=admin_headers, json={
|
||||
"code": "CLI-D2", "name": "rest cli", "connector_type": "rest", "environment": "prod",
|
||||
"config_json": {},
|
||||
})
|
||||
# 创建:body 误传 rest(与客户端 soap 不一致)→ 落库以客户端为准
|
||||
created = client.post(f"{API_PREFIX}/interface-definitions", headers=admin_headers, json={
|
||||
"code": "IF-DERIVE", "name": "iface", "client_instance_code": "CLI-D1",
|
||||
"connector_type": "rest",
|
||||
})
|
||||
assert created.status_code == 201
|
||||
assert created.get_json()["data"]["connector_type"] == "soap"
|
||||
# 换绑客户端 → 类型跟随新客户端
|
||||
updated = client.put(f"{API_PREFIX}/interface-definitions/IF-DERIVE", headers=admin_headers, json={
|
||||
"client_instance_code": "CLI-D2",
|
||||
})
|
||||
assert updated.status_code == 200
|
||||
assert updated.get_json()["data"]["connector_type"] == "rest"
|
||||
# 客户端不存在 → 400(而非依赖外键报 500)
|
||||
missing = client.post(f"{API_PREFIX}/interface-definitions", headers=admin_headers, json={
|
||||
"code": "IF-NOCLI", "name": "iface", "client_instance_code": "CLI-NOT-EXIST",
|
||||
})
|
||||
assert missing.status_code == 400
|
||||
|
||||
|
||||
def test_interface_create_freezes_enabled(app, client, admin_headers):
|
||||
"""接口定义 enabled 冻结:请求体传值被忽略,可用性只由 status 生命周期表达。"""
|
||||
client.post(f"{API_PREFIX}/client-instances", headers=admin_headers, json={
|
||||
"code": "CLI-FE", "name": "cli", "connector_type": "rest", "environment": "prod",
|
||||
})
|
||||
created = client.post(f"{API_PREFIX}/interface-definitions", headers=admin_headers, json={
|
||||
"code": "IF-FE", "name": "iface", "client_instance_code": "CLI-FE", "enabled": False,
|
||||
})
|
||||
assert created.status_code == 201
|
||||
assert created.get_json()["data"]["enabled"] is True
|
||||
|
||||
|
||||
def test_interface_lifecycle_transitions(app, client, admin_headers):
|
||||
"""发布/撤回/退役/恢复按转移表流转;非法转移与未知动作被拒绝。"""
|
||||
client.post(f"{API_PREFIX}/client-instances", headers=admin_headers, json={
|
||||
"code": "CLI-LC", "name": "cli", "connector_type": "rest", "environment": "prod",
|
||||
"config_json": {},
|
||||
})
|
||||
client.post(f"{API_PREFIX}/interface-definitions", headers=admin_headers, json={
|
||||
"code": "IF-LC", "name": "iface", "client_instance_code": "CLI-LC",
|
||||
})
|
||||
|
||||
def lifecycle(action, code="IF-LC"):
|
||||
return client.post(f"{API_PREFIX}/interface-definitions/{code}/{action}", headers=admin_headers)
|
||||
|
||||
# draft 上直接撤回/退役 → 400(源状态不符)
|
||||
assert lifecycle("unpublish").status_code == 400
|
||||
assert lifecycle("retire").status_code == 400
|
||||
# draft → published → draft(撤回)→ published → retired(退役)→ draft(恢复)
|
||||
assert lifecycle("publish").get_json()["data"]["status"] == "published"
|
||||
assert lifecycle("unpublish").get_json()["data"]["status"] == "draft"
|
||||
assert lifecycle("publish").get_json()["data"]["status"] == "published"
|
||||
assert lifecycle("retire").get_json()["data"]["status"] == "retired"
|
||||
# retired 不能直接发布,须经恢复为草稿
|
||||
illegal = lifecycle("publish")
|
||||
assert illegal.status_code == 400
|
||||
assert illegal.get_json()["error"]["code"] == "INTEGRATION.ILLEGAL_STATUS_TRANSITION"
|
||||
assert lifecycle("reopen").get_json()["data"]["status"] == "draft"
|
||||
# 接口不存在 → 404
|
||||
assert lifecycle("publish", code="IF-NOPE").status_code == 404
|
||||
|
||||
|
||||
def test_update_binding(app, client, admin_headers):
|
||||
"""PUT /bindings/<id> → 200,更新映射版本/优先级/状态。"""
|
||||
"""PUT /bindings/<id> → 200,更新映射版本/优先级;状态不经 PUT 改写(走生命周期端点)。"""
|
||||
client.post(f"{API_PREFIX}/client-instances", headers=admin_headers, json={
|
||||
"code": "CLI-B", "name": "cli", "connector_type": "rest", "environment": "prod",
|
||||
"config_json": {},
|
||||
@@ -192,7 +329,7 @@ def test_update_binding(app, client, admin_headers):
|
||||
})
|
||||
created = client.post(f"{API_PREFIX}/bindings", headers=admin_headers, json={
|
||||
"capability": "in_transit_transfer.query_inventory", "client_instance_code": "CLI-B",
|
||||
"interface_definition_code": "IF-B", "status": "draft",
|
||||
"interface_definition_code": "IF-B",
|
||||
})
|
||||
binding_id = created.get_json()["data"]["id"]
|
||||
response = client.put(f"{API_PREFIX}/bindings/{binding_id}", headers=admin_headers, json={
|
||||
@@ -202,24 +339,153 @@ def test_update_binding(app, client, admin_headers):
|
||||
data = response.get_json()["data"]
|
||||
assert data["priority"] == 5
|
||||
assert data["mapping_version"] == 2
|
||||
assert data["status"] == "published"
|
||||
# 请求体携带 status 被忽略:状态只能经 /publish 动作端点流转
|
||||
assert data["status"] == "draft"
|
||||
|
||||
# 发布绑定有就绪门禁:接口定义须先发布
|
||||
client.post(f"{API_PREFIX}/interface-definitions/IF-B/publish", headers=admin_headers)
|
||||
published = client.post(f"{API_PREFIX}/bindings/{binding_id}/publish", headers=admin_headers)
|
||||
assert published.get_json()["data"]["status"] == "published"
|
||||
|
||||
|
||||
def test_binding_create_forces_draft_and_pair_validation(app, client, admin_headers):
|
||||
"""新建绑定固定落 draft;客户端与接口成对校验(错配/缺失均 400)。"""
|
||||
client.post(f"{API_PREFIX}/client-instances", headers=admin_headers, json={
|
||||
"code": "CLI-BC", "name": "cli", "connector_type": "rest", "environment": "prod",
|
||||
"endpoint": "https://erp.invalid",
|
||||
})
|
||||
client.post(f"{API_PREFIX}/client-instances", headers=admin_headers, json={
|
||||
"code": "CLI-OTHER", "name": "other", "connector_type": "rest", "environment": "prod",
|
||||
})
|
||||
client.post(f"{API_PREFIX}/interface-definitions", headers=admin_headers, json={
|
||||
"code": "IF-BC", "name": "iface", "client_instance_code": "CLI-BC", "connector_type": "rest",
|
||||
})
|
||||
# 请求体携带 status / context_source_code 均被忽略:状态走生命周期端点,
|
||||
# 来源路由条件统一由 context_selector_json 表达(无独立快捷列)
|
||||
created = client.post(f"{API_PREFIX}/bindings", headers=admin_headers, json={
|
||||
"capability": "in_transit_transfer.query_inventory",
|
||||
"client_instance_code": "CLI-BC", "interface_definition_code": "IF-BC",
|
||||
"status": "published", "context_source_code": "DBS-AWSBI",
|
||||
})
|
||||
assert created.status_code == 201
|
||||
data = created.get_json()["data"]
|
||||
assert data["status"] == "draft"
|
||||
assert "context_source_code" not in data
|
||||
|
||||
# 接口定义不属于所选客户端 → 400(fail-fast,不留给调用期)
|
||||
mismatch = client.post(f"{API_PREFIX}/bindings", headers=admin_headers, json={
|
||||
"capability": "in_transit_transfer.query_inventory",
|
||||
"client_instance_code": "CLI-OTHER", "interface_definition_code": "IF-BC",
|
||||
})
|
||||
assert mismatch.status_code == 400
|
||||
assert mismatch.get_json()["error"]["code"] == "INTEGRATION.BINDING_PAIR_MISMATCH"
|
||||
# 客户端/接口不存在 → 400(而非依赖外键报 500)
|
||||
assert client.post(f"{API_PREFIX}/bindings", headers=admin_headers, json={
|
||||
"capability": "in_transit_transfer.query_inventory",
|
||||
"client_instance_code": "CLI-NOT-EXIST", "interface_definition_code": "IF-BC",
|
||||
}).status_code == 400
|
||||
assert client.post(f"{API_PREFIX}/bindings", headers=admin_headers, json={
|
||||
"capability": "in_transit_transfer.query_inventory",
|
||||
"client_instance_code": "CLI-BC", "interface_definition_code": "IF-NOT-EXIST",
|
||||
}).status_code == 400
|
||||
|
||||
# 更新换绑接口时同样成对校验:以变更后的最终组合为准
|
||||
binding_id = data["id"]
|
||||
updated = client.put(f"{API_PREFIX}/bindings/{binding_id}", headers=admin_headers, json={
|
||||
"client_instance_code": "CLI-OTHER",
|
||||
})
|
||||
assert updated.status_code == 400
|
||||
assert updated.get_json()["error"]["code"] == "INTEGRATION.BINDING_PAIR_MISMATCH"
|
||||
|
||||
|
||||
def test_binding_lifecycle_transitions(app, client, admin_headers):
|
||||
"""发布/撤回/退役/恢复按转移表流转;发布有就绪门禁(接口须已发布且客户端启用)。"""
|
||||
client.post(f"{API_PREFIX}/client-instances", headers=admin_headers, json={
|
||||
"code": "CLI-BLC", "name": "cli", "connector_type": "rest", "environment": "prod",
|
||||
"config_json": {},
|
||||
})
|
||||
client.post(f"{API_PREFIX}/interface-definitions", headers=admin_headers, json={
|
||||
"code": "IF-BLC", "name": "iface", "client_instance_code": "CLI-BLC",
|
||||
})
|
||||
created = client.post(f"{API_PREFIX}/bindings", headers=admin_headers, json={
|
||||
"capability": "in_transit_transfer.query_inventory",
|
||||
"client_instance_code": "CLI-BLC", "interface_definition_code": "IF-BLC",
|
||||
})
|
||||
binding_id = created.get_json()["data"]["id"]
|
||||
|
||||
def lifecycle(action):
|
||||
return client.post(f"{API_PREFIX}/bindings/{binding_id}/{action}", headers=admin_headers)
|
||||
|
||||
# 接口定义还是草稿 → 发布绑定被就绪门禁拦截(避免发布永不生效的死绑定)
|
||||
not_ready = lifecycle("publish")
|
||||
assert not_ready.status_code == 400
|
||||
assert not_ready.get_json()["error"]["code"] == "INTEGRATION.BINDING_TARGET_NOT_READY"
|
||||
|
||||
# 接口发布后:draft → published → draft(撤回)→ published → retired(退役)→ draft(恢复)
|
||||
client.post(f"{API_PREFIX}/interface-definitions/IF-BLC/publish", headers=admin_headers)
|
||||
assert lifecycle("publish").get_json()["data"]["status"] == "published"
|
||||
assert lifecycle("unpublish").get_json()["data"]["status"] == "draft"
|
||||
assert lifecycle("publish").get_json()["data"]["status"] == "published"
|
||||
assert lifecycle("retire").get_json()["data"]["status"] == "retired"
|
||||
# retired 不能直接发布,须经恢复为草稿
|
||||
illegal = lifecycle("publish")
|
||||
assert illegal.status_code == 400
|
||||
assert illegal.get_json()["error"]["code"] == "INTEGRATION.ILLEGAL_STATUS_TRANSITION"
|
||||
assert lifecycle("reopen").get_json()["data"]["status"] == "draft"
|
||||
# 绑定不存在 → 404
|
||||
assert client.post(f"{API_PREFIX}/bindings/999999/publish", headers=admin_headers).status_code == 404
|
||||
|
||||
|
||||
def test_update_credential_reference(app, client, admin_headers):
|
||||
"""PUT /credential-references/<code> → 200,更新 secret_ref/status,且不回显明文。"""
|
||||
"""PUT /credential-references/<code> → 200,更新 secret_ref,且不回显明文。"""
|
||||
client.post(f"{API_PREFIX}/credential-references", headers=admin_headers, json={
|
||||
"code": "CRED-U", "secret_ref": "IN_TRANSIT_ERP_PASSWORD",
|
||||
})
|
||||
response = client.put(f"{API_PREFIX}/credential-references/CRED-U", headers=admin_headers, json={
|
||||
"secret_ref": "IN_TRANSIT_ERP_PASSWORD_ROTATED", "status": "rotating",
|
||||
"secret_ref": "IN_TRANSIT_ERP_PASSWORD_ROTATED",
|
||||
})
|
||||
assert response.status_code == 200
|
||||
data = response.get_json()["data"]
|
||||
assert data["secret_ref"] == "IN_TRANSIT_ERP_PASSWORD_ROTATED"
|
||||
assert data["status"] == "rotating"
|
||||
assert "secret" not in str(data).lower() or data.get("secret") is None
|
||||
|
||||
|
||||
def test_credential_status_two_state_toggle(app, client, admin_headers):
|
||||
"""凭据状态两态开关:active/retired 可经 PUT 互切;rotating 不可进入;存量 rotating 可恢复。"""
|
||||
client.post(f"{API_PREFIX}/credential-references", headers=admin_headers, json={
|
||||
"code": "CRED-TS", "secret_ref": "IN_TRANSIT_ERP_PASSWORD",
|
||||
})
|
||||
# active → retired(停用;解析层只认 active,停用即断流)
|
||||
retired = client.put(f"{API_PREFIX}/credential-references/CRED-TS", headers=admin_headers, json={
|
||||
"status": "retired",
|
||||
})
|
||||
assert retired.status_code == 200
|
||||
assert retired.get_json()["data"]["status"] == "retired"
|
||||
# rotating 不可进入(其现语义等于断供,真实版本化轮换属 P2)
|
||||
rotating = client.put(f"{API_PREFIX}/credential-references/CRED-TS", headers=admin_headers, json={
|
||||
"status": "rotating",
|
||||
})
|
||||
assert rotating.status_code == 400
|
||||
# retired → active(恢复启用)
|
||||
reactivated = client.put(f"{API_PREFIX}/credential-references/CRED-TS", headers=admin_headers, json={
|
||||
"status": "active",
|
||||
})
|
||||
assert reactivated.get_json()["data"]["status"] == "active"
|
||||
# 存量 rotating 数据(经 create 兼容通道落库)可经 PUT 置回 active 恢复
|
||||
client.post(f"{API_PREFIX}/credential-references", headers=admin_headers, json={
|
||||
"code": "CRED-LEGACY", "secret_ref": "LEGACY_KEY", "status": "rotating",
|
||||
})
|
||||
recovered = client.put(f"{API_PREFIX}/credential-references/CRED-LEGACY", headers=admin_headers, json={
|
||||
"status": "active",
|
||||
})
|
||||
assert recovered.status_code == 200
|
||||
assert recovered.get_json()["data"]["status"] == "active"
|
||||
# 非法状态值 → 400
|
||||
assert client.put(f"{API_PREFIX}/credential-references/CRED-TS", headers=admin_headers, json={
|
||||
"status": "bogus",
|
||||
}).status_code == 400
|
||||
|
||||
|
||||
def test_client_instance_split_columns(app, client, admin_headers):
|
||||
"""POST /client-instances 写 endpoint/timeout_seconds 独立列,config_json 仅存扩展。"""
|
||||
created = client.post(f"{API_PREFIX}/client-instances", headers=admin_headers, json={
|
||||
@@ -265,26 +531,101 @@ def test_interface_definition_split_columns(app, client, admin_headers):
|
||||
assert updated.get_json()["data"]["request_path"] == "/inventory/{invoice_no}"
|
||||
|
||||
|
||||
def test_binding_split_columns(app, client, admin_headers):
|
||||
"""POST/PUT /bindings 写 context_source_code 独立列并回显。"""
|
||||
# ---- 绑定参数映射 / 凭据 db 模式 ----
|
||||
|
||||
def test_binding_param_mapping_round_trip(app, client, admin_headers):
|
||||
"""POST/PUT /bindings 透传 param_mapping_json,序列化原样返回。"""
|
||||
client.post(f"{API_PREFIX}/client-instances", headers=admin_headers, json={
|
||||
"code": "CLI-BC", "name": "cli", "connector_type": "rest", "environment": "prod",
|
||||
"code": "CLI-PM", "name": "cli", "connector_type": "rest", "environment": "prod",
|
||||
"endpoint": "https://erp.invalid",
|
||||
})
|
||||
client.post(f"{API_PREFIX}/interface-definitions", headers=admin_headers, json={
|
||||
"code": "IF-BC", "name": "iface", "client_instance_code": "CLI-BC", "connector_type": "rest",
|
||||
"code": "IFACE-PM", "name": "iface", "client_instance_code": "CLI-PM", "connector_type": "rest",
|
||||
})
|
||||
created = client.post(f"{API_PREFIX}/bindings", headers=admin_headers, json={
|
||||
"capability": "in_transit_transfer.query_inventory",
|
||||
"client_instance_code": "CLI-BC", "interface_definition_code": "IF-BC",
|
||||
"context_source_code": "DBS-AWSBI", "status": "published",
|
||||
"client_instance_code": "CLI-PM", "interface_definition_code": "IFACE-PM",
|
||||
"param_mapping_json": {"organization": {"expr": "external_org"},
|
||||
"condition": {"template": "img04 = '{invoice_no}'"}},
|
||||
})
|
||||
assert created.status_code == 201
|
||||
data = created.get_json()["data"]
|
||||
assert data["context_source_code"] == "DBS-AWSBI"
|
||||
assert data["param_mapping_json"]["organization"] == {"expr": "external_org"}
|
||||
|
||||
updated = client.put(f"{API_PREFIX}/bindings/{data['id']}", headers=admin_headers, json={
|
||||
"context_source_code": "CRANE-SZ",
|
||||
})
|
||||
updated = client.put(f"{API_PREFIX}/bindings/{data['id']}", headers=admin_headers,
|
||||
json={"param_mapping_json": {"condition": {"template": "img02 = '{warehouse}'"}}})
|
||||
assert updated.status_code == 200
|
||||
assert updated.get_json()["data"]["context_source_code"] == "CRANE-SZ"
|
||||
assert updated.get_json()["data"]["param_mapping_json"] == {
|
||||
"condition": {"template": "img02 = '{warehouse}'"},
|
||||
}
|
||||
|
||||
|
||||
def test_credential_db_mode_round_trip(app, client, admin_headers):
|
||||
"""db 模式:按凭据类型加密字段落库;回显非密字段、绝不回显密文;只改密码保留用户名。"""
|
||||
from cryptography.fernet import Fernet
|
||||
|
||||
app.config["INTEGRATION_CREDENTIAL_KEY"] = Fernet.generate_key().decode("ascii")
|
||||
created = client.post(f"{API_PREFIX}/credential-references", headers=admin_headers, json={
|
||||
"code": "CRED-DB", "secret_provider": "db",
|
||||
"username": "erp_user", "password": "erp_pass",
|
||||
})
|
||||
assert created.status_code == 201
|
||||
data = created.get_json()["data"]
|
||||
assert data["secret_fields"] == {"username": "erp_user"}
|
||||
assert data["has_secret"] is True
|
||||
assert "erp_pass" not in created.get_data(as_text=True)
|
||||
assert "secret_ciphertext" not in data
|
||||
|
||||
updated = client.put(f"{API_PREFIX}/credential-references/CRED-DB", headers=admin_headers,
|
||||
json={"password": "new_pass"})
|
||||
assert updated.status_code == 200
|
||||
data = updated.get_json()["data"]
|
||||
assert data["secret_fields"] == {"username": "erp_user"} # 只改密码时用户名保留
|
||||
assert "new_pass" not in updated.get_data(as_text=True)
|
||||
|
||||
|
||||
def test_credential_db_mode_token_type_and_types_endpoint(app, client, admin_headers):
|
||||
"""token 类型按其字段清单组装;类型清单端点返回注册表。"""
|
||||
from cryptography.fernet import Fernet
|
||||
|
||||
app.config["INTEGRATION_CREDENTIAL_KEY"] = Fernet.generate_key().decode("ascii")
|
||||
types = client.get(f"{API_PREFIX}/credential-references/types", headers=admin_headers)
|
||||
assert types.status_code == 200
|
||||
type_names = {item["type"] for item in types.get_json()["data"]}
|
||||
assert type_names == {"password", "token", "api_key"}
|
||||
|
||||
created = client.post(f"{API_PREFIX}/credential-references", headers=admin_headers, json={
|
||||
"code": "CRED-TOKEN", "secret_provider": "db", "credential_type": "token",
|
||||
"token": "tk-123",
|
||||
})
|
||||
assert created.status_code == 201
|
||||
data = created.get_json()["data"]
|
||||
assert data["credential_type"] == "token"
|
||||
assert data["secret_fields"] == {} # token 是密文字段,不回显
|
||||
assert "tk-123" not in created.get_data(as_text=True)
|
||||
|
||||
# token 必填缺失 → 400
|
||||
missing = client.post(f"{API_PREFIX}/credential-references", headers=admin_headers, json={
|
||||
"code": "CRED-TOKEN2", "secret_provider": "db", "credential_type": "token",
|
||||
})
|
||||
assert missing.status_code == 400
|
||||
|
||||
|
||||
def test_credential_db_mode_unknown_type_rejected(app, client, admin_headers):
|
||||
"""未知凭据类型 → 400(fail-closed)。"""
|
||||
from cryptography.fernet import Fernet
|
||||
|
||||
app.config["INTEGRATION_CREDENTIAL_KEY"] = Fernet.generate_key().decode("ascii")
|
||||
response = client.post(f"{API_PREFIX}/credential-references", headers=admin_headers, json={
|
||||
"code": "CRED-BAD", "secret_provider": "db", "credential_type": "nope",
|
||||
"username": "u", "password": "p",
|
||||
})
|
||||
assert response.status_code == 400
|
||||
|
||||
|
||||
def test_credential_db_mode_requires_username_and_password(app, client, admin_headers):
|
||||
"""db 模式创建缺用户名或密码 → 400。"""
|
||||
response = client.post(f"{API_PREFIX}/credential-references", headers=admin_headers, json={
|
||||
"code": "CRED-DB2", "secret_provider": "db", "username": "only-user",
|
||||
})
|
||||
assert response.status_code == 400
|
||||
Reference in new issue
Block a user