From 6c932297e16070bd20e9384ea78e8afabaa3fae2 Mon Sep 17 00:00:00 2001 From: Alex Vaghin Date: Fri, 12 Aug 2016 17:09:37 +0200 Subject: [PATCH] acme: preserve account URI on get and update Let's Encrypt has always provided Account URI in a response to any registration request (new, get and update) in the Location header, up until recently (?). Today, LE's servers provide Account URI only for new-reg requests. In fact, the spec does not say anything about Account URI and Location header for "get" and "update" requests. This change preserves Account URI in return values for "get" and "update" requests, which is already provided by the caller anyway. Change-Id: I8b1112d7443935715e9184a511b5e30a27008e8c Reviewed-on: https://go-review.googlesource.com/26931 Reviewed-by: Brad Fitzpatrick --- acme/internal/acme/acme.go | 16 +++++++++++++--- acme/internal/acme/acme_test.go | 6 ++++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/acme/internal/acme/acme.go b/acme/internal/acme/acme.go index b6d7efb..effc0ec 100644 --- a/acme/internal/acme/acme.go +++ b/acme/internal/acme/acme.go @@ -229,14 +229,24 @@ func (c *Client) Register(a *Account, prompt func(tos string) bool) (*Account, e // GetReg retrieves an existing registration. // The url argument is an Account URI. func (c *Client) GetReg(url string) (*Account, error) { - a := &Account{URI: url} - return c.doReg(url, "reg", a) + a, err := c.doReg(url, "reg", nil) + if err != nil { + return nil, err + } + a.URI = url + return a, nil } // UpdateReg updates an existing registration. // It returns an updated account copy. The provided account is not modified. func (c *Client) UpdateReg(a *Account) (*Account, error) { - return c.doReg(a.URI, "reg", a) + uri := a.URI + a, err := c.doReg(uri, "reg", a) + if err != nil { + return nil, err + } + a.URI = uri + return a, nil } // Authorize performs the initial step in an authorization flow. diff --git a/acme/internal/acme/acme_test.go b/acme/internal/acme/acme_test.go index f8c1d53..3237b09 100644 --- a/acme/internal/acme/acme_test.go +++ b/acme/internal/acme/acme_test.go @@ -205,6 +205,9 @@ func TestUpdateReg(t *testing.T) { if a.CurrentTerms != terms { t.Errorf("a.CurrentTerms = %q; want %q", a.CurrentTerms, terms) } + if a.URI != ts.URL { + t.Errorf("a.URI = %q; want %q", a.URI, ts.URL) + } } func TestGetReg(t *testing.T) { @@ -266,6 +269,9 @@ func TestGetReg(t *testing.T) { if a.CurrentTerms != newTerms { t.Errorf("a.CurrentTerms = %q; want %q", a.CurrentTerms, newTerms) } + if a.URI != ts.URL { + t.Errorf("a.URI = %q; want %q", a.URI, ts.URL) + } } func TestAuthorize(t *testing.T) {