zoneee: fix subdomains. (#1053)

This commit is contained in:
Joonas 2020-02-08 12:38:57 +02:00 committed by GitHub
parent 87e770cc02
commit aad2d9ad92
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 38 additions and 13 deletions

View file

@ -99,7 +99,12 @@ func (d *DNSProvider) Present(domain, token, keyAuth string) error {
Destination: value, 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 { if err != nil {
return fmt.Errorf("zoneee: %v", err) 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 { func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error {
_, value := dns01.GetRecord(domain, keyAuth) _, 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 { if err != nil {
return fmt.Errorf("zoneee: %v", err) 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) 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 fmt.Errorf("zoneee: %v", err)
} }
return nil 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
}

View file

@ -138,7 +138,8 @@ func TestNewDNSProviderConfig(t *testing.T) {
} }
func TestDNSProvider_Present(t *testing.T) { func TestDNSProvider_Present(t *testing.T) {
domain := "prefix.example.com" hostedZone := "example.com"
domain := "prefix." + hostedZone
testCases := []struct { testCases := []struct {
desc string desc string
@ -152,7 +153,10 @@ func TestDNSProvider_Present(t *testing.T) {
username: "bar", username: "bar",
apiKey: "foo", apiKey: "foo",
handlers: map[string]http.HandlerFunc{ 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", username: "nope",
apiKey: "foo", apiKey: "foo",
handlers: map[string]http.HandlerFunc{ handlers: map[string]http.HandlerFunc{
"/" + domain + "/txt": mockHandlerCreateRecord, "/" + hostedZone + "/txt": mockHandlerCreateRecord,
}, },
expectedError: "zoneee: status code=401: Unauthorized\n", expectedError: "zoneee: status code=401: Unauthorized\n",
}, },
@ -203,7 +207,8 @@ func TestDNSProvider_Present(t *testing.T) {
} }
func TestDNSProvider_Cleanup(t *testing.T) { func TestDNSProvider_Cleanup(t *testing.T) {
domain := "prefix.example.com" hostedZone := "example.com"
domain := "prefix." + hostedZone
testCases := []struct { testCases := []struct {
desc string desc string
@ -217,14 +222,14 @@ func TestDNSProvider_Cleanup(t *testing.T) {
username: "bar", username: "bar",
apiKey: "foo", apiKey: "foo",
handlers: map[string]http.HandlerFunc{ handlers: map[string]http.HandlerFunc{
"/" + domain + "/txt": mockHandlerGetRecords([]txtRecord{{ "/" + hostedZone + "/txt": mockHandlerGetRecords([]txtRecord{{
ID: "1234", ID: "1234",
Name: domain, Name: domain,
Destination: "LHDhK3oGRvkiefQnx7OOczTY5Tic_xZ6HcMOc_gmtoM", Destination: "LHDhK3oGRvkiefQnx7OOczTY5Tic_xZ6HcMOc_gmtoM",
Delete: true, Delete: true,
Modify: true, Modify: true,
}}), }}),
"/" + domain + "/txt/1234": mockHandlerDeleteRecord, "/" + hostedZone + "/txt/1234": mockHandlerDeleteRecord,
}, },
}, },
{ {
@ -232,8 +237,8 @@ func TestDNSProvider_Cleanup(t *testing.T) {
username: "bar", username: "bar",
apiKey: "foo", apiKey: "foo",
handlers: map[string]http.HandlerFunc{ handlers: map[string]http.HandlerFunc{
"/" + domain + "/txt": mockHandlerGetRecords([]txtRecord{}), "/" + hostedZone + "/txt": mockHandlerGetRecords([]txtRecord{}),
"/" + domain + "/txt/1234": mockHandlerDeleteRecord, "/" + hostedZone + "/txt/1234": mockHandlerDeleteRecord,
}, },
expectedError: "zoneee: txt record does not exist for LHDhK3oGRvkiefQnx7OOczTY5Tic_xZ6HcMOc_gmtoM", expectedError: "zoneee: txt record does not exist for LHDhK3oGRvkiefQnx7OOczTY5Tic_xZ6HcMOc_gmtoM",
}, },
@ -242,14 +247,14 @@ func TestDNSProvider_Cleanup(t *testing.T) {
username: "nope", username: "nope",
apiKey: "foo", apiKey: "foo",
handlers: map[string]http.HandlerFunc{ handlers: map[string]http.HandlerFunc{
"/" + domain + "/txt": mockHandlerGetRecords([]txtRecord{{ "/" + hostedZone + "/txt": mockHandlerGetRecords([]txtRecord{{
ID: "1234", ID: "1234",
Name: domain, Name: domain,
Destination: "LHDhK3oGRvkiefQnx7OOczTY5Tic_xZ6HcMOc_gmtoM", Destination: "LHDhK3oGRvkiefQnx7OOczTY5Tic_xZ6HcMOc_gmtoM",
Delete: true, Delete: true,
Modify: true, Modify: true,
}}), }}),
"/" + domain + "/txt/1234": mockHandlerDeleteRecord, "/" + hostedZone + "/txt/1234": mockHandlerDeleteRecord,
}, },
expectedError: "zoneee: status code=401: Unauthorized\n", expectedError: "zoneee: status code=401: Unauthorized\n",
}, },