[MM-13891] Enable team domain restriction for AuthService users (#10209)

* Enable team domain restriction for AuthService users

* govet
This commit is contained in:
Daniel Schalla
2019-02-01 23:28:35 +01:00
committed by Carlos Tadeu Panato Junior
parent 46b05499cc
commit 145fa9a57b
2 changed files with 17 additions and 7 deletions

View File

@@ -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)
}

View File

@@ -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")
}
})