MM-44805: Avoid pointers in JSON parsing in createCategoryForTeamForUser (#20429)
Passing null is a valid JSON input for a pointer struct. So we avoid passing pointer to pointer. https://mattermost.atlassian.net/browse/MM-44805 ```release-note NONE ```
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
16174cacf0
Коммит
b443746e80
@@ -52,19 +52,19 @@ func createCategoryForTeamForUser(c *Context, w http.ResponseWriter, r *http.Req
|
||||
auditRec := c.MakeAuditRecord("createCategoryForTeamForUser", audit.Fail)
|
||||
defer c.LogAuditRec(auditRec)
|
||||
|
||||
var categoryCreateRequest *model.SidebarCategoryWithChannels
|
||||
var categoryCreateRequest model.SidebarCategoryWithChannels
|
||||
err := json.NewDecoder(r.Body).Decode(&categoryCreateRequest)
|
||||
if err != nil || c.Params.UserId != categoryCreateRequest.UserId || c.Params.TeamId != categoryCreateRequest.TeamId {
|
||||
c.SetInvalidParam("category")
|
||||
return
|
||||
}
|
||||
|
||||
if appErr := validateSidebarCategory(c, c.Params.TeamId, c.Params.UserId, categoryCreateRequest); appErr != nil {
|
||||
if appErr := validateSidebarCategory(c, c.Params.TeamId, c.Params.UserId, &categoryCreateRequest); appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
category, appErr := c.App.CreateSidebarCategory(c.Params.UserId, c.Params.TeamId, categoryCreateRequest)
|
||||
category, appErr := c.App.CreateSidebarCategory(c.Params.UserId, c.Params.TeamId, &categoryCreateRequest)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
|
||||
@@ -5,6 +5,7 @@ package api4
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -90,6 +91,17 @@ func TestCreateCategoryForTeamForUser(t *testing.T) {
|
||||
require.Equal(t, int64(10), customCategory.SortOrder)
|
||||
})
|
||||
|
||||
t.Run("should not crash with null input", func(t *testing.T) {
|
||||
require.NotPanics(t, func() {
|
||||
user, client := setupUserForSubtest(t, th)
|
||||
payload := []byte(`null`)
|
||||
route := fmt.Sprintf("/users/%s/teams/%s/channels/categories", user.Id, th.BasicTeam.Id)
|
||||
r, err := client.DoAPIPostBytes(route, payload)
|
||||
require.Error(t, err)
|
||||
closeBody(r)
|
||||
})
|
||||
})
|
||||
|
||||
t.Run("should publish expected WS payload", func(t *testing.T) {
|
||||
t.Skip("MM-42652")
|
||||
userWSClient, err := th.CreateWebSocketClient()
|
||||
|
||||
Ссылка в новой задаче
Block a user