From 145fa9a57be41d8cc1340bddda15ae3839ec93cc Mon Sep 17 00:00:00 2001 From: Daniel Schalla Date: Fri, 1 Feb 2019 23:28:35 +0100 Subject: [PATCH] [MM-13891] Enable team domain restriction for AuthService users (#10209) * Enable team domain restriction for AuthService users * govet --- app/team.go | 5 ----- app/team_test.go | 19 +++++++++++++++++-- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/app/team.go b/app/team.go index dd9db99991..db1da88c36 100644 --- a/app/team.go +++ b/app/team.go @@ -89,11 +89,6 @@ func (a *App) isTeamEmailAddressAllowed(email string, allowedDomains string) boo func (a *App) isTeamEmailAllowed(user *model.User, team *model.Team) bool { email := strings.ToLower(user.Email) - - if len(user.AuthService) > 0 && len(*user.AuthData) > 0 { - return true - } - return a.isTeamEmailAddressAllowed(email, team.AllowedDomains) } diff --git a/app/team_test.go b/app/team_test.go index 7bdaf04e5e..15f0356b11 100644 --- a/app/team_test.go +++ b/app/team_test.go @@ -113,12 +113,27 @@ func TestAddUserToTeam(t *testing.T) { } user := model.User{Email: strings.ToLower(model.NewId()) + "test@invalid.com", Nickname: "Darth Vader", Username: "vader" + model.NewId(), Password: "passwd1", AuthService: ""} - ruser, _ := th.App.CreateUser(&user) + ruser, err := th.App.CreateUser(&user) + if err != nil { + t.Fatalf("Error creating user: %s", err) + } + defer th.App.PermanentDeleteUser(&user) + + if _, err = th.App.AddUserToTeam(th.BasicTeam.Id, ruser.Id, ""); err == nil || err.Where != "JoinUserToTeam" { + t.Log(err) + t.Fatal("Should not add restricted user") + } + + user = model.User{Email: strings.ToLower(model.NewId()) + "test@invalid.com", Nickname: "Darth Vader", Username: "vader" + model.NewId(), AuthService: "notnil", AuthData: model.NewString("notnil")} + ruser, err = th.App.CreateUser(&user) + if err != nil { + t.Fatalf("Error creating authservice user: %s", err) + } defer th.App.PermanentDeleteUser(&user) if _, err := th.App.AddUserToTeam(th.BasicTeam.Id, ruser.Id, ""); err == nil || err.Where != "JoinUserToTeam" { t.Log(err) - t.Fatal("Should not add restricted user") + t.Fatal("Should not add authservice user") } })