1db21fb899
- 生产/测试 WeKnora 地址、租户 ID、知识库 ID 由静态 env 收敛为版本化 UI 设置,保留修订号与操作人审计 - 新增 serviceverify:保存前真调目标端点探测,端点无效才拒绝;网络抖动或无凭据仅告警 - 迁移 000042(生产 WeKnora 端点)/000043(服务目标);补齐设置候选与校验契约用例
79 lines
2.8 KiB
Go
79 lines
2.8 KiB
Go
package governance
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestValidProductionWeKnoraBaseURL(t *testing.T) {
|
|
base := CreateUISettingsCandidateRequest{
|
|
DocumentRefreshSeconds: 15, ResourceRefreshSeconds: 30,
|
|
StalledAfterSeconds: 1800, FinalizingAfterSeconds: 7200,
|
|
IngestionConcurrency: 2, UpdatedBy: "admin-1",
|
|
Now: time.Date(2026, 9, 18, 9, 0, 0, 0, time.UTC),
|
|
}
|
|
if !base.Valid() {
|
|
t.Fatal("an empty endpoint means \"not configured\" and must stay legal")
|
|
}
|
|
configured := base
|
|
configured.ProductionWeKnoraBaseURL = "https://weknora.prod.example:8443/weknora"
|
|
if !configured.Valid() {
|
|
t.Fatalf("bare http(s) origin rejected: %q", configured.ProductionWeKnoraBaseURL)
|
|
}
|
|
for _, unsafe := range []string{
|
|
"weknora.prod.example",
|
|
"ftp://weknora.prod.example",
|
|
"https://user:pass@weknora.prod.example",
|
|
"https://weknora.prod.example/?token=abc",
|
|
"https://weknora.prod.example/#frag",
|
|
" https://weknora.prod.example",
|
|
"https://weknora.prod.example\r\nX-Injected: 1",
|
|
} {
|
|
candidate := base
|
|
candidate.ProductionWeKnoraBaseURL = unsafe
|
|
if candidate.Valid() {
|
|
t.Fatalf("unsafe endpoint accepted: %q", unsafe)
|
|
}
|
|
}
|
|
}
|
|
|
|
// The other three service fields carry the same "empty means not configured"
|
|
// rule and their own shape: an origin for the test endpoint, decimal digits for
|
|
// the tenant, and a token without whitespace or URL pieces for the knowledge base.
|
|
func TestValidServiceTargetFields(t *testing.T) {
|
|
base := CreateUISettingsCandidateRequest{
|
|
DocumentRefreshSeconds: 15, ResourceRefreshSeconds: 30,
|
|
StalledAfterSeconds: 1800, FinalizingAfterSeconds: 7200,
|
|
IngestionConcurrency: 2, UpdatedBy: "admin-1",
|
|
Now: time.Date(2026, 9, 18, 9, 0, 0, 0, time.UTC),
|
|
}
|
|
configured := base
|
|
configured.TestWeKnoraBaseURL = "https://weknora.test.example:8443/weknora"
|
|
configured.ProductionTenantID = "10000"
|
|
configured.ProductionKnowledgeBaseID = "1b52c140-2e18-4676-afc5-4c7d8d190a8c"
|
|
if !configured.Valid() {
|
|
t.Fatalf("valid service targets rejected: %#v", configured)
|
|
}
|
|
for _, unsafe := range []string{"weknora.test.example", "https://user:pass@weknora.test.example", "https://weknora.test.example?token=abc", "ftp://weknora.test.example"} {
|
|
candidate := base
|
|
candidate.TestWeKnoraBaseURL = unsafe
|
|
if candidate.Valid() {
|
|
t.Fatalf("unsafe test endpoint accepted: %q", unsafe)
|
|
}
|
|
}
|
|
for _, unsafe := range []string{"abc", "10 000", "-1", "0", "10000.5", "10000000000000000000000", "10000\n20000"} {
|
|
candidate := base
|
|
candidate.ProductionTenantID = unsafe
|
|
if candidate.Valid() {
|
|
t.Fatalf("unsafe production tenant id accepted: %q", unsafe)
|
|
}
|
|
}
|
|
for _, unsafe := range []string{"kb/abc", "kb abc", "kb-abc?x", "kb#frag", "https://weknora.prod.example/kb", `kb\abc`} {
|
|
candidate := base
|
|
candidate.ProductionKnowledgeBaseID = unsafe
|
|
if candidate.Valid() {
|
|
t.Fatalf("unsafe knowledge base id accepted: %q", unsafe)
|
|
}
|
|
}
|
|
}
|