为什么:normalize 会解析主机名,测试用 smtp.example.com;构建机没有外网 DNS 时 必红(run164 tests-go 3 个失败)。改成 localhost,并补一条 .invalid 保留域必须 判非法的断言,校验规则没有放宽。
This commit is contained in:
@@ -39,14 +39,20 @@ func TestNormalizeRefusesEnabledSettingsWithoutTransportAndBadRecipients(t *test
|
||||
if _, err := normalize(SettingsInput{Host: "", From: "", Recipients: nil, Enabled: true}); err != ErrInvalid {
|
||||
t.Fatalf("enabled without host/from/recipients must be invalid, got %v", err)
|
||||
}
|
||||
if _, err := normalize(SettingsInput{Host: "smtp.example.com", From: "kb@example.com", Recipients: []string{"not-an-address"}, Enabled: true}); err == nil {
|
||||
if _, err := normalize(SettingsInput{Host: "localhost", From: "kb@example.com", Recipients: []string{"not-an-address"}, Enabled: true}); err == nil {
|
||||
t.Fatal("a malformed recipient must be rejected")
|
||||
}
|
||||
good, err := normalize(SettingsInput{Host: "smtp.example.com", From: "kb@example.com", Recipients: []string{"a@example.com", "b@example.com"}, Enabled: true})
|
||||
// 校验会解析主机名;用 localhost 避免把构建机的 DNS 当成被测行为。
|
||||
good, err := normalize(SettingsInput{Host: "localhost", From: "kb@example.com", Recipients: []string{"a@example.com", "b@example.com"}, Enabled: true})
|
||||
if err != nil || good.Port != 465 || good.Weekday != 1 || len(good.Recipients) != 2 {
|
||||
t.Fatalf("defaults not applied: %+v %v", good, err)
|
||||
}
|
||||
duplicated := SettingsInput{Host: "smtp.example.com", From: "kb@example.com", Recipients: []string{"a@example.com", "A@example.com"}}
|
||||
// 解析不了的主机名必须仍被判为非法:.invalid 是 RFC 6761 保留域,永远不解析。
|
||||
if _, err := normalize(SettingsInput{Host: "smtp.kg-test.invalid", From: "kb@example.com",
|
||||
Recipients: []string{"a@example.com"}}); err != ErrInvalid {
|
||||
t.Fatalf("unresolvable host must stay invalid, got %v", err)
|
||||
}
|
||||
duplicated := SettingsInput{Host: "localhost", From: "kb@example.com", Recipients: []string{"a@example.com", "A@example.com"}}
|
||||
if _, err := normalize(duplicated); err != ErrInvalid {
|
||||
t.Fatal("case-insensitive duplicate recipients must be rejected")
|
||||
}
|
||||
@@ -94,11 +100,11 @@ func TestMailerRefusesPlaintextServersWithoutSTARTTLS(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestNormalizeRejectsACopyThatIsAlsoAPrimaryRecipient(t *testing.T) {
|
||||
_, err := normalize(SettingsInput{Host: "smtp.example.com", From: "kb@example.com", Recipients: []string{"a@example.com"}, Cc: []string{"A@example.com"}, Enabled: true})
|
||||
_, err := normalize(SettingsInput{Host: "localhost", From: "kb@example.com", Recipients: []string{"a@example.com"}, Cc: []string{"A@example.com"}, Enabled: true})
|
||||
if err != ErrInvalid {
|
||||
t.Fatal("a person in both To and Cc would receive the report twice")
|
||||
}
|
||||
good, err := normalize(SettingsInput{Host: "smtp.example.com", From: "kb@example.com", Recipients: []string{"a@example.com"}, Cc: []string{"b@example.com", "c@example.com"}, Enabled: true})
|
||||
good, err := normalize(SettingsInput{Host: "localhost", From: "kb@example.com", Recipients: []string{"a@example.com"}, Cc: []string{"b@example.com", "c@example.com"}, Enabled: true})
|
||||
if err != nil || len(good.Cc) != 2 {
|
||||
t.Fatalf("valid cc list rejected: %+v %v", good.Cc, err)
|
||||
}
|
||||
@@ -121,11 +127,11 @@ func TestBuildMIMEPlacesTheChartAfterTheBodyAsAnInlineImage(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestNormalizeAcceptsAnOptionalReviewAddressAndRejectsMalformedOnes(t *testing.T) {
|
||||
good, err := normalize(SettingsInput{Host: "smtp.example.com", From: "kb@example.com", Recipients: []string{"a@example.com"}, Review: "owner@example.com", Enabled: true})
|
||||
good, err := normalize(SettingsInput{Host: "localhost", From: "kb@example.com", Recipients: []string{"a@example.com"}, Review: "owner@example.com", Enabled: true})
|
||||
if err != nil || good.Review != "owner@example.com" {
|
||||
t.Fatalf("review address rejected: %q %v", good.Review, err)
|
||||
}
|
||||
if _, err := normalize(SettingsInput{Host: "smtp.example.com", From: "kb@example.com", Recipients: []string{"a@example.com"}, Review: "not-an-address"}); err != ErrInvalid {
|
||||
if _, err := normalize(SettingsInput{Host: "localhost", From: "kb@example.com", Recipients: []string{"a@example.com"}, Review: "not-an-address"}); err != ErrInvalid {
|
||||
t.Fatal("a malformed review address must be rejected")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user