Avoid panic when push messages are empty or nil (#13751)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
3049378506
Коммит
682a1d5d15
@@ -411,14 +411,23 @@ func getRedirectLocation(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func pushNotificationAck(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
ack := model.PushNotificationAckFromJson(r.Body)
|
||||
ack, err := model.PushNotificationAckFromJson(r.Body)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("pushNotificationAck",
|
||||
"api.push_notifications_ack.message.parse.app_error",
|
||||
nil,
|
||||
err.Error(),
|
||||
http.StatusBadRequest,
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
if !*c.App.Config().EmailSettings.SendPushNotifications {
|
||||
c.Err = model.NewAppError("pushNotificationAck", "api.push_notification.disabled.app_error", nil, "", http.StatusNotImplemented)
|
||||
return
|
||||
}
|
||||
|
||||
err := c.App.SendAckToPushProxy(ack)
|
||||
err = c.App.SendAckToPushProxy(ack)
|
||||
if ack.IsIdLoaded {
|
||||
if err != nil {
|
||||
// Log the error only, then continue to fetch notification message
|
||||
|
||||
@@ -627,3 +627,20 @@ func TestServerBusy503(t *testing.T) {
|
||||
CheckNoError(t, resp)
|
||||
})
|
||||
}
|
||||
|
||||
func TestPushNotificationAck(t *testing.T) {
|
||||
th := Setup().InitBasic()
|
||||
api := Init(th.Server, th.Server.AppOptions, th.Server.Router)
|
||||
session, _ := th.App.GetSession(th.Client.AuthToken)
|
||||
defer th.TearDown()
|
||||
t.Run("should return error when the ack body is not passed", func(t *testing.T) {
|
||||
handler := api.ApiHandler(pushNotificationAck)
|
||||
resp := httptest.NewRecorder()
|
||||
req := httptest.NewRequest("POST", "/api/v4/notifications/ack", nil)
|
||||
req.Header.Set(model.HEADER_AUTH, "Bearer "+session.Token)
|
||||
|
||||
handler.ServeHTTP(resp, req)
|
||||
assert.Equal(t, http.StatusBadRequest, resp.Code)
|
||||
assert.NotNil(t, resp.Body)
|
||||
})
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user