[MM-34919] Use Mattermost-Plugin-ID header to pass ID in inter-plugin requests (#17418)

This commit is contained in:
Ben Schumacher
2021-04-19 14:02:00 +02:00
committed by GitHub
parent 4bd6f4942f
commit 730dc6b985
3 changed files with 10 additions and 1 deletions
+4
View File
@@ -1404,6 +1404,10 @@ func TestInterpluginPluginHTTP(t *testing.T) {
return
}
if r.Header.Get("Mattermost-Plugin-ID") != "testplugininterclient" {
return
}
buf := bytes.Buffer{}
buf.ReadFrom(r.Body)
resp := "we got:" + buf.String()
+5
View File
@@ -74,6 +74,8 @@ func (a *App) ServeInterPluginRequest(w http.ResponseWriter, r *http.Request, so
SourcePluginId: sourcePluginId,
}
r.Header.Set("Mattermost-Plugin-ID", sourcePluginId)
hooks.ServeHTTP(context, w, r)
}
@@ -135,6 +137,9 @@ func (a *App) servePluginRequest(w http.ResponseWriter, r *http.Request, handler
token = r.URL.Query().Get("access_token")
}
// Mattermost-Plugin-ID can only be set by inter-plugin requests
r.Header.Del("Mattermost-Plugin-ID")
r.Header.Del("Mattermost-User-Id")
if token != "" {
session, err := a.GetSession(token)
+1 -1
View File
@@ -12,5 +12,5 @@ type Context struct {
IpAddress string
AcceptLanguage string
UserAgent string
SourcePluginId string
SourcePluginId string // Deprecated: Use the "Mattermost-Plugin-ID" HTTP header instead
}