30 lines
680 B
Go
30 lines
680 B
Go
package security
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/FernandoJVideira/simple_bank/pkg/testutil"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestPassword(t *testing.T) {
|
|
password := testutil.RandomString(6)
|
|
|
|
hashedPassword, err := HashPassword(password)
|
|
require.NoError(t, err)
|
|
require.NotEmpty(t, hashedPassword)
|
|
|
|
err = CheckPassword(password, hashedPassword)
|
|
require.NoError(t, err)
|
|
|
|
wrongPassword := testutil.RandomString(6)
|
|
err = CheckPassword(wrongPassword, hashedPassword)
|
|
require.Error(t, err)
|
|
|
|
hashedPassword2, err := HashPassword(password)
|
|
require.NoError(t, err)
|
|
require.NotEmpty(t, hashedPassword2)
|
|
|
|
require.NotEqual(t, hashedPassword, hashedPassword2)
|
|
}
|