修复邮件协议整数边界并补充事务回滚回归

This commit is contained in:
xuans committed 2026-09-21 00:39:26 +08:00
1 parent 97b02b8776
commit 3e135e2b7b
10 files changed
+299 -45

No files matched your search

+36
View File
@@ -0,0 +1,36 @@
package config
import "testing"
func TestLegacyDatabasePortBoundaries(t *testing.T) {
for _, test := range []struct {
value string
want uint16
valid bool
}{
{value: "", want: 3306, valid: true},
{value: "1", want: 1, valid: true},
{value: "65535", want: 65535, valid: true},
{value: "0"},
{value: "-1"},
{value: "65536"},
{value: "18446744073709551616"},
{value: " 3306"},
} {
port, valid := parseLegacyDatabasePort(test.value, DefaultMySQLPort)
if port != test.want || valid != test.valid {
t.Fatalf("端口 %q 的解析结果错误:%d %t", test.value, port, valid)
}
}
for _, value := range []string{"0", "65536", "18446744073709551616"} {
if _, _, valid := parseLegacyMySQLDSN("smail:sample@tcp(db.example.test:" + value + ")/smail"); valid {
t.Fatal("MySQL 连接串接受了越界端口")
}
if _, _, valid := parseLegacyPostgreSQLDSN("postgres://smail:sample@db.example.test:" + value + "/smail"); valid {
t.Fatal("PostgreSQL 连接串接受了越界端口")
}
}
if _, valid := parseLegacyDatabasePort("", 0); valid {
t.Fatal("默认端口不能为零")
}
}