MM-14575 - Automatically serve static files for plugins (#10476)
* MM-14575 - Automatically serve static files for plugins * Added static handler for plugin public files * Added StaticFilesPath method to Environment for use by MainRouter * Added "static_files" property to Manifest Server * Added unit tests for these changes * MM-14575: Adding comment for cache control value * MM-14575: Moved Static Plugin Request handler to plugin_requests * Updated testing * MM-14575: Removing the StaticFiles from Manifest Server * MM-14575: Removing static files from test * MM-14575: Updating static files test * MM14575: Removing cache directive from plugin static files * MM14575: Moving plugin public directory to root * MM-14575: Updating tests for changed public directory * MM-14575: Moved compileGo to a common utils package for tests * MM-14575: Moving plugins initialization to InitPlugins find in tests * Update utils/test_files_compiler.go Adding Copyright header Co-Authored-By: happygaijin <happygaijin@users.noreply.github.com> * MM-14575: Consistent usage of static vs public name * Removing spurious newline * Comment typo Co-Authored-By: happygaijin <happygaijin@users.noreply.github.com> * Removing spurious new line Co-Authored-By: happygaijin <happygaijin@users.noreply.github.com> * MM14575: Adding a test to make sure only public files can be requested * MM-14575 Adding a test for redirects on public files
Этот коммит содержится в:
коммит произвёл
Jesse Hallam
родитель
7c9837d9b1
Коммит
ba34b4607c
@@ -8,7 +8,6 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/mattermost/mattermost-server/utils/fileutils"
|
||||
"image"
|
||||
"image/color"
|
||||
"image/png"
|
||||
@@ -21,13 +20,16 @@ import (
|
||||
"text/template"
|
||||
"time"
|
||||
|
||||
"github.com/mattermost/mattermost-server/utils/fileutils"
|
||||
|
||||
"github.com/mattermost/mattermost-server/model"
|
||||
"github.com/mattermost/mattermost-server/plugin"
|
||||
"github.com/mattermost/mattermost-server/utils"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func setupPluginApiTest(t *testing.T, pluginCode string, pluginManifest string, pluginId string, app *App) {
|
||||
func setupPluginApiTest(t *testing.T, pluginCode string, pluginManifest string, pluginId string, app *App) string {
|
||||
pluginDir, err := ioutil.TempDir("", "")
|
||||
require.NoError(t, err)
|
||||
webappPluginDir, err := ioutil.TempDir("", "")
|
||||
@@ -39,7 +41,7 @@ func setupPluginApiTest(t *testing.T, pluginCode string, pluginManifest string,
|
||||
require.NoError(t, err)
|
||||
|
||||
backend := filepath.Join(pluginDir, pluginId, "backend.exe")
|
||||
compileGo(t, pluginCode, backend)
|
||||
utils.CompileGo(t, pluginCode, backend)
|
||||
|
||||
ioutil.WriteFile(filepath.Join(pluginDir, pluginId, "plugin.json"), []byte(pluginManifest), 0600)
|
||||
manifest, activated, reterr := env.Activate(pluginId)
|
||||
@@ -48,8 +50,39 @@ func setupPluginApiTest(t *testing.T, pluginCode string, pluginManifest string,
|
||||
require.True(t, activated)
|
||||
|
||||
app.SetPluginsEnvironment(env)
|
||||
|
||||
return pluginDir
|
||||
}
|
||||
|
||||
func TestPublicFilesPathConfiguration(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
pluginID := "com.mattermost.sample"
|
||||
|
||||
pluginDir := setupPluginApiTest(t,
|
||||
`
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/mattermost/mattermost-server/plugin"
|
||||
)
|
||||
|
||||
type MyPlugin struct {
|
||||
plugin.MattermostPlugin
|
||||
}
|
||||
|
||||
func main() {
|
||||
plugin.ClientMain(&MyPlugin{})
|
||||
}
|
||||
`,
|
||||
`{"id": "com.mattermost.sample", "server": {"executable": "backend.exe"}, "settings_schema": {"settings": []}}`, pluginID, th.App)
|
||||
|
||||
publicFilesFolderInTest := filepath.Join(pluginDir, pluginID, "public")
|
||||
publicFilesPath, err := th.App.GetPluginsEnvironment().PublicFilesPath(pluginID)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, publicFilesPath, publicFilesFolderInTest)
|
||||
}
|
||||
func TestPluginAPIGetUsers(t *testing.T) {
|
||||
th := Setup(t)
|
||||
defer th.TearDown()
|
||||
@@ -460,7 +493,7 @@ func TestPluginAPIGetPlugins(t *testing.T) {
|
||||
var pluginManifests []*model.Manifest
|
||||
for _, pluginID := range pluginIDs {
|
||||
backend := filepath.Join(pluginDir, pluginID, "backend.exe")
|
||||
compileGo(t, pluginCode, backend)
|
||||
utils.CompileGo(t, pluginCode, backend)
|
||||
|
||||
ioutil.WriteFile(filepath.Join(pluginDir, pluginID, "plugin.json"), []byte(fmt.Sprintf(`{"id": "%s", "server": {"executable": "backend.exe"}}`, pluginID)), 0600)
|
||||
manifest, activated, reterr := env.Activate(pluginID)
|
||||
|
||||
Ссылка в новой задаче
Block a user