2019-10-07 08:14:47 -06:00
|
|
|
// Copyright (c) Mainflux
|
2018-08-26 13:15:48 +02:00
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
2018-05-10 23:53:25 +02:00
|
|
|
package mocks
|
|
|
|
|
2019-11-20 14:43:41 +01:00
|
|
|
import (
|
2022-01-27 17:03:57 +01:00
|
|
|
"github.com/mainflux/mainflux/pkg/errors"
|
2019-11-20 14:43:41 +01:00
|
|
|
"github.com/mainflux/mainflux/users"
|
|
|
|
)
|
2018-05-10 23:53:25 +02: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 15:22:18 +02:00
|
|
|
func (hm *hasherMock) Hash(pwd string) (string, error) {
|
2018-05-10 23:53:25 +02:00
|
|
|
if pwd == "" {
|
2022-01-27 17:03:57 +01:00
|
|
|
return "", errors.ErrMalformedEntity
|
2018-05-10 23:53:25 +02:00
|
|
|
}
|
|
|
|
return pwd, nil
|
|
|
|
}
|
|
|
|
|
2020-03-30 15:22:18 +02:00
|
|
|
func (hm *hasherMock) Compare(plain, hashed string) error {
|
2018-05-10 23:53:25 +02:00
|
|
|
if plain != hashed {
|
2022-02-01 17:33:23 +01:00
|
|
|
return errors.ErrAuthentication
|
2018-05-10 23:53:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|