From c34b30a6e7fb707ae12e78a51e5bd776e5ca85ed Mon Sep 17 00:00:00 2001 From: Harrison Healey Date: Wed, 1 Aug 2018 15:18:14 -0400 Subject: MM-11521/MM-11522 Fix being able to create users with invalid emails through API (#9199) * MM-11522 Fix being able to create users with invalid emails through API * Ensure store tests are using valid emails * Add missing license header * Remove invalid test case * Fix TestUpdateOAuthUserAttrs --- app/team_test.go | 25 +------------------------ app/user_test.go | 8 ++++---- 2 files changed, 5 insertions(+), 28 deletions(-) (limited to 'app') diff --git a/app/team_test.go b/app/team_test.go index 6a47da58b..429e07931 100644 --- a/app/team_test.go +++ b/app/team_test.go @@ -45,35 +45,12 @@ func TestCreateTeamWithUser(t *testing.T) { } if _, err := th.App.CreateTeamWithUser(team, th.BasicUser.Id); err != nil { - t.Log(err) - t.Fatal("Should create a new team with existing user") + t.Fatal("Should create a new team with existing user", err) } if _, err := th.App.CreateTeamWithUser(team, model.NewId()); err == nil { t.Fatal("Should not create a new team - user does not exist") } - - user := model.User{Email: strings.ToLower(model.NewId()) + "success+test", Nickname: "Darth Vader", Username: "vader" + model.NewId(), Password: "passwd1", AuthService: ""} - ruser, _ := th.App.CreateUser(&user) - - id = model.NewId() - team2 := &model.Team{ - DisplayName: "dn_" + id, - Name: "name" + id, - Email: "success2+" + id + "@simulator.amazonses.com", - Type: model.TEAM_OPEN, - } - - //Fail to create a team with user when user has set email without domain - if _, err := th.App.CreateTeamWithUser(team2, ruser.Id); err == nil { - t.Log(err.Message) - t.Fatal("Should not create a team with user when user has set email without domain") - } else { - if err.Id != "model.team.is_valid.email.app_error" { - t.Log(err) - t.Fatal("Invalid error message") - } - } } func TestUpdateTeam(t *testing.T) { diff --git a/app/user_test.go b/app/user_test.go index 959455121..92ff4d62a 100644 --- a/app/user_test.go +++ b/app/user_test.go @@ -250,7 +250,7 @@ func TestUpdateOAuthUserAttrs(t *testing.T) { func getUserFromDB(a *App, id string, t *testing.T) *model.User { if user, err := a.GetUser(id); err != nil { - t.Fatal("user is not found") + t.Fatal("user is not found", err) return nil } else { return user @@ -261,13 +261,13 @@ func getGitlabUserPayload(gitlabUser oauthgitlab.GitLabUser, t *testing.T) []byt var payload []byte var err error if payload, err = json.Marshal(gitlabUser); err != nil { - t.Fatal("Serialization of gitlab user to json failed") + t.Fatal("Serialization of gitlab user to json failed", err) } return payload } -func createGitlabUser(t *testing.T, a *App, email string, username string) (*model.User, oauthgitlab.GitLabUser) { +func createGitlabUser(t *testing.T, a *App, username string, email string) (*model.User, oauthgitlab.GitLabUser) { r := rand.New(rand.NewSource(time.Now().UnixNano())) gitlabUserObj := oauthgitlab.GitLabUser{Id: int64(r.Intn(1000)) + 1, Username: username, Login: "user1", Email: email, Name: "Test User"} gitlabUser := getGitlabUserPayload(gitlabUserObj, t) @@ -276,7 +276,7 @@ func createGitlabUser(t *testing.T, a *App, email string, username string) (*mod var err *model.AppError if user, err = a.CreateOAuthUser("gitlab", bytes.NewReader(gitlabUser), ""); err != nil { - t.Fatal("unable to create the user") + t.Fatal("unable to create the user", err) } return user, gitlabUserObj -- cgit v1.2.3-1-g7c22