package auth import ( "testing" ) func TestHashAndVerify(t *testing.T) { hash, err := HashPassword("correct-horse-battery-staple") if err != nil { t.Fatalf("HashPassword: %v", err) } if hash == "" { t.Fatal("expected non-empty hash") } ok, err := VerifyPassword("correct-horse-battery-staple", hash) if err != nil { t.Fatalf("VerifyPassword: %v", err) } if !ok { t.Error("expected password to match") } ok, err = VerifyPassword("wrong-password", hash) if err != nil { t.Fatalf("VerifyPassword wrong: %v", err) } if ok { t.Error("expected wrong password to not match") } } func TestHashUniqueness(t *testing.T) { h1, _ := HashPassword("same-password") h2, _ := HashPassword("same-password") if h1 == h2 { t.Error("two hashes of the same password should differ (different salts)") } }