2021-05-04 22:06:05 +00:00
|
|
|
package oidc
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestShouldNotRaiseErrorOnEqualPasswordsPlainText(t *testing.T) {
|
2022-10-20 03:21:45 +00:00
|
|
|
hasher := AdaptiveHasher{}
|
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()
|
|
|
|
|
|
|
|
err := hasher.Compare(ctx, a, b)
|
|
|
|
|
|
|
|
assert.NoError(t, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestShouldRaiseErrorOnNonEqualPasswordsPlainText(t *testing.T) {
|
2022-10-20 03:21:45 +00:00
|
|
|
hasher := AdaptiveHasher{}
|
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()
|
|
|
|
|
|
|
|
err := hasher.Compare(ctx, a, b)
|
|
|
|
|
|
|
|
assert.Equal(t, errPasswordsDoNotMatch, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestShouldHashPassword(t *testing.T) {
|
2022-10-20 03:21:45 +00:00
|
|
|
hasher := AdaptiveHasher{}
|
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)
|
|
|
|
}
|