From 3d63e3ec07bcf1ed624aa4a29dca659e226f5d70 Mon Sep 17 00:00:00 2001 From: Jared Ledvina Date: Tue, 26 May 2020 14:04:54 -0400 Subject: [PATCH] Ensure we return a location during account updates (#1158) --- acme/api/account.go | 9 +++++---- e2e/challenges_test.go | 6 +++--- registration/registar.go | 6 ++++-- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/acme/api/account.go b/acme/api/account.go index 04e7a6da..e7c19f1c 100644 --- a/acme/api/account.go +++ b/acme/api/account.go @@ -58,16 +58,17 @@ func (a *AccountService) Get(accountURL string) (acme.Account, error) { } // Update Updates an account. -func (a *AccountService) Update(accountURL string, req acme.Account) (acme.ExtendedAccount, error) { +func (a *AccountService) Update(accountURL string, req acme.Account) (acme.Account, error) { if len(accountURL) == 0 { - return acme.ExtendedAccount{}, errors.New("account[update]: empty URL") + return acme.Account{}, errors.New("account[update]: empty URL") } - var account acme.ExtendedAccount + var account acme.Account _, err := a.core.post(accountURL, req, &account) if err != nil { - return acme.ExtendedAccount{}, err + return acme.Account{}, err } + return account, nil } diff --git a/e2e/challenges_test.go b/e2e/challenges_test.go index 4c169067..e5237342 100644 --- a/e2e/challenges_test.go +++ b/e2e/challenges_test.go @@ -340,14 +340,14 @@ func TestRegistrar_UpdateAccount(t *testing.T) { regOptions := registration.RegisterOptions{TermsOfServiceAgreed: true} reg, err := client.Registration.Register(regOptions) require.NoError(t, err) - require.Equal(t, reg.Body.Contact, []string{"mailto:foo@example.com"}) + require.Equal(t, []string{"mailto:foo@example.com"}, reg.Body.Contact) user.registration = reg user.email = "bar@example.com" resource, err := client.Registration.UpdateRegistration(regOptions) require.NoError(t, err) - require.Equal(t, resource.Body.Contact, []string{"mailto:bar@example.com"}) - require.Empty(t, resource.URI) + require.Equal(t, []string{"mailto:bar@example.com"}, resource.Body.Contact) + require.Equal(t, reg.URI, resource.URI) } type fakeUser struct { diff --git a/registration/registar.go b/registration/registar.go index 4b612e50..67d5100f 100644 --- a/registration/registar.go +++ b/registration/registar.go @@ -131,12 +131,14 @@ func (r *Registrar) UpdateRegistration(options RegisterOptions) (*Resource, erro accMsg.Contact = []string{"mailto:" + r.user.GetEmail()} } - account, err := r.core.Accounts.Update(r.user.GetRegistration().URI, accMsg) + accountURL := r.user.GetRegistration().URI + + account, err := r.core.Accounts.Update(accountURL, accMsg) if err != nil { return nil, err } - return &Resource{URI: account.Location, Body: account.Account}, nil + return &Resource{URI: accountURL, Body: account}, nil } // DeleteRegistration deletes the client's user registration from the ACME server.