feat(shipping-notice): 增强发货通知与审计功能,支持敏感数据控制与哈希链校验
- 更新发货通知工具 API,剥离不可信的操作人身份字段,确保审计安全 - 引入审计事件的哈希链校验机制,支持数据完整性验证 - 增强订单抽取与审计功能,支持敏感快照的访问控制 - 更新相关模型与服务,确保新功能的完整性与可追溯性 - 完善文档与代码注释,反映新的业务逻辑与审计要求
This commit is contained in:
1 parent
95cdfe66b0
commit
d0fe084999
225 files changed
+25923
-6653
No files matched your search
@@ -46,7 +46,7 @@ def test_append_shipping_audit_event_hashes_state_and_rejects_sensitive_metadata
|
||||
assert event.after_snapshot_json == {'status': 'processing'}
|
||||
assert event.operation_id == 'op-stage0-1'
|
||||
assert event.metadata_json == {'target_status': 'processing'}
|
||||
assert event.retention_expires_at is not None
|
||||
assert event.retention_expires_at is None
|
||||
with pytest.raises(ValidationError) as caught:
|
||||
append_shipping_audit_event(
|
||||
event_type='invalid',
|
||||
@@ -120,14 +120,16 @@ def test_shipping_audit_event_rejects_orm_update_and_delete(app):
|
||||
db.session.rollback()
|
||||
|
||||
|
||||
def test_append_shipping_audit_event_hashes_client_context_and_session_item(app):
|
||||
"""会话工作项审计必须记录属主/工作项软引用,且 IP/UA 仅存哈希。"""
|
||||
def test_append_shipping_audit_event_hashes_client_context_and_workflow_refs(app):
|
||||
"""Workflow 审计必须记录属主/软引用与哈希链,且 IP/UA 仅存哈希。"""
|
||||
with app.app_context():
|
||||
event = append_shipping_audit_event(
|
||||
event_type='session_work_item_created',
|
||||
aggregate_type='session_pdf_work_item',
|
||||
aggregate_id='SPWI-1',
|
||||
session_item_id='SPWI-1',
|
||||
event_type='workflow_item_created',
|
||||
aggregate_type='shipping_notice_workflow_item',
|
||||
aggregate_id='SWI-1',
|
||||
workflow_id='SWF-1',
|
||||
workflow_item_id='SWI-1',
|
||||
version_no=1,
|
||||
owner_user_id=42,
|
||||
conversation_id='conv-session-1',
|
||||
client_ip='203.0.113.9',
|
||||
@@ -135,13 +137,18 @@ def test_append_shipping_audit_event_hashes_client_context_and_session_item(app)
|
||||
after={
|
||||
'lifecycle_status': 'pending_review',
|
||||
'current_version_no': 1,
|
||||
'item_no': 'SPWI-1',
|
||||
'item_no': 'SWI-1',
|
||||
'workflow_no': 'SWF-1',
|
||||
},
|
||||
metadata={'source': 'upload'},
|
||||
)
|
||||
db.session.commit()
|
||||
|
||||
assert event.session_item_id == 'SPWI-1'
|
||||
assert event.workflow_id == 'SWF-1'
|
||||
assert event.workflow_item_id == 'SWI-1'
|
||||
assert event.version_no == 1
|
||||
assert event.event_hash
|
||||
assert event.diff_json is not None
|
||||
assert event.owner_user_id == '42'
|
||||
assert event.client_ip_hash == hash_client_context_value('203.0.113.9')
|
||||
assert event.user_agent_hash == hash_client_context_value('Mozilla/5.0 TestAgent')
|
||||
@@ -149,13 +156,14 @@ def test_append_shipping_audit_event_hashes_client_context_and_session_item(app)
|
||||
assert event.after_snapshot_json == {
|
||||
'lifecycle_status': 'pending_review',
|
||||
'current_version_no': 1,
|
||||
'item_no': 'SPWI-1',
|
||||
'item_no': 'SWI-1',
|
||||
'workflow_no': 'SWF-1',
|
||||
}
|
||||
with pytest.raises(ValidationError) as caught:
|
||||
append_shipping_audit_event(
|
||||
event_type='probe',
|
||||
aggregate_type='session_pdf_work_item',
|
||||
aggregate_id='SPWI-2',
|
||||
aggregate_type='shipping_notice_workflow_item',
|
||||
aggregate_id='SWI-2',
|
||||
metadata={'client_ip': '203.0.113.9'},
|
||||
)
|
||||
assert caught.value.code == 'SHIPPING_NOTICE.AUDIT_METADATA_FORBIDDEN'
|
||||
|
||||
Reference in new issue
Block a user