Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix error when deactivating an account #7899

Merged
merged 3 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions ra/ra.go
Original file line number Diff line number Diff line change
Expand Up @@ -2442,13 +2442,18 @@ func (ra *RegistrationAuthorityImpl) DeactivateRegistration(ctx context.Context,
if reg == nil || reg.Id == 0 {
return nil, errIncompleteGRPCRequest
}
// TODO(#5554): Remove this check: this is only enforcing that the WFE has
// told us the correct status. The SA will enforce that the current status is
// valid during its database update.
if reg.Status != string(core.StatusValid) {
return nil, berrors.MalformedError("only valid registrations can be deactivated")
}
_, err := ra.SA.DeactivateRegistration(ctx, &sapb.RegistrationID{Id: reg.Id})
if err != nil {
return nil, err
}

// TODO(#5554): Return the updated account object.
return &emptypb.Empty{}, nil
}

Expand Down
2 changes: 2 additions & 0 deletions sa/sa.go
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,8 @@ func (ssa *SQLStorageAuthority) DeactivateRegistration(ctx context.Context, req
if err != nil {
return nil, err
}

// TODO(#5554): Return the updated account object.
return &emptypb.Empty{}, nil
}

Expand Down
50 changes: 50 additions & 0 deletions test/integration/account_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
//go:build integration

package integration

import (
"crypto/ecdsa"
"crypto/elliptic"
"crypto/rand"
"testing"

"github.com/eggsampler/acme/v3"

"github.com/letsencrypt/boulder/core"
)

// TestAccountDeactivate tests that account deactivation works. It does not test
// that we reject requests for other account statuses, because eggsampler/acme
// wisely does not allow us to construct such malformed requests.
func TestAccountDeactivate(t *testing.T) {
t.Parallel()

c, err := acme.NewClient("http://boulder.service.consul:4001/directory")
if err != nil {
t.Fatalf("failed to connect to acme directory: %s", err)
}

acctKey, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
if err != nil {
t.Fatalf("failed to generate account key: %s", err)
}

account, err := c.NewAccount(acctKey, false, true, "mailto:[email protected]")
if err != nil {
t.Fatalf("failed to create initial account: %s", err)
}

got, err := c.DeactivateAccount(account)
if err != nil {
t.Errorf("unexpected error while deactivating account: %s", err)
}

if got.Status != string(core.StatusDeactivated) {
t.Errorf("account deactivation should have set status to %q, instead got %q", core.StatusDeactivated, got.Status)
}

// TODO(#5554): Check that the contacts have been cleared. We can't do this
// today because eggsampler/acme unmarshals the WFE's response into the same
// account object as it used to make the request, and a wholly missing
// contacts field doesn't overwrite whatever eggsampler was holding in memory.
}
7 changes: 6 additions & 1 deletion wfe2/wfe.go
Original file line number Diff line number Diff line change
Expand Up @@ -1465,12 +1465,17 @@ func (wfe *WebFrontEndImpl) updateAccount(
// their contacts, the deactivation will take place and return before an
// update would be performed. Deactivation deletes the contacts field.
if accountUpdateRequest.Status == core.StatusDeactivated {
_, err = wfe.ra.DeactivateRegistration(ctx, &corepb.Registration{Id: currAcct.ID, Status: string(core.StatusDeactivated)})
// TODO(#5554): Remove the need to pass Status here: we wouldn't have reached
// this point unless the requesting account was valid.
_, err = wfe.ra.DeactivateRegistration(ctx, &corepb.Registration{Id: currAcct.ID, Status: string(currAcct.Status)})
if err != nil {
return nil, web.ProblemDetailsForError(err, "Unable to deactivate account")
}

// TODO(#5554): Have DeactivateRegistration return the updated account
// object, so we don't have to modify it ourselves.
currAcct.Status = core.StatusDeactivated
currAcct.Contact = nil
return currAcct, nil
}

Expand Down
6 changes: 0 additions & 6 deletions wfe2/wfe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2756,9 +2756,6 @@ func TestDeactivateAccount(t *testing.T) {
"n": "yNWVhtYEKJR21y9xsHV-PD_bYwbXSeNuFal46xYxVfRL5mqha7vttvjB_vc7Xg2RvgCxHPCqoxgMPTzHrZT75LjCwIW2K_klBYN8oYvTwwmeSkAz6ut7ZxPv-nZaT5TJhGk0NT2kh_zSpdriEJ_3vW-mqxYbbBmpvHqsa1_zx9fSuHYctAZJWzxzUZXykbWMWQZpEiE0J4ajj51fInEzVn7VxV-mzfMyboQjujPh7aNJxAWSq4oQEJJDgWwSh9leyoJoPpONHxh5nEE5AjE01FkGICSxjpZsF-w8hOTI3XXohUdu29Se26k2B0PolDSuj0GIQU6-W9TdLXSjBb2SpQ",
"e": "AQAB"
},
"contact": [
"mailto:[email protected]"
],
"status": "deactivated"
}`)

Expand All @@ -2775,9 +2772,6 @@ func TestDeactivateAccount(t *testing.T) {
"n": "yNWVhtYEKJR21y9xsHV-PD_bYwbXSeNuFal46xYxVfRL5mqha7vttvjB_vc7Xg2RvgCxHPCqoxgMPTzHrZT75LjCwIW2K_klBYN8oYvTwwmeSkAz6ut7ZxPv-nZaT5TJhGk0NT2kh_zSpdriEJ_3vW-mqxYbbBmpvHqsa1_zx9fSuHYctAZJWzxzUZXykbWMWQZpEiE0J4ajj51fInEzVn7VxV-mzfMyboQjujPh7aNJxAWSq4oQEJJDgWwSh9leyoJoPpONHxh5nEE5AjE01FkGICSxjpZsF-w8hOTI3XXohUdu29Se26k2B0PolDSuj0GIQU6-W9TdLXSjBb2SpQ",
"e": "AQAB"
},
"contact": [
"mailto:[email protected]"
],
"status": "deactivated"
}`)

Expand Down
Loading