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)
|
auditRec := c.MakeAuditRecord("createCategoryForTeamForUser", audit.Fail)
|
||||||
defer c.LogAuditRec(auditRec)
|
defer c.LogAuditRec(auditRec)
|
||||||
|
|
||||||
var categoryCreateRequest *model.SidebarCategoryWithChannels
|
var categoryCreateRequest model.SidebarCategoryWithChannels
|
||||||
err := json.NewDecoder(r.Body).Decode(&categoryCreateRequest)
|
err := json.NewDecoder(r.Body).Decode(&categoryCreateRequest)
|
||||||
if err != nil || c.Params.UserId != categoryCreateRequest.UserId || c.Params.TeamId != categoryCreateRequest.TeamId {
|
if err != nil || c.Params.UserId != categoryCreateRequest.UserId || c.Params.TeamId != categoryCreateRequest.TeamId {
|
||||||
c.SetInvalidParam("category")
|
c.SetInvalidParam("category")
|
||||||
return
|
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
|
c.Err = appErr
|
||||||
return
|
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 {
|
if appErr != nil {
|
||||||
c.Err = appErr
|
c.Err = appErr
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ package api4
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -90,6 +91,17 @@ func TestCreateCategoryForTeamForUser(t *testing.T) {
|
|||||||
require.Equal(t, int64(10), customCategory.SortOrder)
|
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.Run("should publish expected WS payload", func(t *testing.T) {
|
||||||
t.Skip("MM-42652")
|
t.Skip("MM-42652")
|
||||||
userWSClient, err := th.CreateWebSocketClient()
|
userWSClient, err := th.CreateWebSocketClient()
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user