Files
pgbackweb/internal/util/cryptoutil/bcrypt_test.go
Luis Eduardo Jeréz Girón a712669578 Rename bcrypt utilities
2024-07-20 17:31:56 -06:00

40 lines
827 B
Go

package cryptoutil
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestCreateBcryptHash(t *testing.T) {
password := "mysecretpassword"
hash, err := CreateBcryptHash(password)
assert.NoError(t, err)
assert.NotEmpty(t, hash)
}
func TestVerifyBcryptHash(t *testing.T) {
password := "mysecretpassword"
hash, err := CreateBcryptHash(password)
assert.NoError(t, err)
assert.NotEmpty(t, hash)
err = VerifyBcryptHash(password, hash)
assert.NoError(t, err)
}
func TestVerifyBcryptHash_InvalidPassword(t *testing.T) {
password := "mysecretpassword"
invalidPassword := "invalidpassword"
hash, err := CreateBcryptHash(password)
assert.NoError(t, err)
assert.NotEmpty(t, hash)
err = VerifyBcryptHash(invalidPassword, hash)
assert.Error(t, err)
assert.Equal(t, "invalid password", err.Error())
}