ci / test (pull_request) Successful in 1m14s
The records come from the server and follow its own hostname, so after a rename the saved dns.zone keeps the old names, and so does --refresh until the server's hostname is changed in the console. Rewriting the file on a converge wouldn't help: the server still has the old name then. dns now checks whether the records name the install's mail host anywhere (MX, a service record's target, SPF; an MX at a relay is fine because the service records still name the server). If not, the saved copy says it predates the rename and how to refresh it, and a live read says the server still calls itself something else and where to change it.
42 lines
1.5 KiB
Go
42 lines
1.5 KiB
Go
// SPDX-FileCopyrightText: 2026 Coffey Labs LLC
|
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
package apply
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
const savedZone = `example.com. 3600 IN MX 10 mail.example.com.
|
|
_imaps._tcp.example.com. 3600 IN SRV 0 1 993 mail.example.com.
|
|
example.com. 3600 IN TXT "v=spf1 a:mail.example.com -all"
|
|
_dmarc.example.com. 3600 IN TXT "v=DMARC1; p=reject; rua=mailto:[email protected]"
|
|
`
|
|
|
|
// #83: a zone saved before a rename doesn't name the new mail host.
|
|
func TestZoneNamesHost(t *testing.T) {
|
|
if !ZoneNamesHost(savedZone, "mail.example.com") || !ZoneNamesHost(savedZone, "MAIL.example.com.") {
|
|
t.Fatal("the zone names its own mail host")
|
|
}
|
|
if ZoneNamesHost(savedZone, "mail.example.net") {
|
|
t.Fatal("a renamed mail host isn't in the old zone")
|
|
}
|
|
// A name that only contains the host, or is contained in it, doesn't count.
|
|
if ZoneNamesHost(savedZone, "example") || ZoneNamesHost(savedZone, "ail.example.com") {
|
|
t.Fatal("matched part of a name")
|
|
}
|
|
// An MX at a relay still names the server in its service records.
|
|
relayed := strings.Replace(savedZone, "MX 10 mail.example.com.", "MX 10 edge.example.org.", 1)
|
|
if !ZoneNamesHost(relayed, "mail.example.com") {
|
|
t.Fatal("MX at a relay was taken for a stale zone")
|
|
}
|
|
// SPF alone counts too (a:host).
|
|
if !ZoneNamesHost(`example.com. IN TXT "v=spf1 a:mx.example.com -all"`, "mx.example.com") {
|
|
t.Fatal("SPF a: names the host")
|
|
}
|
|
if !ZoneNamesHost(savedZone, "") {
|
|
t.Fatal("no recorded mail host: nothing to compare")
|
|
}
|
|
}
|