This commit is contained in:
parent
482c6b0f80
commit
d70ab71af0
@ -61,7 +61,7 @@ func buildDNSItemsWithWebIPv4(configData *config.Config, domain, dkimPublicKey,
|
||||
address = "[\u672a\u68c0\u6d4b\u5230\u516c\u7f51 IPv4]"
|
||||
}
|
||||
|
||||
items := make([]*DNSItem, 0, 10)
|
||||
items := make([]*DNSItem, 0, 13)
|
||||
appendARecord := func(host string) {
|
||||
for _, item := range items {
|
||||
if item.Type == "A" && item.Host == host {
|
||||
@ -76,6 +76,20 @@ func buildDNSItemsWithWebIPv4(configData *config.Config, domain, dkimPublicKey,
|
||||
Tips: ipTips,
|
||||
})
|
||||
}
|
||||
appendAAAARecord := func(host, address string) {
|
||||
for _, item := range items {
|
||||
if item.Type == "AAAA" && item.Host == host {
|
||||
return
|
||||
}
|
||||
}
|
||||
items = append(items, &DNSItem{
|
||||
Type: "AAAA",
|
||||
Host: host,
|
||||
Value: address,
|
||||
TTL: dnsRecordTTL,
|
||||
Tips: ipTips,
|
||||
})
|
||||
}
|
||||
|
||||
webHost := dnsHostForDomain(configData.WebDomain, domain)
|
||||
if webHost == "@" {
|
||||
@ -105,13 +119,10 @@ func buildDNSItemsWithWebIPv4(configData *config.Config, domain, dkimPublicKey,
|
||||
appendARecord("@")
|
||||
|
||||
if ipv6Address := buildSPFAddressMechanism(ipv6); strings.HasPrefix(ipv6Address, "ip6:") {
|
||||
items = append(items, &DNSItem{
|
||||
Type: "AAAA",
|
||||
Host: "@",
|
||||
Value: strings.TrimPrefix(ipv6Address, "ip6:"),
|
||||
TTL: dnsRecordTTL,
|
||||
Tips: ipTips,
|
||||
})
|
||||
address := strings.TrimPrefix(ipv6Address, "ip6:")
|
||||
for _, host := range []string{"@", "smtp", "imap", "pop"} {
|
||||
appendAAAARecord(host, address)
|
||||
}
|
||||
}
|
||||
|
||||
items = append(items,
|
||||
|
||||
@ -69,8 +69,8 @@ func TestBuildDNSItemsCreatesExpectedRecordShape(t *testing.T) {
|
||||
}
|
||||
items := buildDNSItemsWithWebIPv4(cfg, "example.com", "v=DKIM1; k=rsa; p=test", "198.51.100.20", "2001:db8::20", "", []string{"203.0.113.20"})
|
||||
|
||||
if len(items) != 10 {
|
||||
t.Fatalf("DNS item count = %d, want 10", len(items))
|
||||
if len(items) != 13 {
|
||||
t.Fatalf("DNS item count = %d, want 13", len(items))
|
||||
}
|
||||
if items[0].Host != "panel" || items[0].Type != "A" || items[0].Value != "203.0.113.20" {
|
||||
t.Fatalf("web A record = %#v", items[0])
|
||||
@ -81,8 +81,13 @@ func TestBuildDNSItemsCreatesExpectedRecordShape(t *testing.T) {
|
||||
if items[5].Type != "AAAA" || items[5].Host != "@" || items[5].Value != "2001:db8::20" {
|
||||
t.Fatalf("root AAAA record = %#v", items[5])
|
||||
}
|
||||
if items[6].Value != "smtp.example.com | 1" || items[6].TTL != dnsRecordTTL {
|
||||
t.Fatalf("MX record = %#v", items[6])
|
||||
for index, host := range map[int]string{6: "smtp", 7: "imap", 8: "pop"} {
|
||||
if items[index].Type != "AAAA" || items[index].Host != host || items[index].Value != "2001:db8::20" {
|
||||
t.Fatalf("mail service AAAA record = %#v", items[index])
|
||||
}
|
||||
}
|
||||
if items[9].Value != "smtp.example.com | 1" || items[9].TTL != dnsRecordTTL {
|
||||
t.Fatalf("MX record = %#v", items[9])
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user