Skip to content

Commit

Permalink
Use IsAnyNilOrZero; improve comment; more SA test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
jprenken committed Oct 11, 2024
1 parent f3eae28 commit 77a6b6c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
4 changes: 2 additions & 2 deletions ra/ra.go
Original file line number Diff line number Diff line change
Expand Up @@ -1757,7 +1757,7 @@ func (ra *RegistrationAuthorityImpl) UpdateRegistration(ctx context.Context, req

// UpdateRegistrationContact updates an existing Registration's contact.
func (ra *RegistrationAuthorityImpl) UpdateRegistrationContact(ctx context.Context, req *rapb.UpdateRegistrationContactRequest) (*corepb.Registration, error) {
if req == nil || req.RegistrationID == 0 {
if core.IsAnyNilOrZero(req.RegistrationID) {
return nil, errIncompleteGRPCRequest
}

Expand All @@ -1780,7 +1780,7 @@ func (ra *RegistrationAuthorityImpl) UpdateRegistrationContact(ctx context.Conte

// UpdateRegistrationKey updates an existing Registration's key.
func (ra *RegistrationAuthorityImpl) UpdateRegistrationKey(ctx context.Context, req *rapb.UpdateRegistrationKeyRequest) (*corepb.Registration, error) {
if req == nil || req.RegistrationID == 0 || len(req.Jwk) == 0 {
if core.IsAnyNilOrZero(req.RegistrationID, req.Jwk) {
return nil, errIncompleteGRPCRequest
}

Expand Down
8 changes: 4 additions & 4 deletions sa/sa.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ func (ssa *SQLStorageAuthority) UpdateRegistration(ctx context.Context, req *cor

// UpdateRegistrationContact stores an updated contact in a Registration
func (ssa *SQLStorageAuthority) UpdateRegistrationContact(ctx context.Context, req *sapb.UpdateRegistrationContactRequest) (*corepb.Registration, error) {
if req == nil || req.RegistrationID == 0 {
if core.IsAnyNilOrZero(req.RegistrationID) {
return nil, errIncompleteRequest
}

Expand Down Expand Up @@ -217,15 +217,15 @@ func (ssa *SQLStorageAuthority) UpdateRegistrationContact(ctx context.Context, r

updatedRegistration, ok := result.(*corepb.Registration)
if !ok {
return nil, fmt.Errorf("casting error in UpdateRegistrationContact")
return nil, fmt.Errorf("failed to assert result as *corepb.Registration in UpdateRegistrationContact")
}

return updatedRegistration, nil
}

// UpdateRegistrationKey stores an updated key in a Registration
func (ssa *SQLStorageAuthority) UpdateRegistrationKey(ctx context.Context, req *sapb.UpdateRegistrationKeyRequest) (*corepb.Registration, error) {
if req == nil || req.RegistrationID == 0 || len(req.Jwk) == 0 {
if core.IsAnyNilOrZero(req.RegistrationID, req.Jwk) {
return nil, errIncompleteRequest
}

Expand Down Expand Up @@ -282,7 +282,7 @@ func (ssa *SQLStorageAuthority) UpdateRegistrationKey(ctx context.Context, req *

updatedRegistration, ok := result.(*corepb.Registration)
if !ok {
return nil, fmt.Errorf("casting error in UpdateRegistrationKey")
return nil, fmt.Errorf("failed to assert result as *corepb.Registration in UpdateRegistrationKey")
}

return updatedRegistration, nil
Expand Down
13 changes: 13 additions & 0 deletions sa/sa_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4875,6 +4875,7 @@ func TestUpdateRegistrationContact(t *testing.T) {

noContact, _ := json.Marshal("")
exampleContact, _ := json.Marshal("test@example.com")
twoExampleContacts, _ := json.Marshal([]string{"test1@example.com", "test2@example.com"})

tests := []struct {
name string
Expand All @@ -4900,6 +4901,18 @@ func TestUpdateRegistrationContact(t *testing.T) {
newContacts: []string{},
expectedError: nil,
},
{
name: "update a valid registration from one email address to two email addresses",
oldContactsJSON: []string{string(exampleContact)},
newContacts: []string{"mailto:test1@example.com", "mailto:test2@example.com"},
expectedError: nil,
},
{
name: "update a valid registration from two email addresses to no contacts",
oldContactsJSON: []string{string(twoExampleContacts)},
newContacts: []string{},
expectedError: nil,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down

0 comments on commit 77a6b6c

Please sign in to comment.