Skip to content

Commit

Permalink
[MM-61910] refactor: log users by email (#873)
Browse files Browse the repository at this point in the history
* refactor: log users by email

* chore: move comment to proper location

* chore: revert strings.Replace for the username
  • Loading branch information
fmartingr authored Jan 8, 2025
1 parent d96dece commit 49fb24a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
19 changes: 12 additions & 7 deletions api/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -492,17 +492,13 @@ func getUserCredentials(usersFilePath string, _ *loadtest.Config) ([]user, error
}
email := split[0]
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 +511,19 @@ 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)
}

// Quick and dirty hack to extract username from email.
// This is not terribly important to be correct.
username := emailParts[0]
username = strings.Replace(username, "+", "-", -1)

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

0 comments on commit 49fb24a

Please sign in to comment.