AI Gateway Go 0.10.0 源码快照 + 旗舰版需求规划报告
M0-M7 已完成:核心网关(身份/RBAC/TOTP/OIDC/SAML/Provider/配额/路由/内容策略/审计/定价)+ 资源市场(MCP/Skills/数字员工)。 含 22 个 PostgreSQL 迁移、管理端/门户端前端源码、OpenAPI 契约、部署 compose。 Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/sha256"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestReadRecordsValidatesChecksumAndDeterministicID(t *testing.T) {
|
||||
data := json.RawMessage(`{"id":7,"name":"研发"}`)
|
||||
canonical, _ := json.Marshal(map[string]any{"source_system": "python-gateway", "entity_type": "departments", "legacy_id": "7", "data": data})
|
||||
digest := sha256.Sum256(canonical)
|
||||
line, _ := json.Marshal(record{SourceSystem: "python-gateway", EntityType: "departments", LegacyID: "7", Data: data, Checksum: hex.EncodeToString(digest[:])})
|
||||
items, source, counts, err := readRecords(bytes.NewReader(append(line, '\n')))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(items) != 1 || items[0].NewID == "" || source == "" || counts["departments"] != 1 {
|
||||
t.Fatalf("unexpected result: %#v %s %#v", items, source, counts)
|
||||
}
|
||||
line[len(line)-2] ^= 1
|
||||
if _, _, _, err = readRecords(bytes.NewReader(append(line, '\n'))); err == nil {
|
||||
t.Fatal("expected tamper detection")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user