Ticking update PTR alone did nothing: the web UI didn't send it, and the engine only acted when the name or address changed. Alone it now adds a missing PTR record (or enables it); for linked zones every linked view's reverse zone counts. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
54 lines
2.2 KiB
Go
54 lines
2.2 KiB
Go
package engine
|
|
|
|
import (
|
|
"slices"
|
|
"strings"
|
|
"testing"
|
|
|
|
"jarl/internal/model"
|
|
)
|
|
|
|
// Ticking "update PTR" on an unchanged address record adds its PTR when
|
|
// the reverse zone is there (it was created after the record).
|
|
func TestUpdatePTRAddsMissing(t *testing.T) {
|
|
env := newEnv(t)
|
|
env.submit(env.admin, NewRequest(OpSettingsUpdate, 0, SettingsInput{Nameservers: &[]string{"ns1.example.net."}}))
|
|
env.submit(env.admin, NewRequest(OpZoneCreate, 0, ZoneInput{Name: model.Ptr("example.com")}))
|
|
env.submit(env.admin, rec("example.com", "ldn", "A", "139.144.144.154"))
|
|
env.submit(env.admin, NewRequest(OpZoneCreate, 0, ZoneInput{Name: model.Ptr("139.144.144.154/32")}))
|
|
var id int64
|
|
for _, r := range env.state().Records {
|
|
if r.Name == "ldn.example.com." {
|
|
id = r.ID
|
|
}
|
|
}
|
|
env.submit(env.admin, NewRequest(OpRecordUpdate, id, RecordInput{PTR: true}))
|
|
got := env.records("154.144.144.139.in-addr.arpa.")
|
|
if !slices.ContainsFunc(got, func(s string) bool { return strings.Contains(s, "PTR ldn.example.com.") }) {
|
|
t.Errorf("reverse zone = %q", got)
|
|
}
|
|
}
|
|
|
|
// In linked zones the PTR goes to the reverse zone of whichever linked
|
|
// view has one.
|
|
func TestUpdatePTRLinked(t *testing.T) {
|
|
env := linkedEnv(t)
|
|
env.submit(env.admin, NewRequest(OpZoneCreate, 0, ZoneInput{Name: model.Ptr("example.com"), View: model.Ptr("external"), LinkWith: "internal"}))
|
|
env.submit(env.admin, recIn("internal", "ldn", "A", "139.144.144.154"))
|
|
env.submit(env.admin, NewRequest(OpZoneCreate, 0, ZoneInput{Name: model.Ptr("139.144.144.154/32"), View: model.Ptr("external")}))
|
|
res := env.submit(env.admin, NewRequest(OpRecordUpdate, env.recordID("internal", "ldn", "A"), RecordInput{PTR: true}))
|
|
st := env.state()
|
|
z := st.FindZone("154.144.144.139.in-addr.arpa.", st.ViewByName("external").ID)
|
|
ok := false
|
|
for _, r := range st.ZoneRecords(z.ID) {
|
|
ok = ok || r.Type == "PTR" && r.Data == "ldn.example.com."
|
|
}
|
|
if !ok {
|
|
t.Errorf("no PTR in external's reverse zone (warnings %q)", res.Warnings)
|
|
}
|
|
// Again: already there, nothing to do.
|
|
if e := env.submitErr(env.admin, NewRequest(OpRecordUpdate, env.recordID("internal", "ldn", "A"), RecordInput{PTR: true})); !strings.Contains(e.Message, "nothing to do") {
|
|
t.Errorf("second time: %v", e)
|
|
}
|
|
}
|