From e85d9b990a0e617b3693c9bb453e47fdcfa1fa21 Mon Sep 17 00:00:00 2001 From: Virgil Date: Fri, 3 Apr 2026 21:37:34 +0000 Subject: [PATCH] Align resolve-all with RFC payload --- service.go | 10 ++++++++-- service_test.go | 20 ++++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/service.go b/service.go index 2a8a8f7..3d30013 100644 --- a/service.go +++ b/service.go @@ -530,7 +530,7 @@ func (service *Service) ResolveTXT(name string) ([]string, bool) { // ResolveTXTRecords returns TXT records wrapped with the RFC field name for action payloads. // -// service.ResolveTXTRecords("gateway.charon.lthn") +// result, ok := service.ResolveTXTRecords("gateway.charon.lthn") func (service *Service) ResolveTXTRecords(name string) (ResolveTXTResult, bool) { record, ok := service.findRecord(name) if !ok { @@ -614,6 +614,7 @@ func (service *Service) ResolveReverse(ip string) ([]string, bool) { } // ResolveAll returns the full record set for a name, including synthesized apex NS data. +// Missing names still return empty arrays so the action payload stays stable. // // result, ok := service.ResolveAll("charon.lthn") func (service *Service) ResolveAll(name string) (ResolveAllResult, bool) { @@ -624,7 +625,12 @@ func (service *Service) ResolveAll(name string) (ResolveAllResult, bool) { NS: []string{"ns." + service.ZoneApex()}, }, true } - return ResolveAllResult{}, false + return ResolveAllResult{ + A: []string{}, + AAAA: []string{}, + TXT: []string{}, + NS: []string{}, + }, true } result := resolveResult(record) if normalizeName(name) == service.ZoneApex() && service.ZoneApex() != "" && len(result.NS) == 0 { diff --git a/service_test.go b/service_test.go index 745b16d..ecd6f5a 100644 --- a/service_test.go +++ b/service_test.go @@ -1486,6 +1486,26 @@ func TestServiceResolveAllReturnsEmptyArraysForMissingRecordValues(t *testing.T) } } +func TestServiceResolveAllReturnsEmptyArraysForMissingName(t *testing.T) { + service := NewService(ServiceOptions{}) + + result, ok := service.ResolveAll("missing.charon.lthn") + if !ok { + t.Fatal("expected missing name to still return the array-shaped payload") + } + if len(result.A) != 0 || len(result.AAAA) != 0 || len(result.TXT) != 0 || len(result.NS) != 0 { + t.Fatalf("expected empty arrays for missing name, got %#v", result) + } + + raw, err := json.Marshal(result) + if err != nil { + t.Fatalf("expected result to marshal: %v", err) + } + if string(raw) != `{"a":[],"aaaa":[],"txt":[],"ns":[]}` { + t.Fatalf("expected empty arrays in JSON, got %s", raw) + } +} + func TestServiceServeReturnsNXDOMAINWhenMissing(t *testing.T) { service := NewService(ServiceOptions{}) -- 2.45.3