From f05aa4c241fd8b43da9dc8cab8c8965e5b3c1b55 Mon Sep 17 00:00:00 2001 From: Ludovic Fernandez Date: Mon, 4 Feb 2019 22:54:54 +0100 Subject: [PATCH] fix: endpoint with path. (#781) --- providers/dns/httpreq/httpreq.go | 4 +++- providers/dns/httpreq/httpreq_test.go | 11 +++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/providers/dns/httpreq/httpreq.go b/providers/dns/httpreq/httpreq.go index f6a1fe0c..af1b73a7 100644 --- a/providers/dns/httpreq/httpreq.go +++ b/providers/dns/httpreq/httpreq.go @@ -10,6 +10,7 @@ import ( "net/http" "net/url" "os" + "path" "time" "github.com/xenolf/lego/challenge/dns01" @@ -158,7 +159,8 @@ func (d *DNSProvider) doPost(uri string, msg interface{}) error { return err } - endpoint, err := d.config.Endpoint.Parse(uri) + newURI := path.Join(d.config.Endpoint.EscapedPath(), uri) + endpoint, err := d.config.Endpoint.Parse(newURI) if err != nil { return err } diff --git a/providers/dns/httpreq/httpreq_test.go b/providers/dns/httpreq/httpreq_test.go index 7b64d297..4ca4103d 100644 --- a/providers/dns/httpreq/httpreq_test.go +++ b/providers/dns/httpreq/httpreq_test.go @@ -6,6 +6,7 @@ import ( "net/http" "net/http/httptest" "net/url" + "path" "testing" "github.com/stretchr/testify/require" @@ -104,6 +105,7 @@ func TestNewDNSProvider_Present(t *testing.T) { mode string username string password string + pathPrefix string handler http.HandlerFunc expectedError string }{ @@ -111,6 +113,11 @@ func TestNewDNSProvider_Present(t *testing.T) { desc: "success", handler: successHandler, }, + { + desc: "success with path prefix", + handler: successHandler, + pathPrefix: "/api/acme/", + }, { desc: "error", handler: http.NotFound, @@ -150,11 +157,11 @@ func TestNewDNSProvider_Present(t *testing.T) { t.Parallel() mux := http.NewServeMux() - mux.HandleFunc("/present", test.handler) + mux.HandleFunc(path.Join("/", test.pathPrefix, "present"), test.handler) server := httptest.NewServer(mux) config := NewDefaultConfig() - config.Endpoint = mustParse(server.URL) + config.Endpoint = mustParse(server.URL + test.pathPrefix) config.Mode = test.mode config.Username = test.username config.Password = test.password