package customer import "testing" func TestRegistrationChallengeAndProof(t *testing.T) { secret := "0123456789abcdef0123456789abcdef" user := "Alice" challenge := RegistrationChallenge(secret, user, 60) if !VerifyRegistrationChallenge(secret, user, challenge) { t.Fatal("valid challenge rejected") } if VerifyRegistrationChallenge(secret, "Bob", challenge) { t.Fatal("challenge must be username-bound") } const bits = 12 var counter uint64 for ; counter < 1<<20; counter++ { if VerifyRegistrationProof(user, challenge, counter, bits) { break } } if counter == 1<<20 { t.Fatal("could not find proof") } if !VerifyRegistrationProof(user, challenge, counter, bits) { t.Fatal("valid proof rejected") } if VerifyRegistrationProof("Bob", challenge, counter, bits) { t.Fatal("proof must be username-bound") } } func TestInviteHashIsStableAndDoesNotExposeCode(t *testing.T) { code := "nhinvite_example-secret" h := HashInviteCode(code) if h == "" || h == code { t.Fatalf("unexpected invite hash %q", h) } if h != HashInviteCode(code) { t.Fatal("invite hash not stable") } }