From 653744867cacc048f00089605d17383f8b205766 Mon Sep 17 00:00:00 2001 From: Glauber Ferreira Date: Tue, 15 Sep 2026 10:12:17 -0300 Subject: [PATCH] altera soa-edit-api para INCEPTION-INCREMENT --- internal/pdns/client.go | 6 +++--- internal/pdns/client_test.go | 10 +++++----- internal/server/server_test.go | 28 ++++++++++++++++++++++++++++ internal/server/templates/zone.html | 6 +++++- 4 files changed, 41 insertions(+), 9 deletions(-) diff --git a/internal/pdns/client.go b/internal/pdns/client.go index b18b9b0..009b9a5 100644 --- a/internal/pdns/client.go +++ b/internal/pdns/client.go @@ -13,7 +13,7 @@ import ( "time" ) -const soaEditAPIIncrease = "INCREASE" +const soaEditAPIInceptionIncrement = "INCEPTION-INCREMENT" type HTTPClient interface { Do(*http.Request) (*http.Response, error) @@ -97,7 +97,7 @@ func (c *Client) ListZones(ctx context.Context) ([]Zone, error) { } func (c *Client) CreateZone(ctx context.Context, zone Zone) (Zone, error) { - zone.SOAEditAPI = soaEditAPIIncrease + zone.SOAEditAPI = soaEditAPIInceptionIncrement var created Zone if err := c.do(ctx, http.MethodPost, c.path("/zones"), zone, &created); err != nil { return Zone{}, err @@ -139,7 +139,7 @@ func (c *Client) EnsureAllZonesSOAEditAPI(ctx context.Context) error { } func (c *Client) SetZoneSOAEditAPI(ctx context.Context, zoneID string) error { - body := Zone{SOAEditAPI: soaEditAPIIncrease} + body := Zone{SOAEditAPI: soaEditAPIInceptionIncrement} return c.do(ctx, http.MethodPut, c.path("/zones/"+url.PathEscape(zoneID)), body, nil) } diff --git a/internal/pdns/client_test.go b/internal/pdns/client_test.go index 8ca5043..fd1b00e 100644 --- a/internal/pdns/client_test.go +++ b/internal/pdns/client_test.go @@ -238,7 +238,7 @@ func TestCreateZonePostsZone(t *testing.T) { if payload.Name != "example.org." || payload.Kind != "Native" { t.Fatalf("unexpected payload: %#v", payload) } - if payload.SOAEditAPI != soaEditAPIIncrease { + if payload.SOAEditAPI != "INCEPTION-INCREMENT" { t.Fatalf("unexpected soa_edit_api: %q", payload.SOAEditAPI) } w.WriteHeader(http.StatusCreated) @@ -252,7 +252,7 @@ func TestCreateZonePostsZone(t *testing.T) { if err := json.NewDecoder(r.Body).Decode(&payload); err != nil { t.Fatalf("decode request: %v", err) } - if payload.SOAEditAPI != soaEditAPIIncrease { + if payload.SOAEditAPI != "INCEPTION-INCREMENT" { t.Fatalf("unexpected soa_edit_api: %q", payload.SOAEditAPI) } w.WriteHeader(http.StatusNoContent) @@ -285,7 +285,7 @@ func TestEnsureAllZonesSOAEditAPIUpdatesAllZones(t *testing.T) { t.Fatalf("unexpected path: %s", r.URL.Path) } _ = json.NewEncoder(w).Encode([]Zone{ - {ID: "already.example.org.", Name: "already.example.org.", SOAEditAPI: soaEditAPIIncrease}, + {ID: "already.example.org.", Name: "already.example.org.", SOAEditAPI: soaEditAPIInceptionIncrement}, {ID: "missing.example.org.", Name: "missing.example.org."}, {ID: "", Name: "fallback.example.org.", SOAEditAPI: "DEFAULT"}, }) @@ -294,7 +294,7 @@ func TestEnsureAllZonesSOAEditAPIUpdatesAllZones(t *testing.T) { if err := json.NewDecoder(r.Body).Decode(&payload); err != nil { t.Fatalf("decode request: %v", err) } - if payload.SOAEditAPI != soaEditAPIIncrease { + if payload.SOAEditAPI != "INCEPTION-INCREMENT" { t.Fatalf("unexpected soa_edit_api: %q", payload.SOAEditAPI) } updated = append(updated, strings.TrimPrefix(r.URL.Path, "/api/v1/servers/localhost/zones/")) @@ -331,7 +331,7 @@ func TestSetZoneSOAEditAPIUsesPUT(t *testing.T) { if err := json.NewDecoder(r.Body).Decode(&payload); err != nil { t.Fatalf("decode request: %v", err) } - if payload.SOAEditAPI != soaEditAPIIncrease { + if payload.SOAEditAPI != "INCEPTION-INCREMENT" { t.Fatalf("unexpected soa_edit_api: %q", payload.SOAEditAPI) } w.WriteHeader(http.StatusNoContent) diff --git a/internal/server/server_test.go b/internal/server/server_test.go index e8baf2b..4d92aea 100644 --- a/internal/server/server_test.go +++ b/internal/server/server_test.go @@ -151,6 +151,34 @@ func TestAuthCanBeDisabled(t *testing.T) { } } +func TestZoneRecordsPageShowsSOAEditAPI(t *testing.T) { + client := &fakeClient{zone: pdns.Zone{ + Name: "example.org.", + SOAEditAPI: "INCEPTION-INCREMENT", + RRSets: []pdns.RRSet{{ + Name: "example.org.", + Type: "SOA", + TTL: 3600, + }}, + }} + srv, err := New(Config{}, client, nil) + if err != nil { + t.Fatalf("New returned error: %v", err) + } + + req := httptest.NewRequest(http.MethodGet, "/zones/example.org.", nil) + rec := httptest.NewRecorder() + srv.routes().ServeHTTP(rec, req) + + if rec.Code != http.StatusOK { + t.Fatalf("unexpected status: %d", rec.Code) + } + body := rec.Body.String() + if !strings.Contains(body, "SOA-EDIT-API:") || !strings.Contains(body, "INCEPTION-INCREMENT") { + t.Fatalf("expected SOA-EDIT-API value in zone records page, got %q", body) + } +} + func TestServesEmbeddedTablerAssets(t *testing.T) { srv, err := New(Config{}, &fakeClient{}, nil) if err != nil { diff --git a/internal/server/templates/zone.html b/internal/server/templates/zone.html index fe8bbbf..f6956a4 100644 --- a/internal/server/templates/zone.html +++ b/internal/server/templates/zone.html @@ -4,7 +4,11 @@
Zona

{{ .Zone.Name }}

-
{{ len .Zone.RRSets }} conjuntos de registros
+
+ {{ len .Zone.RRSets }} conjuntos de registros + · + SOA-EDIT-API: {{ .Zone.SOAEditAPI }} +