2021-05-04 22:06:05 +00:00
|
|
|
package oidc
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2022-12-04 22:37:08 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
2021-05-04 22:06:05 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestShouldNotRaiseErrorOnEqualPasswordsPlainText(t *testing.T) {
|
2023-03-06 03:58:50 +00:00
|
|
|
hasher, err := NewHasher()
|
2022-12-04 22:37:08 +00:00
|
|
|
|
|
|
|
require.NoError(t, err)
|
2021-05-04 22:06:05 +00:00
|
|
|
|
2022-10-20 03:21:45 +00:00
|
|
|
a := []byte("$plaintext$abc")
|
2021-05-04 22:06:05 +00:00
|
|
|
b := []byte("abc")
|
|
|
|
|
|
|
|
ctx := context.Background()
|
|
|
|
|
2022-12-04 22:37:08 +00:00
|
|
|
assert.NoError(t, hasher.Compare(ctx, a, b))
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestShouldNotRaiseErrorOnEqualPasswordsPlainTextWithSeparator(t *testing.T) {
|
2023-03-06 03:58:50 +00:00
|
|
|
hasher, err := NewHasher()
|
2021-05-04 22:06:05 +00:00
|
|
|
|
2022-12-04 22:37:08 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
a := []byte("$plaintext$abc$123")
|
|
|
|
b := []byte("abc$123")
|
|
|
|
|
|
|
|
ctx := context.Background()
|
|
|
|
|
|
|
|
assert.NoError(t, hasher.Compare(ctx, a, b))
|
2021-05-04 22:06:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestShouldRaiseErrorOnNonEqualPasswordsPlainText(t *testing.T) {
|
2023-03-06 03:58:50 +00:00
|
|
|
hasher, err := NewHasher()
|
2022-12-04 22:37:08 +00:00
|
|
|
|
|
|
|
require.NoError(t, err)
|
2021-05-04 22:06:05 +00:00
|
|
|
|
2022-10-20 03:21:45 +00:00
|
|
|
a := []byte("$plaintext$abc")
|
2021-05-04 22:06:05 +00:00
|
|
|
b := []byte("abcd")
|
|
|
|
|
|
|
|
ctx := context.Background()
|
|
|
|
|
2022-12-04 22:37:08 +00:00
|
|
|
assert.Equal(t, errPasswordsDoNotMatch, hasher.Compare(ctx, a, b))
|
2021-05-04 22:06:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestShouldHashPassword(t *testing.T) {
|
2023-03-06 03:58:50 +00:00
|
|
|
hasher := Hasher{}
|
2021-05-04 22:06:05 +00:00
|
|
|
|
|
|
|
data := []byte("abc")
|
|
|
|
|
|
|
|
ctx := context.Background()
|
|
|
|
|
|
|
|
hash, err := hasher.Hash(ctx, data)
|
|
|
|
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, data, hash)
|
|
|
|
}
|