Fix panic if JSON null value is passed as channel update (#23629)

Этот коммит содержится в:
Ben Schumacher
2023-06-05 19:16:47 +02:00
коммит произвёл GitHub
родитель 9c656c25d9
Коммит 3705d7af4d
2 изменённых файлов: 10 добавлений и 1 удалений

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

@@ -125,7 +125,7 @@ func updateChannel(c *Context, w http.ResponseWriter, r *http.Request) {
var channel *model.Channel
err := json.NewDecoder(r.Body).Decode(&channel)
if err != nil {
if err != nil || channel == nil {
c.SetInvalidParamWithErr("channel", err)
return
}

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

@@ -250,6 +250,15 @@ func TestUpdateChannel(t *testing.T) {
_, resp, err = client.UpdateChannel(directChannel)
require.Error(t, err)
CheckForbiddenStatus(t, resp)
t.Run("null value", func(t *testing.T) {
r, err := client.DoAPIPut(fmt.Sprintf("/channels"+"/%v", channel.Id), "null")
resp := model.BuildResponse(r)
defer closeBody(r)
require.Error(t, err)
CheckBadRequestStatus(t, resp)
})
}
func TestPatchChannel(t *testing.T) {