mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
* 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
96 lines
2.6 KiB
Go
96 lines
2.6 KiB
Go
// Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved.
|
|
// See License.txt for license information.
|
|
|
|
package plugin
|
|
|
|
import (
|
|
"io/ioutil"
|
|
"os"
|
|
"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"
|
|
)
|
|
|
|
func TestSupervisor(t *testing.T) {
|
|
for name, f := range map[string]func(*testing.T){
|
|
"Supervisor_InvalidExecutablePath": testSupervisor_InvalidExecutablePath,
|
|
"Supervisor_NonExistentExecutablePath": testSupervisor_NonExistentExecutablePath,
|
|
"Supervisor_StartTimeout": testSupervisor_StartTimeout,
|
|
} {
|
|
t.Run(name, f)
|
|
}
|
|
}
|
|
|
|
func testSupervisor_InvalidExecutablePath(t *testing.T) {
|
|
dir, err := ioutil.TempDir("", "")
|
|
require.NoError(t, err)
|
|
defer os.RemoveAll(dir)
|
|
|
|
ioutil.WriteFile(filepath.Join(dir, "plugin.json"), []byte(`{"id": "foo", "backend": {"executable": "/foo/../../backend.exe"}}`), 0600)
|
|
|
|
bundle := model.BundleInfoForPath(dir)
|
|
log := mlog.NewLogger(&mlog.LoggerConfiguration{
|
|
EnableConsole: true,
|
|
ConsoleJson: true,
|
|
ConsoleLevel: "error",
|
|
EnableFile: false,
|
|
})
|
|
supervisor, err := newSupervisor(bundle, log, nil)
|
|
assert.Nil(t, supervisor)
|
|
assert.Error(t, err)
|
|
}
|
|
|
|
func testSupervisor_NonExistentExecutablePath(t *testing.T) {
|
|
dir, err := ioutil.TempDir("", "")
|
|
require.NoError(t, err)
|
|
defer os.RemoveAll(dir)
|
|
|
|
ioutil.WriteFile(filepath.Join(dir, "plugin.json"), []byte(`{"id": "foo", "backend": {"executable": "thisfileshouldnotexist"}}`), 0600)
|
|
|
|
bundle := model.BundleInfoForPath(dir)
|
|
log := mlog.NewLogger(&mlog.LoggerConfiguration{
|
|
EnableConsole: true,
|
|
ConsoleJson: true,
|
|
ConsoleLevel: "error",
|
|
EnableFile: false,
|
|
})
|
|
supervisor, err := newSupervisor(bundle, log, nil)
|
|
require.Error(t, err)
|
|
require.Nil(t, supervisor)
|
|
}
|
|
|
|
// If plugin development goes really wrong, let's make sure plugin activation won't block forever.
|
|
func testSupervisor_StartTimeout(t *testing.T) {
|
|
dir, err := ioutil.TempDir("", "")
|
|
require.NoError(t, err)
|
|
defer os.RemoveAll(dir)
|
|
|
|
backend := filepath.Join(dir, "backend.exe")
|
|
utils.CompileGo(t, `
|
|
package main
|
|
|
|
func main() {
|
|
for {
|
|
}
|
|
}
|
|
`, backend)
|
|
|
|
ioutil.WriteFile(filepath.Join(dir, "plugin.json"), []byte(`{"id": "foo", "backend": {"executable": "backend.exe"}}`), 0600)
|
|
|
|
bundle := model.BundleInfoForPath(dir)
|
|
log := mlog.NewLogger(&mlog.LoggerConfiguration{
|
|
EnableConsole: true,
|
|
ConsoleJson: true,
|
|
ConsoleLevel: "error",
|
|
EnableFile: false,
|
|
})
|
|
supervisor, err := newSupervisor(bundle, log, nil)
|
|
require.Error(t, err)
|
|
require.Nil(t, supervisor)
|
|
}
|