45 lines
1.3 KiB
Go
45 lines
1.3 KiB
Go
package inmemory
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
|
|
"src.dualinventive.com/go/authentication-service/internal/domain"
|
|
)
|
|
|
|
//ExistingCredentials are test credentials
|
|
var ExistingCredentials = &domain.User{ //nolint: gochecknoglobals
|
|
Name: "existingUser",
|
|
PasswordHash: "$2y$10$tZkK8QkTTokLPhyWj7jX9ue/AzeabNdNP1lJEYyxTuw/Tp3QzfRO.",
|
|
Email: "existingUser@existingDomain.com",
|
|
}
|
|
|
|
//CredentialsRepository is in memory mock for CredentialsRepository
|
|
type CredentialsRepository struct {
|
|
credentials map[string]*domain.User
|
|
}
|
|
|
|
//NewCredentialsRepository returns new instance of repository
|
|
func NewCredentialsRepository() (*CredentialsRepository, error) {
|
|
repo := &CredentialsRepository{
|
|
credentials: make(map[string]*domain.User),
|
|
}
|
|
repo.credentials[ExistingCredentials.Name] = ExistingCredentials
|
|
return repo, nil
|
|
}
|
|
|
|
//GetUserByUserName returns credentials for user, if exists
|
|
func (cr *CredentialsRepository) GetUserByUserName(userName string, companyCode string) (*domain.User, error) {
|
|
user, ok := cr.credentials[userName]
|
|
var err error
|
|
if !ok {
|
|
err = fmt.Errorf("CredentialsRepositoryMocked - user is not stored in repository")
|
|
}
|
|
return user, err
|
|
}
|
|
|
|
//SetPassword is not yet implemented or necessary
|
|
func (cr *CredentialsRepository) SetPassword(userName *domain.User, passwordHash []byte) error {
|
|
return errors.New("not implemented")
|
|
}
|