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
@@ -94,6 +94,15 @@ func (env *Environment) IsActive(id string) bool {
|
||||
return ok
|
||||
}
|
||||
|
||||
// PublicFilesPath returns a path and true if the plugin with the given id is active.
|
||||
// It returns an empty string and false if the path is not set or invalid
|
||||
func (env *Environment) PublicFilesPath(id string) (string, error) {
|
||||
if _, ok := env.activePlugins.Load(id); !ok {
|
||||
return "", fmt.Errorf("plugin not found: %v", id)
|
||||
}
|
||||
return filepath.Join(env.pluginDir, id, "public"), nil
|
||||
}
|
||||
|
||||
// Statuses returns a list of plugin statuses representing the state of every plugin
|
||||
func (env *Environment) Statuses() (model.PluginStatuses, error) {
|
||||
plugins, err := env.Available()
|
||||
|
||||
@@ -6,12 +6,12 @@ package plugin
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/mattermost/mattermost-server/mlog"
|
||||
"github.com/mattermost/mattermost-server/model"
|
||||
"github.com/mattermost/mattermost-server/utils"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
@@ -26,18 +26,6 @@ func TestSupervisor(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func compileGo(t *testing.T, sourceCode, outputPath string) {
|
||||
dir, err := ioutil.TempDir(".", "")
|
||||
require.NoError(t, err)
|
||||
defer os.RemoveAll(dir)
|
||||
require.NoError(t, ioutil.WriteFile(filepath.Join(dir, "main.go"), []byte(sourceCode), 0600))
|
||||
cmd := exec.Command("go", "build", "-o", outputPath, "main.go")
|
||||
cmd.Dir = dir
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
require.NoError(t, cmd.Run())
|
||||
}
|
||||
|
||||
func testSupervisor_InvalidExecutablePath(t *testing.T) {
|
||||
dir, err := ioutil.TempDir("", "")
|
||||
require.NoError(t, err)
|
||||
@@ -83,7 +71,7 @@ func testSupervisor_StartTimeout(t *testing.T) {
|
||||
defer os.RemoveAll(dir)
|
||||
|
||||
backend := filepath.Join(dir, "backend.exe")
|
||||
compileGo(t, `
|
||||
utils.CompileGo(t, `
|
||||
package main
|
||||
|
||||
func main() {
|
||||
|
||||
Ссылка в новой задаче
Block a user