Support auto-hashing fields via hooks.

This commit is contained in:
mikestefanello 2025-04-12 16:19:18 -04:00
parent 56f8a619a5
commit 7ff1e3f9d2
6 changed files with 49 additions and 36 deletions

View file

@ -8,6 +8,7 @@ import (
"github.com/mikestefanello/pagoda/ent/passwordtoken"
"github.com/mikestefanello/pagoda/ent/user"
"golang.org/x/crypto/bcrypt"
"github.com/stretchr/testify/require"
@ -41,12 +42,12 @@ func TestAuthClient_Auth(t *testing.T) {
assertNoAuth()
}
func TestAuthClient_PasswordHashing(t *testing.T) {
func TestAuthClient_CheckPassword(t *testing.T) {
pw := "testcheckpassword"
hash, err := c.Auth.HashPassword(pw)
assert.NoError(t, err)
hash, err := bcrypt.GenerateFromPassword([]byte(pw), bcrypt.DefaultCost)
require.NoError(t, err)
assert.NotEqual(t, hash, pw)
err = c.Auth.CheckPassword(pw, hash)
err = c.Auth.CheckPassword(pw, string(hash))
assert.NoError(t, err)
}