Ignore blank role names in getRolesByName call. (#8507)
Этот коммит содержится в:
коммит произвёл
Jesús Espino
родитель
5fa1b35819
Коммит
ca5198c7b6
10
api4/role.go
10
api4/role.go
@@ -5,6 +5,7 @@ package api4
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/mattermost/mattermost-server/model"
|
"github.com/mattermost/mattermost-server/model"
|
||||||
)
|
)
|
||||||
@@ -52,14 +53,21 @@ func getRolesByNames(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var cleanedRoleNames []string
|
||||||
for _, rolename := range rolenames {
|
for _, rolename := range rolenames {
|
||||||
|
if strings.TrimSpace(rolename) == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
if !model.IsValidRoleName(rolename) {
|
if !model.IsValidRoleName(rolename) {
|
||||||
c.SetInvalidParam("rolename")
|
c.SetInvalidParam("rolename")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cleanedRoleNames = append(cleanedRoleNames, rolename)
|
||||||
}
|
}
|
||||||
|
|
||||||
if roles, err := c.App.GetRolesByNames(rolenames); err != nil {
|
if roles, err := c.App.GetRolesByNames(cleanedRoleNames); err != nil {
|
||||||
c.Err = err
|
c.Err = err
|
||||||
return
|
return
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -129,13 +129,21 @@ func TestGetRolesByNames(t *testing.T) {
|
|||||||
assert.Contains(t, received, role2)
|
assert.Contains(t, received, role2)
|
||||||
assert.Contains(t, received, role3)
|
assert.Contains(t, received, role3)
|
||||||
|
|
||||||
// Check a list of invalid roles.
|
// Check a list of non-existant roles.
|
||||||
// TODO: Confirm whether no error for invalid role names is intended.
|
|
||||||
received, resp = th.Client.GetRolesByNames([]string{model.NewId(), model.NewId()})
|
received, resp = th.Client.GetRolesByNames([]string{model.NewId(), model.NewId()})
|
||||||
CheckNoError(t, resp)
|
CheckNoError(t, resp)
|
||||||
|
|
||||||
|
// Empty list should error.
|
||||||
_, resp = th.SystemAdminClient.GetRolesByNames([]string{})
|
_, resp = th.SystemAdminClient.GetRolesByNames([]string{})
|
||||||
CheckBadRequestStatus(t, resp)
|
CheckBadRequestStatus(t, resp)
|
||||||
|
|
||||||
|
// Invalid role name should error.
|
||||||
|
received, resp = th.Client.GetRolesByNames([]string{model.NewId(), model.NewId(), "!!!!!!"})
|
||||||
|
CheckBadRequestStatus(t, resp)
|
||||||
|
|
||||||
|
// Empty/whitespace rolenames should be ignored.
|
||||||
|
received, resp = th.Client.GetRolesByNames([]string{model.NewId(), model.NewId(), "", " "})
|
||||||
|
CheckNoError(t, resp)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPatchRole(t *testing.T) {
|
func TestPatchRole(t *testing.T) {
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user