package jnpf.bizcommon.audit.service.listener;
|
|
import com.alibaba.fastjson.JSON;
|
import jnpf.bizcommon.audit.service.support.AuditQueryResponseSanitizer;
|
import org.junit.jupiter.api.Test;
|
import java.util.*;
|
import static org.junit.jupiter.api.Assertions.*;
|
|
public class DmsWorkflowAuditEventTest {
|
@Test public void frozenContextSurvivesMessageJsonAndDetailSanitizing() {
|
Map<String,Object> context = new LinkedHashMap<>();
|
context.put("taskId", "task"); context.put("operatorId", "round-2");
|
context.put("nodeId", "node"); context.put("nodeCode", "review"); context.put("nodeName", "审核");
|
context.put("untrustedExtra", "ignored");
|
Map<String,Object> wire = JSON.parseObject(JSON.toJSONString(Map.of("workflowAuditContext", context)));
|
Map<String,Object> extra = new LinkedHashMap<>();
|
AuditVisualLogListener.appendDmsWorkflowContext(extra, "dms_wenjian_xinzeng_shenhe", "task", wire);
|
Map<?,?> visible = (Map<?,?>) JSON.parseObject(AuditQueryResponseSanitizer.sanitizeJson(JSON.toJSONString(extra))).get("workflow");
|
assertEquals("round-2", visible.get("operatorId")); assertEquals("审核", visible.get("nodeName"));
|
assertEquals(5, visible.size());
|
}
|
@Test public void unrelatedTablesAndMismatchedInstancesCannotAcquireContext() {
|
Map<String,Object> form = Map.of("workflowAuditContext", Map.of("taskId", "task", "operatorId", "round"));
|
Map<String,Object> extra = new LinkedHashMap<>();
|
AuditVisualLogListener.appendDmsWorkflowContext(extra, "lims_other", "task", form);
|
AuditVisualLogListener.appendDmsWorkflowContext(extra, "dms_wenjian_xiuding_shenhe", "other", form);
|
AuditVisualLogListener.appendDmsWorkflowContext(extra, "dms_wenjian_xiuding_shenhe", null, form);
|
assertTrue(extra.isEmpty());
|
}
|
@Test public void historicalEventsWithoutContextAreNotAssignedAnInventedNode() {
|
Map<String,Object> extra = new LinkedHashMap<>();
|
AuditVisualLogListener.appendDmsWorkflowContext(extra, "dms_wenjian_xiuding_shenhe", "task", Map.of());
|
assertTrue(extra.isEmpty());
|
}
|
}
|