diff --git a/providers/dns/zoneee/zoneee.go b/providers/dns/zoneee/zoneee.go index 7e3f8e2f..932b733c 100644 --- a/providers/dns/zoneee/zoneee.go +++ b/providers/dns/zoneee/zoneee.go @@ -99,7 +99,12 @@ func (d *DNSProvider) Present(domain, token, keyAuth string) error { Destination: value, } - _, err := d.addTxtRecord(domain, record) + authZone, err := getHostedZone(domain) + if err != nil { + return fmt.Errorf("zoneee: %v", err) + } + + _, err = d.addTxtRecord(authZone, record) if err != nil { return fmt.Errorf("zoneee: %v", err) } @@ -110,7 +115,12 @@ func (d *DNSProvider) Present(domain, token, keyAuth string) error { func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error { _, value := dns01.GetRecord(domain, keyAuth) - records, err := d.getTxtRecords(domain) + authZone, err := getHostedZone(domain) + if err != nil { + return fmt.Errorf("zoneee: %v", err) + } + + records, err := d.getTxtRecords(authZone) if err != nil { return fmt.Errorf("zoneee: %v", err) } @@ -126,9 +136,19 @@ func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error { return fmt.Errorf("zoneee: txt record does not exist for %v", value) } - if err = d.removeTxtRecord(domain, id); err != nil { + if err = d.removeTxtRecord(authZone, id); err != nil { return fmt.Errorf("zoneee: %v", err) } return nil } + +func getHostedZone(domain string) (string, error) { + authZone, err := dns01.FindZoneByFqdn(dns01.ToFqdn(domain)) + if err != nil { + return "", err + } + + zoneName := dns01.UnFqdn(authZone) + return zoneName, nil +} diff --git a/providers/dns/zoneee/zoneee_test.go b/providers/dns/zoneee/zoneee_test.go index fc17709b..3989f409 100644 --- a/providers/dns/zoneee/zoneee_test.go +++ b/providers/dns/zoneee/zoneee_test.go @@ -138,7 +138,8 @@ func TestNewDNSProviderConfig(t *testing.T) { } func TestDNSProvider_Present(t *testing.T) { - domain := "prefix.example.com" + hostedZone := "example.com" + domain := "prefix." + hostedZone testCases := []struct { desc string @@ -152,7 +153,10 @@ func TestDNSProvider_Present(t *testing.T) { username: "bar", apiKey: "foo", handlers: map[string]http.HandlerFunc{ - "/" + domain + "/txt": mockHandlerCreateRecord, + "/": http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) { + fmt.Println(req.URL) + }), + "/" + hostedZone + "/txt": mockHandlerCreateRecord, }, }, { @@ -160,7 +164,7 @@ func TestDNSProvider_Present(t *testing.T) { username: "nope", apiKey: "foo", handlers: map[string]http.HandlerFunc{ - "/" + domain + "/txt": mockHandlerCreateRecord, + "/" + hostedZone + "/txt": mockHandlerCreateRecord, }, expectedError: "zoneee: status code=401: Unauthorized\n", }, @@ -203,7 +207,8 @@ func TestDNSProvider_Present(t *testing.T) { } func TestDNSProvider_Cleanup(t *testing.T) { - domain := "prefix.example.com" + hostedZone := "example.com" + domain := "prefix." + hostedZone testCases := []struct { desc string @@ -217,14 +222,14 @@ func TestDNSProvider_Cleanup(t *testing.T) { username: "bar", apiKey: "foo", handlers: map[string]http.HandlerFunc{ - "/" + domain + "/txt": mockHandlerGetRecords([]txtRecord{{ + "/" + hostedZone + "/txt": mockHandlerGetRecords([]txtRecord{{ ID: "1234", Name: domain, Destination: "LHDhK3oGRvkiefQnx7OOczTY5Tic_xZ6HcMOc_gmtoM", Delete: true, Modify: true, }}), - "/" + domain + "/txt/1234": mockHandlerDeleteRecord, + "/" + hostedZone + "/txt/1234": mockHandlerDeleteRecord, }, }, { @@ -232,8 +237,8 @@ func TestDNSProvider_Cleanup(t *testing.T) { username: "bar", apiKey: "foo", handlers: map[string]http.HandlerFunc{ - "/" + domain + "/txt": mockHandlerGetRecords([]txtRecord{}), - "/" + domain + "/txt/1234": mockHandlerDeleteRecord, + "/" + hostedZone + "/txt": mockHandlerGetRecords([]txtRecord{}), + "/" + hostedZone + "/txt/1234": mockHandlerDeleteRecord, }, expectedError: "zoneee: txt record does not exist for LHDhK3oGRvkiefQnx7OOczTY5Tic_xZ6HcMOc_gmtoM", }, @@ -242,14 +247,14 @@ func TestDNSProvider_Cleanup(t *testing.T) { username: "nope", apiKey: "foo", handlers: map[string]http.HandlerFunc{ - "/" + domain + "/txt": mockHandlerGetRecords([]txtRecord{{ + "/" + hostedZone + "/txt": mockHandlerGetRecords([]txtRecord{{ ID: "1234", Name: domain, Destination: "LHDhK3oGRvkiefQnx7OOczTY5Tic_xZ6HcMOc_gmtoM", Delete: true, Modify: true, }}), - "/" + domain + "/txt/1234": mockHandlerDeleteRecord, + "/" + hostedZone + "/txt/1234": mockHandlerDeleteRecord, }, expectedError: "zoneee: status code=401: Unauthorized\n", },