summaryrefslogtreecommitdiffstats
path: root/plugin
diff options
context:
space:
mode:
Diffstat (limited to 'plugin')
-rw-r--r--plugin/pluginenv/environment.go21
-rw-r--r--plugin/rpcplugin/api.go2
-rw-r--r--plugin/rpcplugin/api_test.go43
-rw-r--r--plugin/rpcplugin/sandbox/sandbox_linux.go9
4 files changed, 66 insertions, 9 deletions
diff --git a/plugin/pluginenv/environment.go b/plugin/pluginenv/environment.go
index f53021f74..adc9ddbde 100644
--- a/plugin/pluginenv/environment.go
+++ b/plugin/pluginenv/environment.go
@@ -8,6 +8,7 @@ import (
"fmt"
"io/ioutil"
"net/http"
+ "path/filepath"
"sync"
"github.com/pkg/errors"
@@ -163,12 +164,24 @@ func (env *Environment) ActivatePlugin(id string) error {
return fmt.Errorf("env missing webapp path, cannot activate plugin: %v", id)
}
- webappBundle, err := ioutil.ReadFile(fmt.Sprintf("%s/%s/webapp/%s_bundle.js", env.searchPath, id, id))
+ bundlePath := filepath.Clean(bundle.Manifest.Webapp.BundlePath)
+ if bundlePath == "" || bundlePath[0] == '.' {
+ return fmt.Errorf("invalid webapp bundle path")
+ }
+ bundlePath = filepath.Join(env.searchPath, id, bundlePath)
+
+ webappBundle, err := ioutil.ReadFile(bundlePath)
if err != nil {
- if supervisor != nil {
- supervisor.Stop()
+ // Backwards compatibility for plugins where webapp.bundle_path was ignored. This should
+ // be removed eventually.
+ if webappBundle2, err2 := ioutil.ReadFile(fmt.Sprintf("%s/%s/webapp/%s_bundle.js", env.searchPath, id, id)); err2 == nil {
+ webappBundle = webappBundle2
+ } else {
+ if supervisor != nil {
+ supervisor.Stop()
+ }
+ return errors.Wrapf(err, "unable to read webapp bundle: %v", id)
}
- return errors.Wrapf(err, "unable to read webapp bundle: %v", id)
}
err = ioutil.WriteFile(fmt.Sprintf("%s/%s_bundle.js", env.webappPath, id), webappBundle, 0644)
diff --git a/plugin/rpcplugin/api.go b/plugin/rpcplugin/api.go
index 5b5b11a62..d87f65b55 100644
--- a/plugin/rpcplugin/api.go
+++ b/plugin/rpcplugin/api.go
@@ -610,4 +610,6 @@ func ConnectAPI(conn io.ReadWriteCloser, muxer *Muxer) *RemoteAPI {
func init() {
gob.Register([]*model.SlackAttachment{})
+ gob.Register([]interface{}{})
+ gob.Register(map[string]interface{}{})
}
diff --git a/plugin/rpcplugin/api_test.go b/plugin/rpcplugin/api_test.go
index 145ec9005..7fe7a0ff9 100644
--- a/plugin/rpcplugin/api_test.go
+++ b/plugin/rpcplugin/api_test.go
@@ -72,11 +72,6 @@ func TestAPI(t *testing.T) {
testPost := &model.Post{
Message: "hello",
- Props: map[string]interface{}{
- "attachments": []*model.SlackAttachment{
- &model.SlackAttachment{},
- },
- },
}
testAPIRPC(&api, func(remote plugin.API) {
@@ -244,3 +239,41 @@ func TestAPI(t *testing.T) {
assert.Nil(t, err)
})
}
+
+func TestAPI_GobRegistration(t *testing.T) {
+ keyValueStore := &plugintest.KeyValueStore{}
+ api := plugintest.API{Store: keyValueStore}
+ defer api.AssertExpectations(t)
+
+ testAPIRPC(&api, func(remote plugin.API) {
+ api.On("CreatePost", mock.AnythingOfType("*model.Post")).Return(func(p *model.Post) (*model.Post, *model.AppError) {
+ p.Id = "thepostid"
+ return p, nil
+ }).Once()
+ _, err := remote.CreatePost(&model.Post{
+ Message: "hello",
+ Props: map[string]interface{}{
+ "attachments": []*model.SlackAttachment{
+ &model.SlackAttachment{
+ Actions: []*model.PostAction{
+ &model.PostAction{
+ Integration: &model.PostActionIntegration{
+ Context: map[string]interface{}{
+ "foo": "bar",
+ "foos": []interface{}{"bar", "baz", 1, 2},
+ "foo_map": map[string]interface{}{
+ "1": "bar",
+ "2": 2,
+ },
+ },
+ },
+ },
+ },
+ Timestamp: 1,
+ },
+ },
+ },
+ })
+ require.Nil(t, err)
+ })
+}
diff --git a/plugin/rpcplugin/sandbox/sandbox_linux.go b/plugin/rpcplugin/sandbox/sandbox_linux.go
index c83572c82..4ade00cf2 100644
--- a/plugin/rpcplugin/sandbox/sandbox_linux.go
+++ b/plugin/rpcplugin/sandbox/sandbox_linux.go
@@ -425,6 +425,15 @@ func checkSupportInNamespace() error {
return errors.Wrapf(err, "unable to enable seccomp filter")
}
+ if f, err := os.Create(os.DevNull); err != nil {
+ return errors.Wrapf(err, "unable to open os.DevNull")
+ } else {
+ defer f.Close()
+ if _, err = f.Write([]byte("foo")); err != nil {
+ return errors.Wrapf(err, "unable to write to os.DevNull")
+ }
+ }
+
return nil
}