保存 DNS 多账户数据层与实库故障夹具修复前检查点
基础模型和迁移已完成;增量竞态暴露 MySQL 审计故障注入权限问题,后续修复,不代表完整功能或验收通过。
This commit is contained in:
1 parent
26b8c3c5c0
commit
02e039984a
19 files changed
+1000
-11
No files matched your search
@@ -0,0 +1,44 @@
|
||||
package domain
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestDNSAccountValidationAndSerialization(t *testing.T) {
|
||||
base := DNSAccount{ID: "dns-one", Name: "生产 DNS", ProjectID: "default", OwnerUserID: "primary-super-admin",
|
||||
Provider: "aliyun", CredentialRef: "secret://dns/aliyun/example", Status: DNSAccountActive,
|
||||
VerificationState: DNSAccountUnverified, Revision: 1}
|
||||
if err := base.Validate(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for name, change := range map[string]func(*DNSAccount){
|
||||
"empty_id": func(a *DNSAccount) { a.ID = "" },
|
||||
"bad_project": func(a *DNSAccount) { a.ProjectID = "../other" },
|
||||
"missing_owner": func(a *DNSAccount) { a.OwnerUserID = "" },
|
||||
"blank_name": func(a *DNSAccount) { a.Name = " " },
|
||||
"control_name": func(a *DNSAccount) { a.Name = "账户\n名称" },
|
||||
"long_name": func(a *DNSAccount) { a.Name = strings.Repeat("中", 129) },
|
||||
"invalid_provider": func(a *DNSAccount) { a.Provider = "other/provider" },
|
||||
"wrong_secret_type": func(a *DNSAccount) { a.CredentialRef = "secret://ssh/password" },
|
||||
"empty_secret_id": func(a *DNSAccount) { a.CredentialRef = "secret://dns/" },
|
||||
"secret_whitespace": func(a *DNSAccount) { a.CredentialRef += "\n" },
|
||||
"invalid_state": func(a *DNSAccount) { a.Status = "deleted" },
|
||||
"invalid_verification": func(a *DNSAccount) { a.VerificationState = "trusted" },
|
||||
"zero_revision": func(a *DNSAccount) { a.Revision = 0 },
|
||||
"overflow_revision": func(a *DNSAccount) { a.Revision = 2147483648 },
|
||||
} {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
item := base
|
||||
change(&item)
|
||||
if item.Validate() == nil {
|
||||
t.Fatal("无效账户未被拒绝")
|
||||
}
|
||||
})
|
||||
}
|
||||
payload, err := json.Marshal(base)
|
||||
if err != nil || strings.Contains(string(payload), "secret://") || strings.Contains(string(payload), "credential_ref") {
|
||||
t.Fatal("账户 JSON 暴露秘密引用", err)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user