mirror of
https://github.com/eduardolat/pgbackweb.git
synced 2026-02-11 14:48:35 -06:00
40 lines
827 B
Go
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())
|
|
}
|