[MM-63345] Address Go v1.23 incompatibility issues with plugins (#30386)
* Address Go v1.23 incompatibility issues with plugins * Install multiple Go versions for compatibility tests * Rename
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
661f7f6a83
Коммит
7c25de2cff
@@ -1614,7 +1614,8 @@ func TestInterpluginPluginHTTP(t *testing.T) {
|
||||
defer th.TearDown()
|
||||
|
||||
setupMultiPluginAPITest(t,
|
||||
[]string{`
|
||||
[]string{
|
||||
`
|
||||
package main
|
||||
|
||||
import (
|
||||
@@ -1759,8 +1760,7 @@ func TestAPIMetrics(t *testing.T) {
|
||||
|
||||
pluginID := model.NewId()
|
||||
backend := filepath.Join(pluginDir, pluginID, "backend.exe")
|
||||
code :=
|
||||
`
|
||||
code := `
|
||||
package main
|
||||
|
||||
import (
|
||||
@@ -1896,6 +1896,23 @@ func TestPluginHTTPConnHijack(t *testing.T) {
|
||||
require.Equal(t, "OK", string(body))
|
||||
}
|
||||
|
||||
func makePluginHTTPRequest(t *testing.T, pluginID string, port int, token string) string {
|
||||
t.Helper()
|
||||
client := &http.Client{}
|
||||
reqURL := fmt.Sprintf("http://localhost:%d/plugins/%s", port, pluginID)
|
||||
req, err := http.NewRequest("GET", reqURL, nil)
|
||||
require.NoError(t, err)
|
||||
req.Header.Set(model.HeaderAuth, model.HeaderToken+" "+token)
|
||||
|
||||
resp, err := client.Do(req)
|
||||
require.NoError(t, err)
|
||||
defer resp.Body.Close()
|
||||
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
require.NoError(t, err)
|
||||
return string(body)
|
||||
}
|
||||
|
||||
func TestPluginMFAEnforcement(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
@@ -1942,22 +1959,6 @@ func TestPluginMFAEnforcement(t *testing.T) {
|
||||
})
|
||||
require.Nil(t, appErr)
|
||||
|
||||
client := &http.Client{}
|
||||
makeRequest := func() string {
|
||||
reqURL := fmt.Sprintf("http://localhost:%d/plugins/%s", th.Server.ListenAddr.Port, pluginID)
|
||||
req, err := http.NewRequest("GET", reqURL, nil)
|
||||
require.NoError(t, err)
|
||||
req.Header.Set(model.HeaderAuth, model.HeaderToken+" "+session.Token)
|
||||
|
||||
resp, err := client.Do(req)
|
||||
require.NoError(t, err)
|
||||
defer resp.Body.Close()
|
||||
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
require.NoError(t, err)
|
||||
return string(body)
|
||||
}
|
||||
|
||||
t.Run("MFA not enforced", func(t *testing.T) {
|
||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||
*cfg.ServiceSettings.EnableMultifactorAuthentication = true
|
||||
@@ -1965,7 +1966,7 @@ func TestPluginMFAEnforcement(t *testing.T) {
|
||||
})
|
||||
|
||||
// Should return user ID since MFA is not enforced
|
||||
userID := makeRequest()
|
||||
userID := makePluginHTTPRequest(t, pluginID, th.Server.ListenAddr.Port, session.Token)
|
||||
assert.Equal(t, user.Id, userID)
|
||||
})
|
||||
|
||||
@@ -1976,7 +1977,7 @@ func TestPluginMFAEnforcement(t *testing.T) {
|
||||
})
|
||||
|
||||
// Should return empty string since MFA is enforced but not active
|
||||
userID := makeRequest()
|
||||
userID := makePluginHTTPRequest(t, pluginID, th.Server.ListenAddr.Port, session.Token)
|
||||
assert.Empty(t, userID)
|
||||
})
|
||||
}
|
||||
@@ -2806,3 +2807,42 @@ func TestPluginPatchChannelMembersNotifications(t *testing.T) {
|
||||
assert.Equal(t, "", updated.NotifyProps["test_field"])
|
||||
})
|
||||
}
|
||||
|
||||
func TestPluginServeHTTPCompatibility(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
pluginCode := `
|
||||
package main
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"github.com/mattermost/mattermost/server/public/plugin"
|
||||
)
|
||||
|
||||
type MyPlugin struct {
|
||||
plugin.MattermostPlugin
|
||||
}
|
||||
|
||||
func (p *MyPlugin) ServeHTTP(c *plugin.Context, w http.ResponseWriter, r *http.Request) {
|
||||
w.Write([]byte("plugin response"))
|
||||
}
|
||||
|
||||
func main() {
|
||||
plugin.ClientMain(&MyPlugin{})
|
||||
}
|
||||
`
|
||||
|
||||
for _, goVersion := range strings.Fields(os.Getenv("GO_COMPATIBILITY_TEST_VERSIONS")) {
|
||||
t.Run(goVersion, func(t *testing.T) {
|
||||
tearDown, ids, errs := SetAppEnvironmentWithPluginsGoVersion(t, []string{pluginCode}, th.App, th.NewPluginAPI, goVersion)
|
||||
defer tearDown()
|
||||
require.NoError(t, errs[0])
|
||||
require.Len(t, ids, 1)
|
||||
pluginID := ids[0]
|
||||
|
||||
res := makePluginHTTPRequest(t, pluginID, th.Server.ListenAddr.Port, "")
|
||||
assert.Equal(t, "plugin response", res)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user