[MM-50080] Limit max length for the name field (#22282)

Этот коммит содержится в:
Julien Tant
2023-02-09 09:37:40 -07:00
коммит произвёл GitHub
родитель 0880837fd0
Коммит 4752a5b8e0
3 изменённых файлов: 18 добавлений и 0 удалений

Просмотреть файл

@@ -68,6 +68,12 @@ func (a *App) executeWorkTemplate(
ChannelIDs: []string{},
}
if wtcr.Name != "" {
if len(wtcr.Name) > model.ChannelNameMaxLength {
return res, model.NewAppError("ExecuteWorkTemplate", "app.worktemplates.execute_work_template.name_too_long", nil, "", http.StatusBadRequest)
}
}
contentByType := map[string][]model.WorkTemplateContent{
"channel": {},
"board": {},

Просмотреть файл

@@ -4,6 +4,8 @@
package app
import (
"net/http"
"strings"
"testing"
"time"
@@ -228,4 +230,10 @@ func TestExecuteWorkTemplate(t *testing.T) {
executorMock.AssertExpectations(t)
})
t.Run("with name too long", func(t *testing.T) {
req.Name = strings.Repeat("a", model.ChannelNameMaxLength+1)
_, appErr := th.App.executeWorkTemplate(c, req, nil, false)
assert.NotNil(t, appErr)
assert.Equal(t, http.StatusBadRequest, appErr.StatusCode)
})
}

Просмотреть файл

@@ -7127,6 +7127,10 @@
"id": "app.worktemplates.execute_work_template.channels.create_error",
"translation": "Error while creating a channel."
},
{
"id": "app.worktemplates.execute_work_template.name_too_long",
"translation": "The name field cannot contain more than 64 characters."
},
{
"id": "app.worktemplates.execute_work_template.playbooks.create_error",
"translation": "Error while creating a playbook."