-
-
Notifications
You must be signed in to change notification settings - Fork 608
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce separate UpdateRegistrationContact & UpdateRegistrationKey …
…methods in RA & SA (#7735) Introduce separate UpdateRegistrationContact & UpdateRegistrationKey methods in RA & SA Clear contact field during DeactivateRegistration Part of #7716 Part of #5554
- Loading branch information
Showing
10 changed files
with
1,540 additions
and
588 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -671,10 +671,21 @@ type NoUpdateSA struct { | |
sapb.StorageAuthorityClient | ||
} | ||
|
||
func (sa NoUpdateSA) UpdateRegistration(_ context.Context, _ *corepb.Registration, _ ...grpc.CallOption) (*emptypb.Empty, error) { | ||
// Deprecated: When this function is removed, the NoUpdateSA should be moved | ||
// down to join the other mocks and tests for UpdateRegistrationContact & Key, | ||
// where it's also used. | ||
func (sa *NoUpdateSA) UpdateRegistration(_ context.Context, _ *corepb.Registration, _ ...grpc.CallOption) (*emptypb.Empty, error) { | ||
return nil, fmt.Errorf("UpdateRegistration() is mocked to always error") | ||
} | ||
|
||
func (sa *NoUpdateSA) UpdateRegistrationContact(_ context.Context, _ *sapb.UpdateRegistrationContactRequest, _ ...grpc.CallOption) (*corepb.Registration, error) { | ||
return nil, fmt.Errorf("UpdateRegistrationContact() is mocked to always error") | ||
} | ||
|
||
func (sa *NoUpdateSA) UpdateRegistrationKey(_ context.Context, _ *sapb.UpdateRegistrationKeyRequest, _ ...grpc.CallOption) (*corepb.Registration, error) { | ||
return nil, fmt.Errorf("UpdateRegistrationKey() is mocked to always error") | ||
} | ||
|
||
func TestUpdateRegistrationSame(t *testing.T) { | ||
_, _, ra, _, cleanUp := initAuthorities(t) | ||
defer cleanUp() | ||
|
@@ -4483,3 +4494,136 @@ func TestGetAuthorization(t *testing.T) { | |
test.AssertNotError(t, err, "should not fail") | ||
test.AssertEquals(t, len(authz.Challenges), 0) | ||
} | ||
|
||
// mockSARecordingRegistration tests UpdateRegistrationContact and UpdateRegistrationKey. | ||
type mockSARecordingRegistration struct { | ||
sapb.StorageAuthorityClient | ||
providedRegistrationID int64 | ||
providedContacts []string | ||
providedJwk []byte | ||
} | ||
|
||
// UpdateRegistrationContact records the registration ID and updated contacts | ||
// (optional) provided. | ||
func (sa *mockSARecordingRegistration) UpdateRegistrationContact(ctx context.Context, req *sapb.UpdateRegistrationContactRequest, _ ...grpc.CallOption) (*corepb.Registration, error) { | ||
sa.providedRegistrationID = req.RegistrationID | ||
sa.providedContacts = req.Contacts | ||
|
||
return &corepb.Registration{ | ||
Id: req.RegistrationID, | ||
Contact: req.Contacts, | ||
}, nil | ||
} | ||
|
||
// UpdateRegistrationKey records the registration ID and updated key provided. | ||
func (sa *mockSARecordingRegistration) UpdateRegistrationKey(ctx context.Context, req *sapb.UpdateRegistrationKeyRequest, _ ...grpc.CallOption) (*corepb.Registration, error) { | ||
sa.providedRegistrationID = req.RegistrationID | ||
sa.providedJwk = req.Jwk | ||
|
||
return &corepb.Registration{ | ||
Id: req.RegistrationID, | ||
Key: req.Jwk, | ||
}, nil | ||
} | ||
|
||
// TestUpdateRegistrationContact tests that the RA's UpdateRegistrationContact | ||
// method correctly: requires a registration ID; validates the contact provided; | ||
// does not require a contact; passes the requested registration ID and contact | ||
// to the SA; passes the updated Registration back to the caller; and can return | ||
// an error. | ||
func TestUpdateRegistrationContact(t *testing.T) { | ||
_, _, ra, _, cleanUp := initAuthorities(t) | ||
defer cleanUp() | ||
|
||
expectRegID := int64(1) | ||
expectContacts := []string{"mailto:[email protected]"} | ||
mockSA := mockSARecordingRegistration{} | ||
ra.SA = &mockSA | ||
|
||
_, err := ra.UpdateRegistrationContact(context.Background(), &rapb.UpdateRegistrationContactRequest{}) | ||
test.AssertError(t, err, "should not have been able to update registration contact without a registration ID") | ||
test.AssertContains(t, err.Error(), "incomplete gRPC request message") | ||
|
||
_, err = ra.UpdateRegistrationContact(context.Background(), &rapb.UpdateRegistrationContactRequest{ | ||
RegistrationID: expectRegID, | ||
Contacts: []string{"tel:+44123"}, | ||
}) | ||
test.AssertError(t, err, "should not have been able to update registration contact to an invalid contact") | ||
test.AssertContains(t, err.Error(), "invalid contact") | ||
|
||
res, err := ra.UpdateRegistrationContact(context.Background(), &rapb.UpdateRegistrationContactRequest{ | ||
RegistrationID: expectRegID, | ||
}) | ||
test.AssertNotError(t, err, "should have been able to update registration with a blank contact") | ||
test.AssertEquals(t, res.Id, expectRegID) | ||
test.AssertEquals(t, mockSA.providedRegistrationID, expectRegID) | ||
test.AssertDeepEquals(t, res.Contact, []string(nil)) | ||
test.AssertDeepEquals(t, mockSA.providedContacts, []string(nil)) | ||
|
||
res, err = ra.UpdateRegistrationContact(context.Background(), &rapb.UpdateRegistrationContactRequest{ | ||
RegistrationID: expectRegID, | ||
Contacts: expectContacts, | ||
}) | ||
test.AssertNotError(t, err, "should have been able to update registration with a populated contact") | ||
test.AssertEquals(t, res.Id, expectRegID) | ||
test.AssertEquals(t, mockSA.providedRegistrationID, expectRegID) | ||
test.AssertDeepEquals(t, res.Contact, expectContacts) | ||
test.AssertDeepEquals(t, mockSA.providedContacts, expectContacts) | ||
|
||
// Switch to a mock SA that will always error if UpdateRegistrationContact() | ||
// is called. | ||
ra.SA = &NoUpdateSA{} | ||
_, err = ra.UpdateRegistrationContact(context.Background(), &rapb.UpdateRegistrationContactRequest{ | ||
RegistrationID: expectRegID, | ||
Contacts: expectContacts, | ||
}) | ||
test.AssertError(t, err, "should have received an error from the SA") | ||
test.AssertContains(t, err.Error(), "failed to update registration contact") | ||
test.AssertContains(t, err.Error(), "mocked to always error") | ||
} | ||
|
||
// TestUpdateRegistrationKey tests that the RA's UpdateRegistrationKey method | ||
// correctly requires a registration ID and key, passes them to the SA, and | ||
// passes the updated Registration back to the caller. | ||
func TestUpdateRegistrationKey(t *testing.T) { | ||
_, _, ra, _, cleanUp := initAuthorities(t) | ||
defer cleanUp() | ||
|
||
expectRegID := int64(1) | ||
expectJwk := AccountKeyJSONA | ||
mockSA := mockSARecordingRegistration{} | ||
ra.SA = &mockSA | ||
|
||
_, err := ra.UpdateRegistrationKey(context.Background(), &rapb.UpdateRegistrationKeyRequest{}) | ||
test.AssertError(t, err, "should not have been able to update registration key without a registration ID or key") | ||
test.AssertContains(t, err.Error(), "incomplete gRPC request message") | ||
|
||
_, err = ra.UpdateRegistrationKey(context.Background(), &rapb.UpdateRegistrationKeyRequest{RegistrationID: expectRegID}) | ||
test.AssertError(t, err, "should not have been able to update registration key without a key") | ||
test.AssertContains(t, err.Error(), "incomplete gRPC request message") | ||
|
||
_, err = ra.UpdateRegistrationKey(context.Background(), &rapb.UpdateRegistrationKeyRequest{Jwk: expectJwk}) | ||
test.AssertError(t, err, "should not have been able to update registration key without a registration ID") | ||
test.AssertContains(t, err.Error(), "incomplete gRPC request message") | ||
|
||
res, err := ra.UpdateRegistrationKey(context.Background(), &rapb.UpdateRegistrationKeyRequest{ | ||
RegistrationID: expectRegID, | ||
Jwk: expectJwk, | ||
}) | ||
test.AssertNotError(t, err, "should have been able to update registration key") | ||
test.AssertEquals(t, res.Id, expectRegID) | ||
test.AssertEquals(t, mockSA.providedRegistrationID, expectRegID) | ||
test.AssertDeepEquals(t, res.Key, expectJwk) | ||
test.AssertDeepEquals(t, mockSA.providedJwk, expectJwk) | ||
|
||
// Switch to a mock SA that will always error if UpdateRegistrationKey() is | ||
// called. | ||
ra.SA = &NoUpdateSA{} | ||
_, err = ra.UpdateRegistrationKey(context.Background(), &rapb.UpdateRegistrationKeyRequest{ | ||
RegistrationID: expectRegID, | ||
Jwk: expectJwk, | ||
}) | ||
test.AssertError(t, err, "should have received an error from the SA") | ||
test.AssertContains(t, err.Error(), "failed to update registration key") | ||
test.AssertContains(t, err.Error(), "mocked to always error") | ||
} |
Oops, something went wrong.