30 lines
729 B
Go
30 lines
729 B
Go
package auth_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/techxcar/backend/internal/auth"
|
|
)
|
|
|
|
func TestHashPassword_isNotPlaintext(t *testing.T) {
|
|
hash, err := auth.HashPassword("mysecret")
|
|
require.NoError(t, err)
|
|
assert.NotEqual(t, "mysecret", hash)
|
|
assert.NotEmpty(t, hash)
|
|
}
|
|
|
|
func TestVerifyPassword_correct(t *testing.T) {
|
|
hash, err := auth.HashPassword("correctpassword")
|
|
require.NoError(t, err)
|
|
assert.True(t, auth.VerifyPassword("correctpassword", hash))
|
|
}
|
|
|
|
func TestVerifyPassword_wrong(t *testing.T) {
|
|
hash, err := auth.HashPassword("correctpassword")
|
|
require.NoError(t, err)
|
|
assert.False(t, auth.VerifyPassword("wrongpassword", hash))
|
|
}
|