feat(identity): confirm the email address with a six-digit code from the message
This commit is contained in:
1 parent
c94434cd09
commit
d365a05c96
87 files changed
+4764
-224
No files matched your search
@@ -143,3 +143,41 @@ func TestResultHistoryCursorKeyIsSeparateFromIdempotencyAndBoundToTheCandidate(t
|
||||
t.Fatal("the cursor signature shares a key with the idempotency scope")
|
||||
}
|
||||
}
|
||||
|
||||
func TestVerificationCodeDigestIsKeyedAndPurposeSeparated(t *testing.T) {
|
||||
keyring, err := NewKeyring([]byte("keyring test secret with enough entropy"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
other, err := NewKeyring([]byte("another keyring secret with enough entropy"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
code, err := domain.ParseVerificationCode("482915")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
digest := keyring.VerificationCodeDigest(code)
|
||||
if digest != keyring.VerificationCodeDigest(code) {
|
||||
t.Fatal("the same code gives different digests under one key")
|
||||
}
|
||||
if digest == other.VerificationCodeDigest(code) {
|
||||
t.Fatal("two server secrets give the same digest for one code")
|
||||
}
|
||||
if digest == domain.VerificationCodeHash(sha256.Sum256([]byte("482915"))) {
|
||||
t.Fatal("the stored digest is an unkeyed SHA-256 of the code")
|
||||
}
|
||||
if !keyring.VerifyVerificationCode(code, digest) {
|
||||
t.Fatal("VerifyVerificationCode() rejected the matching code")
|
||||
}
|
||||
wrong, err := domain.ParseVerificationCode("482916")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if keyring.VerifyVerificationCode(wrong, digest) {
|
||||
t.Fatal("VerifyVerificationCode() accepted a wrong code")
|
||||
}
|
||||
if keyring.VerifyVerificationCode(domain.VerificationCode{}, digest) || keyring.VerifyVerificationCode(code, domain.VerificationCodeHash{}) {
|
||||
t.Fatal("VerifyVerificationCode() accepted a missing code or digest")
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user