Files
neural-hunt/internal/customer/security_registration_test.go
jbergner 74d6b2f7d2
Some checks failed
release-tag / release-image (push) Failing after 2m11s
RC-10
2026-08-11 22:08:00 +02:00

43 lines
1.1 KiB
Go

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")
}
}