MM-18081 Except bots from team email domain restrictions (#12041)

* Except bots from team email domain restrictions

* Fix style
This commit is contained in:
Joram Wilander
2019-09-06 10:55:55 -04:00
committed by GitHub
parent adb1a98760
commit 50e97bd9d3
2 changed files with 15 additions and 2 deletions

View File

@@ -89,6 +89,9 @@ func (a *App) isTeamEmailAddressAllowed(email string, allowedDomains string) boo
}
func (a *App) isTeamEmailAllowed(user *model.User, team *model.Team) bool {
if user.IsBot {
return true
}
email := strings.ToLower(user.Email)
return a.isTeamEmailAddressAllowed(email, team.AllowedDomains)
}

View File

@@ -105,7 +105,7 @@ func TestAddUserToTeam(t *testing.T) {
}
})
t.Run("block user by domain", func(t *testing.T) {
t.Run("block user by domain but allow bot", func(t *testing.T) {
th.BasicTeam.AllowedDomains = "example.com"
if _, err := th.App.UpdateTeam(th.BasicTeam); err != nil {
t.Log(err)
@@ -131,10 +131,20 @@ func TestAddUserToTeam(t *testing.T) {
}
defer th.App.PermanentDeleteUser(&user)
if _, err := th.App.AddUserToTeam(th.BasicTeam.Id, ruser.Id, ""); err == nil || err.Where != "JoinUserToTeam" {
if _, err = th.App.AddUserToTeam(th.BasicTeam.Id, ruser.Id, ""); err == nil || err.Where != "JoinUserToTeam" {
t.Log(err)
t.Fatal("Should not add authservice user")
}
bot, err := th.App.CreateBot(&model.Bot{
Username: "somebot",
Description: "a bot",
OwnerId: th.BasicUser.Id,
})
require.Nil(t, err)
_, err = th.App.AddUserToTeam(th.BasicTeam.Id, bot.UserId, "")
assert.Nil(t, err, "should be able to add bot to domain restricted team")
})
t.Run("block user with subdomain", func(t *testing.T) {