fix: empty forwards

This commit is contained in:
Fernandez Ludovic 2026-03-08 19:18:04 +01:00
commit 46a063993b
5 changed files with 82 additions and 5 deletions

View file

@ -128,7 +128,7 @@ func (d *DNSProvider) Present(domain, token, keyAuth string) error {
}
if validation.Report != nil && !validation.Report.IsValid {
return fmt.Errorf("eurodns: %w", validation.Report)
return fmt.Errorf("eurodns: validation report: %w", validation.Report)
}
err = d.client.SaveZone(ctx, authZone, zone)
@ -179,7 +179,7 @@ func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error {
}
if validation.Report != nil && !validation.Report.IsValid {
return fmt.Errorf("eurodns: %w", validation.Report)
return fmt.Errorf("eurodns: validation report: %w", validation.Report)
}
err = d.client.SaveZone(ctx, authZone, zone)

View file

@ -71,6 +71,14 @@ func (c *Client) GetZone(ctx context.Context, domain string) (*Zone, error) {
func (c *Client) SaveZone(ctx context.Context, domain string, zone *Zone) error {
endpoint := c.BaseURL.JoinPath(domain)
if len(zone.URLForwards) == 0 {
zone.URLForwards = make([]URLForward, 0)
}
if len(zone.MailForwards) == 0 {
zone.MailForwards = make([]MailForward, 0)
}
req, err := newJSONRequest(ctx, http.MethodPut, endpoint, zone)
if err != nil {
return err
@ -84,6 +92,14 @@ func (c *Client) SaveZone(ctx context.Context, domain string, zone *Zone) error
func (c *Client) ValidateZone(ctx context.Context, domain string, zone *Zone) (*Zone, error) {
endpoint := c.BaseURL.JoinPath(domain, "check")
if len(zone.URLForwards) == 0 {
zone.URLForwards = make([]URLForward, 0)
}
if len(zone.MailForwards) == 0 {
zone.MailForwards = make([]MailForward, 0)
}
req, err := newJSONRequest(ctx, http.MethodPost, endpoint, zone)
if err != nil {
return nil, err

View file

@ -80,6 +80,26 @@ func TestClient_SaveZone(t *testing.T) {
require.NoError(t, err)
}
func TestClient_SaveZone_emptyForwards(t *testing.T) {
client := mockBuilder().
Route("PUT /example.com",
servermock.Noop().
WithStatusCode(http.StatusNoContent),
servermock.CheckRequestJSONBodyFromFixture("zones_add_empty_forwards.json"),
).
Build(t)
record := Record{
Type: "TXT",
Host: "_acme-challenge",
RData: "ADw2sEd82DUgXcQ9hNBZThJs7zVJkR5v9JeSbAb9mZY",
TTL: 600,
}
err := client.SaveZone(context.Background(), "example.com", expectedZoneSlim(record))
require.NoError(t, err)
}
func TestClient_SaveZone_error(t *testing.T) {
client := mockBuilder().
Route("PUT /example.com",
@ -214,3 +234,19 @@ func expectedZone(records ...Record) *Zone {
},
}
}
func expectedZoneSlim(records ...Record) *Zone {
rs := []Record{{
Type: "A",
Host: "string",
RData: "string",
}}
rs = append(rs, records...)
return &Zone{
Name: "string",
DomainConnect: true,
Records: rs,
}
}

View file

@ -0,0 +1,25 @@
{
"name": "string",
"domainConnect": true,
"records": [
{
"type": "A",
"host": "string",
"rdata": "string",
"updated": null,
"locked": null,
"isDynDns": null
},
{
"type": "TXT",
"host": "_acme-challenge",
"ttl": 600,
"rdata": "ADw2sEd82DUgXcQ9hNBZThJs7zVJkR5v9JeSbAb9mZY",
"updated": null,
"locked": null,
"isDynDns": null
}
],
"urlForwards": [],
"mailForwards": []
}

View file

@ -27,9 +27,9 @@ type Error struct {
type Zone struct {
Name string `json:"name,omitempty"`
DomainConnect bool `json:"domainConnect,omitempty"`
Records []Record `json:"records,omitempty"`
URLForwards []URLForward `json:"urlForwards,omitempty"`
MailForwards []MailForward `json:"mailForwards,omitempty"`
Records []Record `json:"records"`
URLForwards []URLForward `json:"urlForwards"`
MailForwards []MailForward `json:"mailForwards"`
Report *Report `json:"report,omitempty"`
}