From 73725b643703de05d299078f7502de97fd0c78d8 Mon Sep 17 00:00:00 2001 From: Chris Marchesi Date: Fri, 6 Nov 2020 14:30:51 -0800 Subject: [PATCH] acme/api: use postAsGet instead of post for AccountService.Get (#1283) Co-authored-by: Fernandez Ludovic --- acme/api/account.go | 2 +- e2e/challenges_test.go | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/acme/api/account.go b/acme/api/account.go index 54ea8a74e7..79daa29d71 100644 --- a/acme/api/account.go +++ b/acme/api/account.go @@ -51,7 +51,7 @@ func (a *AccountService) Get(accountURL string) (acme.Account, error) { } var account acme.Account - _, err := a.core.post(accountURL, acme.Account{}, &account) + _, err := a.core.postAsGet(accountURL, &account) if err != nil { return acme.Account{}, err } diff --git a/e2e/challenges_test.go b/e2e/challenges_test.go index 96ff84372f..3d0c9fb662 100644 --- a/e2e/challenges_test.go +++ b/e2e/challenges_test.go @@ -236,6 +236,38 @@ func TestChallengeHTTP_Client_Obtain(t *testing.T) { assert.Empty(t, resource.CSR) } +func TestChallengeHTTP_Client_Registration_QueryRegistration(t *testing.T) { + err := os.Setenv("LEGO_CA_CERTIFICATES", "./fixtures/certs/pebble.minica.pem") + require.NoError(t, err) + defer func() { _ = os.Unsetenv("LEGO_CA_CERTIFICATES") }() + + privateKey, err := rsa.GenerateKey(rand.Reader, 2048) + require.NoError(t, err, "Could not generate test key") + + user := &fakeUser{privateKey: privateKey} + config := lego.NewConfig(user) + config.CADirURL = load.PebbleOptions.HealthCheckURL + + client, err := lego.NewClient(config) + require.NoError(t, err) + + err = client.Challenge.SetHTTP01Provider(http01.NewProviderServer("", "5002")) + require.NoError(t, err) + + reg, err := client.Registration.Register(registration.RegisterOptions{TermsOfServiceAgreed: true}) + require.NoError(t, err) + user.registration = reg + + resource, err := client.Registration.QueryRegistration() + require.NoError(t, err) + + require.NotNil(t, resource) + + assert.Equal(t, "valid", resource.Body.Status) + assert.Regexp(t, `https://localhost:14000/list-orderz/\d+`, resource.Body.Orders) + assert.Regexp(t, `https://localhost:14000/my-account/\d+`, resource.URI) +} + func TestChallengeTLS_Client_Obtain(t *testing.T) { err := os.Setenv("LEGO_CA_CERTIFICATES", "./fixtures/certs/pebble.minica.pem") require.NoError(t, err)