Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MM-61910] refactor: log users by email #873

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions api/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -494,15 +494,13 @@ func getUserCredentials(usersFilePath string, _ *loadtest.Config) ([]user, error
password := split[1]
// Quick and dirty hack to extract username from email.
// This is not terribly important to be correct.
username := strings.Split(email, "@")[0]
username = strings.Replace(username, "+", "-", -1)
authService := userentity.AuthenticationTypeMattermost

// Check if the user has a custom authentication type. Custom authentication types are
// specified by prepending the email with the authentication type followed by a colon.
// Example: "openid:[email protected]"
if strings.Contains(username, ":") {
split := strings.Split(username, ":")
if strings.Contains(email, ":") {
split := strings.Split(email, ":")
if len(split) != 2 {
return nil, fmt.Errorf("invalid custom authentication found in %q", email)
}
Expand All @@ -515,10 +513,16 @@ func getUserCredentials(usersFilePath string, _ *loadtest.Config) ([]user, error
return nil, fmt.Errorf("invalid custom authentication type %q", authService)
}

username = split[1]
email = strings.Replace(email, authService+":", "", 1)
}

emailParts := strings.Split(email, "@")
if len(emailParts) != 2 {
return nil, fmt.Errorf("invalid email %q", email)
}

username := emailParts[0]

users = append(users, user{
email: email,
username: username,
Expand Down
8 changes: 4 additions & 4 deletions loadtest/user/userentity/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ func (ue *UserEntity) SignUp(email, username, password string) error {
return fmt.Errorf("error while signing up using %s: %w", ue.config.AuthenticationType, err)
}

newUser, _, err = ue.client.GetUserByUsername(context.Background(), username, "")
newUser, _, err = ue.client.GetUserByEmail(context.Background(), email, "")
if err != nil {
return fmt.Errorf("error while getting user by username: %w", err)
return fmt.Errorf("error while getting user by email: %w", err)
}

default:
Expand Down Expand Up @@ -194,9 +194,9 @@ func (ue *UserEntity) Login() error {
return fmt.Errorf("error while logging in using %s: %w", ue.config.AuthenticationType, err)
}

loggedUser, _, err = ue.client.GetUserByUsername(context.Background(), user.Username, "")
loggedUser, _, err = ue.client.GetUserByEmail(context.Background(), user.Email, "")
if err != nil {
return fmt.Errorf("error while getting user by username through %s: %w", ue.config.AuthenticationType, err)
return fmt.Errorf("error while getting user by email through %s: %w", ue.config.AuthenticationType, err)
}
default:
loggedUser, _, err = ue.client.Login(context.Background(), user.Email, user.Password)
Expand Down
Loading