[MM-61458] Fix errcheck issues in server/channels/app/plugin_requests.go (#29121)
Этот коммит содержится в:
@@ -133,7 +133,6 @@ issues:
|
|||||||
channels/app/plugin_api_tests/manual.test_serve_metrics_plugin/main.go|\
|
channels/app/plugin_api_tests/manual.test_serve_metrics_plugin/main.go|\
|
||||||
channels/app/plugin_api_tests/test_update_user_auth_plugin/main.go|\
|
channels/app/plugin_api_tests/test_update_user_auth_plugin/main.go|\
|
||||||
channels/app/plugin_install.go|\
|
channels/app/plugin_install.go|\
|
||||||
channels/app/plugin_requests.go|\
|
|
||||||
channels/app/plugin_signature.go|\
|
channels/app/plugin_signature.go|\
|
||||||
channels/app/plugin_signature_test.go|\
|
channels/app/plugin_signature_test.go|\
|
||||||
channels/app/plugin_test.go|\
|
channels/app/plugin_test.go|\
|
||||||
|
|||||||
@@ -25,11 +25,13 @@ func (ch *Channels) ServePluginRequest(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
pluginsEnvironment := ch.GetPluginsEnvironment()
|
pluginsEnvironment := ch.GetPluginsEnvironment()
|
||||||
if pluginsEnvironment == nil {
|
if pluginsEnvironment == nil {
|
||||||
err := model.NewAppError("ServePluginRequest", "app.plugin.disabled.app_error", nil, "Enable plugins to serve plugin requests", http.StatusNotImplemented)
|
appErr := model.NewAppError("ServePluginRequest", "app.plugin.disabled.app_error", nil, "Enable plugins to serve plugin requests", http.StatusNotImplemented)
|
||||||
mlog.Error(err.Error())
|
mlog.Error(appErr.Error())
|
||||||
w.WriteHeader(err.StatusCode)
|
w.WriteHeader(appErr.StatusCode)
|
||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
w.Write([]byte(err.ToJSON()))
|
if _, err := w.Write([]byte(appErr.ToJSON())); err != nil {
|
||||||
|
mlog.Warn("Error while writing response", mlog.Err(err))
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -49,11 +51,13 @@ func (ch *Channels) ServePluginRequest(w http.ResponseWriter, r *http.Request) {
|
|||||||
func (a *App) ServeInterPluginRequest(w http.ResponseWriter, r *http.Request, sourcePluginId, destinationPluginId string) {
|
func (a *App) ServeInterPluginRequest(w http.ResponseWriter, r *http.Request, sourcePluginId, destinationPluginId string) {
|
||||||
pluginsEnvironment := a.ch.GetPluginsEnvironment()
|
pluginsEnvironment := a.ch.GetPluginsEnvironment()
|
||||||
if pluginsEnvironment == nil {
|
if pluginsEnvironment == nil {
|
||||||
err := model.NewAppError("ServeInterPluginRequest", "app.plugin.disabled.app_error", nil, "Plugin environment not found.", http.StatusNotImplemented)
|
appErr := model.NewAppError("ServeInterPluginRequest", "app.plugin.disabled.app_error", nil, "Plugin environment not found.", http.StatusNotImplemented)
|
||||||
a.Log().Error(err.Error())
|
a.Log().Error(appErr.Error())
|
||||||
w.WriteHeader(err.StatusCode)
|
w.WriteHeader(appErr.StatusCode)
|
||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
w.Write([]byte(err.ToJSON()))
|
if _, err := w.Write([]byte(appErr.ToJSON())); err != nil {
|
||||||
|
mlog.Warn("Error while writing response", mlog.Err(err))
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -147,17 +151,19 @@ func (ch *Channels) servePluginRequest(w http.ResponseWriter, r *http.Request, h
|
|||||||
|
|
||||||
r.Header.Del("Mattermost-User-Id")
|
r.Header.Del("Mattermost-User-Id")
|
||||||
if token != "" {
|
if token != "" {
|
||||||
session, err := New(ServerConnector(ch)).GetSession(token)
|
session, appErr := New(ServerConnector(ch)).GetSession(token)
|
||||||
|
|
||||||
csrfCheckPassed := false
|
csrfCheckPassed := false
|
||||||
|
|
||||||
if session != nil && err == nil && cookieAuth && r.Method != "GET" {
|
if session != nil && appErr == nil && cookieAuth && r.Method != "GET" {
|
||||||
sentToken := ""
|
sentToken := ""
|
||||||
|
|
||||||
if r.Header.Get(model.HeaderCsrfToken) == "" {
|
if r.Header.Get(model.HeaderCsrfToken) == "" {
|
||||||
bodyBytes, _ := io.ReadAll(r.Body)
|
bodyBytes, _ := io.ReadAll(r.Body)
|
||||||
r.Body = io.NopCloser(bytes.NewBuffer(bodyBytes))
|
r.Body = io.NopCloser(bytes.NewBuffer(bodyBytes))
|
||||||
r.ParseForm()
|
if err := r.ParseForm(); err != nil {
|
||||||
|
mlog.Warn("Failed to parse form data for plugin request", mlog.Err(err))
|
||||||
|
}
|
||||||
sentToken = r.FormValue("csrf")
|
sentToken = r.FormValue("csrf")
|
||||||
r.Body = io.NopCloser(bytes.NewBuffer(bodyBytes))
|
r.Body = io.NopCloser(bytes.NewBuffer(bodyBytes))
|
||||||
} else {
|
} else {
|
||||||
@@ -199,7 +205,7 @@ func (ch *Channels) servePluginRequest(w http.ResponseWriter, r *http.Request, h
|
|||||||
csrfCheckPassed = true
|
csrfCheckPassed = true
|
||||||
}
|
}
|
||||||
|
|
||||||
if (session != nil && session.Id != "") && err == nil && csrfCheckPassed {
|
if (session != nil && session.Id != "") && appErr == nil && csrfCheckPassed {
|
||||||
r.Header.Set("Mattermost-User-Id", session.UserId)
|
r.Header.Set("Mattermost-User-Id", session.UserId)
|
||||||
context.SessionId = session.Id
|
context.SessionId = session.Id
|
||||||
|
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user