-
-
Notifications
You must be signed in to change notification settings - Fork 607
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add missing ModelToPb; add initial tests for contact
- Loading branch information
Showing
2 changed files
with
74 additions
and
2 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -3,6 +3,8 @@ package sa | |
import ( | ||
"bytes" | ||
"context" | ||
"crypto/ecdsa" | ||
"crypto/elliptic" | ||
"crypto/rand" | ||
"crypto/rsa" | ||
"crypto/sha256" | ||
|
@@ -4858,3 +4860,65 @@ func TestGetPausedIdentifiersOnlyUnpausesOneAccount(t *testing.T) { | |
test.AssertEquals(t, len(identifiers.Identifiers), 1) | ||
test.AssertEquals(t, identifiers.Identifiers[0].Value, "example.net") | ||
} | ||
|
||
func newAcctKey(t *testing.T) []byte { | ||
key, _ := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) | ||
jwk := &jose.JSONWebKey{Key: key.Public()} | ||
acctKey, err := jwk.MarshalJSON() | ||
test.AssertNotError(t, err, "failed to marshal account key") | ||
return acctKey | ||
} | ||
|
||
func TestUpdateRegistrationContact(t *testing.T) { | ||
sa, _, cleanUp := initSA(t) | ||
defer cleanUp() | ||
|
||
noContact, _ := json.Marshal("") | ||
exampleContact, _ := json.Marshal("[email protected]") | ||
|
||
tests := []struct { | ||
name string | ||
oldContactsJSON []string | ||
newContacts []string | ||
expectedError error | ||
}{ | ||
{ | ||
name: "update a valid registration from no contacts to one email address", | ||
oldContactsJSON: []string{string(noContact)}, | ||
newContacts: []string{"mailto:[email protected]"}, | ||
expectedError: nil, | ||
}, | ||
{ | ||
name: "update a valid registration from no contacts to two email addresses", | ||
oldContactsJSON: []string{string(noContact)}, | ||
newContacts: []string{"mailto:[email protected]", "mailto:[email protected]"}, | ||
expectedError: nil, | ||
}, | ||
{ | ||
name: "update a valid registration from one email address to no contacts", | ||
oldContactsJSON: []string{string(exampleContact)}, | ||
newContacts: []string{}, | ||
expectedError: nil, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
initialIP, _ := net.ParseIP("43.34.43.34").MarshalText() | ||
|
||
reg, err := sa.NewRegistration(ctx, &corepb.Registration{ | ||
Contact: tt.oldContactsJSON, | ||
Key: newAcctKey(t), | ||
InitialIP: initialIP, | ||
}) | ||
test.AssertNotError(t, err, "creating new registration") | ||
|
||
reg, err = sa.UpdateRegistrationContact(ctx, &sapb.UpdateRegistrationContactRequest{ | ||
RegistrationID: reg.Id, | ||
Contacts: tt.newContacts, | ||
}) | ||
test.AssertNotError(t, err, "Unexpected error for UpdateRegistrationContact()") | ||
|
||
test.AssertDeepEquals(t, reg.Contact, tt.newContacts) | ||
}) | ||
} | ||
} |