Ensure we return a location during account updates (#1158)

This commit is contained in:
Jared Ledvina 2020-05-26 14:04:54 -04:00 committed by GitHub
parent 0714fcf679
commit 3d63e3ec07
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 9 deletions

View file

@ -58,16 +58,17 @@ func (a *AccountService) Get(accountURL string) (acme.Account, error) {
} }
// Update Updates an account. // 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 { 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) _, err := a.core.post(accountURL, req, &account)
if err != nil { if err != nil {
return acme.ExtendedAccount{}, err return acme.Account{}, err
} }
return account, nil return account, nil
} }

View file

@ -340,14 +340,14 @@ func TestRegistrar_UpdateAccount(t *testing.T) {
regOptions := registration.RegisterOptions{TermsOfServiceAgreed: true} regOptions := registration.RegisterOptions{TermsOfServiceAgreed: true}
reg, err := client.Registration.Register(regOptions) reg, err := client.Registration.Register(regOptions)
require.NoError(t, err) 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.registration = reg
user.email = "bar@example.com" user.email = "bar@example.com"
resource, err := client.Registration.UpdateRegistration(regOptions) resource, err := client.Registration.UpdateRegistration(regOptions)
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, resource.Body.Contact, []string{"mailto:bar@example.com"}) require.Equal(t, []string{"mailto:bar@example.com"}, resource.Body.Contact)
require.Empty(t, resource.URI) require.Equal(t, reg.URI, resource.URI)
} }
type fakeUser struct { type fakeUser struct {

View file

@ -131,12 +131,14 @@ func (r *Registrar) UpdateRegistration(options RegisterOptions) (*Resource, erro
accMsg.Contact = []string{"mailto:" + r.user.GetEmail()} 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 { if err != nil {
return nil, err 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. // DeleteRegistration deletes the client's user registration from the ACME server.