2019-10-07 22:14:47 +08:00
|
|
|
// Copyright (c) Mainflux
|
2018-08-26 19:15:48 +08:00
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
2018-05-11 05:53:25 +08:00
|
|
|
package mocks
|
|
|
|
|
2019-11-20 21:43:41 +08:00
|
|
|
import (
|
2022-01-28 00:03:57 +08:00
|
|
|
"github.com/mainflux/mainflux/pkg/errors"
|
2019-11-20 21:43:41 +08:00
|
|
|
"github.com/mainflux/mainflux/users"
|
|
|
|
)
|
2018-05-11 05:53:25 +08:00
|
|
|
|
|
|
|
var _ users.Hasher = (*hasherMock)(nil)
|
|
|
|
|
|
|
|
type hasherMock struct{}
|
|
|
|
|
|
|
|
// NewHasher creates "no-op" hasher for test purposes. This implementation will
|
|
|
|
// return secrets without changing them.
|
|
|
|
func NewHasher() users.Hasher {
|
|
|
|
return &hasherMock{}
|
|
|
|
}
|
|
|
|
|
2020-03-30 21:22:18 +08:00
|
|
|
func (hm *hasherMock) Hash(pwd string) (string, error) {
|
2018-05-11 05:53:25 +08:00
|
|
|
if pwd == "" {
|
2022-01-28 00:03:57 +08:00
|
|
|
return "", errors.ErrMalformedEntity
|
2018-05-11 05:53:25 +08:00
|
|
|
}
|
|
|
|
return pwd, nil
|
|
|
|
}
|
|
|
|
|
2020-03-30 21:22:18 +08:00
|
|
|
func (hm *hasherMock) Compare(plain, hashed string) error {
|
2018-05-11 05:53:25 +08:00
|
|
|
if plain != hashed {
|
2022-02-02 00:33:23 +08:00
|
|
|
return errors.ErrAuthentication
|
2018-05-11 05:53:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|