[MM-27022] Add marketplace endpoints to local mode (#15053)
* [MM-27022] Add marketplace endpoints to local mode * Fix test Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
94e50c30e3
Коммит
10d2fed795
@@ -10,4 +10,6 @@ func (api *API) InitPluginLocal() {
|
|||||||
api.BaseRoutes.Plugin.Handle("", api.ApiLocal(removePlugin)).Methods("DELETE")
|
api.BaseRoutes.Plugin.Handle("", api.ApiLocal(removePlugin)).Methods("DELETE")
|
||||||
api.BaseRoutes.Plugin.Handle("/enable", api.ApiLocal(enablePlugin)).Methods("POST")
|
api.BaseRoutes.Plugin.Handle("/enable", api.ApiLocal(enablePlugin)).Methods("POST")
|
||||||
api.BaseRoutes.Plugin.Handle("/disable", api.ApiLocal(disablePlugin)).Methods("POST")
|
api.BaseRoutes.Plugin.Handle("/disable", api.ApiLocal(disablePlugin)).Methods("POST")
|
||||||
|
api.BaseRoutes.Plugins.Handle("/marketplace", api.ApiLocal(installMarketplacePlugin)).Methods("POST")
|
||||||
|
api.BaseRoutes.Plugins.Handle("/marketplace", api.ApiLocal(getMarketplacePlugins)).Methods("GET")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -479,27 +479,27 @@ func TestGetMarketplacePlugins(t *testing.T) {
|
|||||||
*cfg.PluginSettings.EnableMarketplace = false
|
*cfg.PluginSettings.EnableMarketplace = false
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("marketplace disabled", func(t *testing.T) {
|
th.TestForSystemAdminAndLocal(t, func(t *testing.T, client *model.Client4) {
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||||
*cfg.PluginSettings.EnableMarketplace = false
|
*cfg.PluginSettings.EnableMarketplace = false
|
||||||
*cfg.PluginSettings.MarketplaceUrl = "invalid.com"
|
*cfg.PluginSettings.MarketplaceUrl = "invalid.com"
|
||||||
})
|
})
|
||||||
|
|
||||||
plugins, resp := th.SystemAdminClient.GetMarketplacePlugins(&model.MarketplacePluginFilter{})
|
plugins, resp := client.GetMarketplacePlugins(&model.MarketplacePluginFilter{})
|
||||||
CheckNotImplementedStatus(t, resp)
|
CheckNotImplementedStatus(t, resp)
|
||||||
require.Nil(t, plugins)
|
require.Nil(t, plugins)
|
||||||
})
|
}, "marketplace disabled")
|
||||||
|
|
||||||
t.Run("no server", func(t *testing.T) {
|
th.TestForSystemAdminAndLocal(t, func(t *testing.T, client *model.Client4) {
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||||
*cfg.PluginSettings.EnableMarketplace = true
|
*cfg.PluginSettings.EnableMarketplace = true
|
||||||
*cfg.PluginSettings.MarketplaceUrl = "invalid.com"
|
*cfg.PluginSettings.MarketplaceUrl = "invalid.com"
|
||||||
})
|
})
|
||||||
|
|
||||||
plugins, resp := th.SystemAdminClient.GetMarketplacePlugins(&model.MarketplacePluginFilter{})
|
plugins, resp := client.GetMarketplacePlugins(&model.MarketplacePluginFilter{})
|
||||||
CheckInternalErrorStatus(t, resp)
|
CheckInternalErrorStatus(t, resp)
|
||||||
require.Nil(t, plugins)
|
require.Nil(t, plugins)
|
||||||
})
|
}, "no server")
|
||||||
|
|
||||||
t.Run("no permission", func(t *testing.T) {
|
t.Run("no permission", func(t *testing.T) {
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||||
@@ -512,7 +512,7 @@ func TestGetMarketplacePlugins(t *testing.T) {
|
|||||||
require.Nil(t, plugins)
|
require.Nil(t, plugins)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("empty response from server", func(t *testing.T) {
|
th.TestForSystemAdminAndLocal(t, func(t *testing.T, client *model.Client4) {
|
||||||
testServer := httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) {
|
testServer := httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) {
|
||||||
res.WriteHeader(http.StatusOK)
|
res.WriteHeader(http.StatusOK)
|
||||||
json, err := json.Marshal([]*model.MarketplacePlugin{})
|
json, err := json.Marshal([]*model.MarketplacePlugin{})
|
||||||
@@ -526,12 +526,12 @@ func TestGetMarketplacePlugins(t *testing.T) {
|
|||||||
*cfg.PluginSettings.MarketplaceUrl = testServer.URL
|
*cfg.PluginSettings.MarketplaceUrl = testServer.URL
|
||||||
})
|
})
|
||||||
|
|
||||||
plugins, resp := th.SystemAdminClient.GetMarketplacePlugins(&model.MarketplacePluginFilter{})
|
plugins, resp := client.GetMarketplacePlugins(&model.MarketplacePluginFilter{})
|
||||||
CheckNoError(t, resp)
|
CheckNoError(t, resp)
|
||||||
require.Empty(t, plugins)
|
require.Empty(t, plugins)
|
||||||
})
|
}, "empty response from server")
|
||||||
|
|
||||||
t.Run("verify server version is passed through", func(t *testing.T) {
|
th.TestForSystemAdminAndLocal(t, func(t *testing.T, client *model.Client4) {
|
||||||
testServer := httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) {
|
testServer := httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) {
|
||||||
serverVersion, ok := req.URL.Query()["server_version"]
|
serverVersion, ok := req.URL.Query()["server_version"]
|
||||||
require.True(t, ok)
|
require.True(t, ok)
|
||||||
@@ -551,12 +551,12 @@ func TestGetMarketplacePlugins(t *testing.T) {
|
|||||||
*cfg.PluginSettings.MarketplaceUrl = testServer.URL
|
*cfg.PluginSettings.MarketplaceUrl = testServer.URL
|
||||||
})
|
})
|
||||||
|
|
||||||
plugins, resp := th.SystemAdminClient.GetMarketplacePlugins(&model.MarketplacePluginFilter{})
|
plugins, resp := client.GetMarketplacePlugins(&model.MarketplacePluginFilter{})
|
||||||
CheckNoError(t, resp)
|
CheckNoError(t, resp)
|
||||||
require.Empty(t, plugins)
|
require.Empty(t, plugins)
|
||||||
})
|
}, "verify server version is passed through")
|
||||||
|
|
||||||
t.Run("verify EnterprisePlugins is false for TE", func(t *testing.T) {
|
th.TestForSystemAdminAndLocal(t, func(t *testing.T, client *model.Client4) {
|
||||||
testServer := httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) {
|
testServer := httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) {
|
||||||
licenseType, ok := req.URL.Query()["enterprise_plugins"]
|
licenseType, ok := req.URL.Query()["enterprise_plugins"]
|
||||||
require.True(t, ok)
|
require.True(t, ok)
|
||||||
@@ -575,12 +575,12 @@ func TestGetMarketplacePlugins(t *testing.T) {
|
|||||||
*cfg.PluginSettings.MarketplaceUrl = testServer.URL
|
*cfg.PluginSettings.MarketplaceUrl = testServer.URL
|
||||||
})
|
})
|
||||||
|
|
||||||
plugins, resp := th.SystemAdminClient.GetMarketplacePlugins(&model.MarketplacePluginFilter{})
|
plugins, resp := client.GetMarketplacePlugins(&model.MarketplacePluginFilter{})
|
||||||
CheckNoError(t, resp)
|
CheckNoError(t, resp)
|
||||||
require.Empty(t, plugins)
|
require.Empty(t, plugins)
|
||||||
})
|
}, "verify EnterprisePlugins is false for TE")
|
||||||
|
|
||||||
t.Run("verify EnterprisePlugins is false for E10", func(t *testing.T) {
|
th.TestForSystemAdminAndLocal(t, func(t *testing.T, client *model.Client4) {
|
||||||
testServer := httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) {
|
testServer := httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) {
|
||||||
licenseType, ok := req.URL.Query()["enterprise_plugins"]
|
licenseType, ok := req.URL.Query()["enterprise_plugins"]
|
||||||
require.True(t, ok)
|
require.True(t, ok)
|
||||||
@@ -604,12 +604,12 @@ func TestGetMarketplacePlugins(t *testing.T) {
|
|||||||
*l.Features.EnterprisePlugins = false
|
*l.Features.EnterprisePlugins = false
|
||||||
th.App.Srv().SetLicense(l)
|
th.App.Srv().SetLicense(l)
|
||||||
|
|
||||||
plugins, resp := th.SystemAdminClient.GetMarketplacePlugins(&model.MarketplacePluginFilter{})
|
plugins, resp := client.GetMarketplacePlugins(&model.MarketplacePluginFilter{})
|
||||||
CheckNoError(t, resp)
|
CheckNoError(t, resp)
|
||||||
require.Empty(t, plugins)
|
require.Empty(t, plugins)
|
||||||
})
|
}, "verify EnterprisePlugins is false for E10")
|
||||||
|
|
||||||
t.Run("verify EnterprisePlugins is false for E20", func(t *testing.T) {
|
th.TestForSystemAdminAndLocal(t, func(t *testing.T, client *model.Client4) {
|
||||||
testServer := httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) {
|
testServer := httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) {
|
||||||
licenseType, ok := req.URL.Query()["enterprise_plugins"]
|
licenseType, ok := req.URL.Query()["enterprise_plugins"]
|
||||||
require.True(t, ok)
|
require.True(t, ok)
|
||||||
@@ -630,10 +630,10 @@ func TestGetMarketplacePlugins(t *testing.T) {
|
|||||||
|
|
||||||
th.App.Srv().SetLicense(model.NewTestLicense("enterprise_plugins"))
|
th.App.Srv().SetLicense(model.NewTestLicense("enterprise_plugins"))
|
||||||
|
|
||||||
plugins, resp := th.SystemAdminClient.GetMarketplacePlugins(&model.MarketplacePluginFilter{})
|
plugins, resp := client.GetMarketplacePlugins(&model.MarketplacePluginFilter{})
|
||||||
CheckNoError(t, resp)
|
CheckNoError(t, resp)
|
||||||
require.Empty(t, plugins)
|
require.Empty(t, plugins)
|
||||||
})
|
}, "verify EnterprisePlugins is false for E20")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetInstalledMarketplacePlugins(t *testing.T) {
|
func TestGetInstalledMarketplacePlugins(t *testing.T) {
|
||||||
@@ -1240,40 +1240,40 @@ func TestInstallMarketplacePlugin(t *testing.T) {
|
|||||||
|
|
||||||
request := &model.InstallMarketplacePluginRequest{Id: "", Version: ""}
|
request := &model.InstallMarketplacePluginRequest{Id: "", Version: ""}
|
||||||
|
|
||||||
t.Run("marketplace disabled", func(t *testing.T) {
|
th.TestForSystemAdminAndLocal(t, func(t *testing.T, client *model.Client4) {
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||||
*cfg.PluginSettings.EnableMarketplace = false
|
*cfg.PluginSettings.EnableMarketplace = false
|
||||||
*cfg.PluginSettings.MarketplaceUrl = "invalid.com"
|
*cfg.PluginSettings.MarketplaceUrl = "invalid.com"
|
||||||
})
|
})
|
||||||
plugin, resp := th.SystemAdminClient.InstallMarketplacePlugin(request)
|
plugin, resp := client.InstallMarketplacePlugin(request)
|
||||||
CheckNotImplementedStatus(t, resp)
|
CheckNotImplementedStatus(t, resp)
|
||||||
require.Nil(t, plugin)
|
require.Nil(t, plugin)
|
||||||
})
|
}, "marketplace disabled")
|
||||||
|
|
||||||
t.Run("RequirePluginSignature enabled", func(t *testing.T) {
|
th.TestForSystemAdminAndLocal(t, func(t *testing.T, client *model.Client4) {
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||||
*cfg.PluginSettings.Enable = true
|
*cfg.PluginSettings.Enable = true
|
||||||
*cfg.PluginSettings.RequirePluginSignature = true
|
*cfg.PluginSettings.RequirePluginSignature = true
|
||||||
})
|
})
|
||||||
manifest, resp := th.SystemAdminClient.UploadPlugin(bytes.NewReader(tarData))
|
manifest, resp := client.UploadPlugin(bytes.NewReader(tarData))
|
||||||
CheckNotImplementedStatus(t, resp)
|
CheckNotImplementedStatus(t, resp)
|
||||||
require.Nil(t, manifest)
|
require.Nil(t, manifest)
|
||||||
|
|
||||||
manifest, resp = th.SystemAdminClient.InstallPluginFromUrl("some_url", true)
|
manifest, resp = client.InstallPluginFromUrl("some_url", true)
|
||||||
CheckNotImplementedStatus(t, resp)
|
CheckNotImplementedStatus(t, resp)
|
||||||
require.Nil(t, manifest)
|
require.Nil(t, manifest)
|
||||||
})
|
}, "RequirePluginSignature enabled")
|
||||||
|
|
||||||
t.Run("no server", func(t *testing.T) {
|
th.TestForSystemAdminAndLocal(t, func(t *testing.T, client *model.Client4) {
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||||
*cfg.PluginSettings.EnableMarketplace = true
|
*cfg.PluginSettings.EnableMarketplace = true
|
||||||
*cfg.PluginSettings.MarketplaceUrl = "invalid.com"
|
*cfg.PluginSettings.MarketplaceUrl = "invalid.com"
|
||||||
})
|
})
|
||||||
|
|
||||||
plugin, resp := th.SystemAdminClient.InstallMarketplacePlugin(request)
|
plugin, resp := client.InstallMarketplacePlugin(request)
|
||||||
CheckInternalErrorStatus(t, resp)
|
CheckInternalErrorStatus(t, resp)
|
||||||
require.Nil(t, plugin)
|
require.Nil(t, plugin)
|
||||||
})
|
}, "no server")
|
||||||
|
|
||||||
t.Run("no permission", func(t *testing.T) {
|
t.Run("no permission", func(t *testing.T) {
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||||
@@ -1286,7 +1286,7 @@ func TestInstallMarketplacePlugin(t *testing.T) {
|
|||||||
require.Nil(t, plugin)
|
require.Nil(t, plugin)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("plugin not found on the server", func(t *testing.T) {
|
th.TestForSystemAdminAndLocal(t, func(t *testing.T, client *model.Client4) {
|
||||||
testServer := httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) {
|
testServer := httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) {
|
||||||
res.WriteHeader(http.StatusOK)
|
res.WriteHeader(http.StatusOK)
|
||||||
json, err := json.Marshal([]*model.MarketplacePlugin{})
|
json, err := json.Marshal([]*model.MarketplacePlugin{})
|
||||||
@@ -1300,12 +1300,12 @@ func TestInstallMarketplacePlugin(t *testing.T) {
|
|||||||
*cfg.PluginSettings.MarketplaceUrl = testServer.URL
|
*cfg.PluginSettings.MarketplaceUrl = testServer.URL
|
||||||
})
|
})
|
||||||
pRequest := &model.InstallMarketplacePluginRequest{Id: "some_plugin_id", Version: "0.0.1"}
|
pRequest := &model.InstallMarketplacePluginRequest{Id: "some_plugin_id", Version: "0.0.1"}
|
||||||
plugin, resp := th.SystemAdminClient.InstallMarketplacePlugin(pRequest)
|
plugin, resp := client.InstallMarketplacePlugin(pRequest)
|
||||||
CheckInternalErrorStatus(t, resp)
|
CheckInternalErrorStatus(t, resp)
|
||||||
require.Nil(t, plugin)
|
require.Nil(t, plugin)
|
||||||
})
|
}, "plugin not found on the server")
|
||||||
|
|
||||||
t.Run("plugin not verified", func(t *testing.T) {
|
th.TestForSystemAdminAndLocal(t, func(t *testing.T, client *model.Client4) {
|
||||||
testServer := httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) {
|
testServer := httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) {
|
||||||
res.WriteHeader(http.StatusOK)
|
res.WriteHeader(http.StatusOK)
|
||||||
json, err := json.Marshal([]*model.MarketplacePlugin{samplePlugins[0]})
|
json, err := json.Marshal([]*model.MarketplacePlugin{samplePlugins[0]})
|
||||||
@@ -1320,12 +1320,12 @@ func TestInstallMarketplacePlugin(t *testing.T) {
|
|||||||
*cfg.PluginSettings.AllowInsecureDownloadUrl = true
|
*cfg.PluginSettings.AllowInsecureDownloadUrl = true
|
||||||
})
|
})
|
||||||
pRequest := &model.InstallMarketplacePluginRequest{Id: "testplugin2", Version: "1.2.2"}
|
pRequest := &model.InstallMarketplacePluginRequest{Id: "testplugin2", Version: "1.2.2"}
|
||||||
plugin, resp := th.SystemAdminClient.InstallMarketplacePlugin(pRequest)
|
plugin, resp := client.InstallMarketplacePlugin(pRequest)
|
||||||
CheckInternalErrorStatus(t, resp)
|
CheckInternalErrorStatus(t, resp)
|
||||||
require.Nil(t, plugin)
|
require.Nil(t, plugin)
|
||||||
})
|
}, "plugin not verified")
|
||||||
|
|
||||||
t.Run("verify, install and remove plugin", func(t *testing.T) {
|
th.TestForSystemAdminAndLocal(t, func(t *testing.T, client *model.Client4) {
|
||||||
testServer := httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) {
|
testServer := httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) {
|
||||||
serverVersion := req.URL.Query().Get("server_version")
|
serverVersion := req.URL.Query().Get("server_version")
|
||||||
require.NotEmpty(t, serverVersion)
|
require.NotEmpty(t, serverVersion)
|
||||||
@@ -1349,7 +1349,7 @@ func TestInstallMarketplacePlugin(t *testing.T) {
|
|||||||
require.Nil(t, appErr)
|
require.Nil(t, appErr)
|
||||||
|
|
||||||
pRequest := &model.InstallMarketplacePluginRequest{Id: "testplugin2", Version: "1.2.3"}
|
pRequest := &model.InstallMarketplacePluginRequest{Id: "testplugin2", Version: "1.2.3"}
|
||||||
manifest, resp := th.SystemAdminClient.InstallMarketplacePlugin(pRequest)
|
manifest, resp := client.InstallMarketplacePlugin(pRequest)
|
||||||
CheckNoError(t, resp)
|
CheckNoError(t, resp)
|
||||||
require.NotNil(t, manifest)
|
require.NotNil(t, manifest)
|
||||||
require.Equal(t, "testplugin2", manifest.Id)
|
require.Equal(t, "testplugin2", manifest.Id)
|
||||||
@@ -1360,7 +1360,7 @@ func TestInstallMarketplacePlugin(t *testing.T) {
|
|||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
require.EqualValues(t, sigFile, savedSigFile)
|
require.EqualValues(t, sigFile, savedSigFile)
|
||||||
|
|
||||||
ok, resp := th.SystemAdminClient.RemovePlugin(manifest.Id)
|
ok, resp := client.RemovePlugin(manifest.Id)
|
||||||
CheckNoError(t, resp)
|
CheckNoError(t, resp)
|
||||||
assert.True(t, ok)
|
assert.True(t, ok)
|
||||||
exists, err := th.App.FileExists(filePath)
|
exists, err := th.App.FileExists(filePath)
|
||||||
@@ -1369,9 +1369,9 @@ func TestInstallMarketplacePlugin(t *testing.T) {
|
|||||||
|
|
||||||
appErr = th.App.DeletePublicKey("pub_key")
|
appErr = th.App.DeletePublicKey("pub_key")
|
||||||
require.Nil(t, appErr)
|
require.Nil(t, appErr)
|
||||||
})
|
}, "verify, install and remove plugin")
|
||||||
|
|
||||||
t.Run("verify EnterprisePlugins is false for TE", func(t *testing.T) {
|
th.TestForSystemAdminAndLocal(t, func(t *testing.T, client *model.Client4) {
|
||||||
requestHandled := false
|
requestHandled := false
|
||||||
|
|
||||||
testServer := httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) {
|
testServer := httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) {
|
||||||
@@ -1398,13 +1398,13 @@ func TestInstallMarketplacePlugin(t *testing.T) {
|
|||||||
|
|
||||||
// The content of the request is irrelevant. This test only cares about enterprise_plugins.
|
// The content of the request is irrelevant. This test only cares about enterprise_plugins.
|
||||||
pRequest := &model.InstallMarketplacePluginRequest{}
|
pRequest := &model.InstallMarketplacePluginRequest{}
|
||||||
manifest, resp := th.SystemAdminClient.InstallMarketplacePlugin(pRequest)
|
manifest, resp := client.InstallMarketplacePlugin(pRequest)
|
||||||
CheckInternalErrorStatus(t, resp)
|
CheckInternalErrorStatus(t, resp)
|
||||||
require.Nil(t, manifest)
|
require.Nil(t, manifest)
|
||||||
assert.True(t, requestHandled)
|
assert.True(t, requestHandled)
|
||||||
})
|
}, "verify EnterprisePlugins is false for TE")
|
||||||
|
|
||||||
t.Run("verify EnterprisePlugins is false for E10", func(t *testing.T) {
|
th.TestForSystemAdminAndLocal(t, func(t *testing.T, client *model.Client4) {
|
||||||
requestHandled := false
|
requestHandled := false
|
||||||
|
|
||||||
testServer := httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) {
|
testServer := httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) {
|
||||||
@@ -1436,13 +1436,13 @@ func TestInstallMarketplacePlugin(t *testing.T) {
|
|||||||
|
|
||||||
// The content of the request is irrelevant. This test only cares about enterprise_plugins.
|
// The content of the request is irrelevant. This test only cares about enterprise_plugins.
|
||||||
pRequest := &model.InstallMarketplacePluginRequest{}
|
pRequest := &model.InstallMarketplacePluginRequest{}
|
||||||
manifest, resp := th.SystemAdminClient.InstallMarketplacePlugin(pRequest)
|
manifest, resp := client.InstallMarketplacePlugin(pRequest)
|
||||||
CheckInternalErrorStatus(t, resp)
|
CheckInternalErrorStatus(t, resp)
|
||||||
require.Nil(t, manifest)
|
require.Nil(t, manifest)
|
||||||
assert.True(t, requestHandled)
|
assert.True(t, requestHandled)
|
||||||
})
|
}, "verify EnterprisePlugins is false for E10")
|
||||||
|
|
||||||
t.Run("verify EnterprisePlugins is true for E20", func(t *testing.T) {
|
th.TestForSystemAdminAndLocal(t, func(t *testing.T, client *model.Client4) {
|
||||||
requestHandled := false
|
requestHandled := false
|
||||||
|
|
||||||
testServer := httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) {
|
testServer := httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) {
|
||||||
@@ -1470,11 +1470,11 @@ func TestInstallMarketplacePlugin(t *testing.T) {
|
|||||||
|
|
||||||
// The content of the request is irrelevant. This test only cares about enterprise_plugins.
|
// The content of the request is irrelevant. This test only cares about enterprise_plugins.
|
||||||
pRequest := &model.InstallMarketplacePluginRequest{}
|
pRequest := &model.InstallMarketplacePluginRequest{}
|
||||||
manifest, resp := th.SystemAdminClient.InstallMarketplacePlugin(pRequest)
|
manifest, resp := client.InstallMarketplacePlugin(pRequest)
|
||||||
CheckInternalErrorStatus(t, resp)
|
CheckInternalErrorStatus(t, resp)
|
||||||
require.Nil(t, manifest)
|
require.Nil(t, manifest)
|
||||||
assert.True(t, requestHandled)
|
assert.True(t, requestHandled)
|
||||||
})
|
}, "verify EnterprisePlugins is true for E20")
|
||||||
|
|
||||||
t.Run("install prepackaged and remote plugins through marketplace", func(t *testing.T) {
|
t.Run("install prepackaged and remote plugins through marketplace", func(t *testing.T) {
|
||||||
prepackagedPluginsDir := "prepackaged_plugins"
|
prepackagedPluginsDir := "prepackaged_plugins"
|
||||||
@@ -1492,124 +1492,126 @@ func TestInstallMarketplacePlugin(t *testing.T) {
|
|||||||
err = utils.CopyFile(filepath.Join(path, "testplugin.tar.gz.asc"), filepath.Join(prepackagedPluginsDir, "testplugin.tar.gz.sig"))
|
err = utils.CopyFile(filepath.Join(path, "testplugin.tar.gz.asc"), filepath.Join(prepackagedPluginsDir, "testplugin.tar.gz.sig"))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
th := SetupConfig(t, func(cfg *model.Config) {
|
th2 := SetupConfig(t, func(cfg *model.Config) {
|
||||||
// Disable auto-installing prepackaged plugins
|
// Disable auto-installing prepackaged plugins
|
||||||
*cfg.PluginSettings.AutomaticPrepackagedPlugins = false
|
*cfg.PluginSettings.AutomaticPrepackagedPlugins = false
|
||||||
}).InitBasic()
|
}).InitBasic()
|
||||||
defer th.TearDown()
|
defer th2.TearDown()
|
||||||
|
|
||||||
pluginSignatureFile, err := os.Open(filepath.Join(path, "testplugin.tar.gz.asc"))
|
th2.TestForSystemAdminAndLocal(t, func(t *testing.T, client *model.Client4) {
|
||||||
require.Nil(t, err)
|
pluginSignatureFile, err := os.Open(filepath.Join(path, "testplugin.tar.gz.asc"))
|
||||||
pluginSignatureData, err := ioutil.ReadAll(pluginSignatureFile)
|
require.Nil(t, err)
|
||||||
require.Nil(t, err)
|
pluginSignatureData, err := ioutil.ReadAll(pluginSignatureFile)
|
||||||
|
require.Nil(t, err)
|
||||||
|
|
||||||
key, err := os.Open(filepath.Join(path, "development-private-key.asc"))
|
key, err := os.Open(filepath.Join(path, "development-private-key.asc"))
|
||||||
require.NoError(t, err)
|
|
||||||
appErr := th.App.AddPublicKey("pub_key", key)
|
|
||||||
require.Nil(t, appErr)
|
|
||||||
|
|
||||||
testServer := httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) {
|
|
||||||
serverVersion := req.URL.Query().Get("server_version")
|
|
||||||
require.NotEmpty(t, serverVersion)
|
|
||||||
require.Equal(t, model.CurrentVersion, serverVersion)
|
|
||||||
res.WriteHeader(http.StatusOK)
|
|
||||||
json, err := json.Marshal([]*model.MarketplacePlugin{samplePlugins[1]})
|
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
res.Write(json)
|
appErr := th2.App.AddPublicKey("pub_key", key)
|
||||||
}))
|
require.Nil(t, appErr)
|
||||||
defer testServer.Close()
|
|
||||||
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
testServer := httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) {
|
||||||
*cfg.PluginSettings.EnableMarketplace = true
|
serverVersion := req.URL.Query().Get("server_version")
|
||||||
*cfg.PluginSettings.EnableRemoteMarketplace = false
|
require.NotEmpty(t, serverVersion)
|
||||||
*cfg.PluginSettings.MarketplaceUrl = testServer.URL
|
require.Equal(t, model.CurrentVersion, serverVersion)
|
||||||
*cfg.PluginSettings.AllowInsecureDownloadUrl = false
|
res.WriteHeader(http.StatusOK)
|
||||||
})
|
json, err := json.Marshal([]*model.MarketplacePlugin{samplePlugins[1]})
|
||||||
|
require.NoError(t, err)
|
||||||
|
res.Write(json)
|
||||||
|
}))
|
||||||
|
defer testServer.Close()
|
||||||
|
|
||||||
env := th.App.GetPluginsEnvironment()
|
th2.App.UpdateConfig(func(cfg *model.Config) {
|
||||||
|
*cfg.PluginSettings.EnableMarketplace = true
|
||||||
|
*cfg.PluginSettings.EnableRemoteMarketplace = false
|
||||||
|
*cfg.PluginSettings.MarketplaceUrl = testServer.URL
|
||||||
|
*cfg.PluginSettings.AllowInsecureDownloadUrl = false
|
||||||
|
})
|
||||||
|
|
||||||
pluginsResp, resp := th.SystemAdminClient.GetPlugins()
|
env := th2.App.GetPluginsEnvironment()
|
||||||
CheckNoError(t, resp)
|
|
||||||
require.Len(t, pluginsResp.Active, 0)
|
|
||||||
require.Len(t, pluginsResp.Inactive, 0)
|
|
||||||
|
|
||||||
// Should fail to install unknown prepackaged plugin
|
pluginsResp, resp := client.GetPlugins()
|
||||||
pRequest := &model.InstallMarketplacePluginRequest{Id: "testplugin", Version: "0.0.2"}
|
CheckNoError(t, resp)
|
||||||
manifest, resp := th.SystemAdminClient.InstallMarketplacePlugin(pRequest)
|
require.Len(t, pluginsResp.Active, 0)
|
||||||
CheckInternalErrorStatus(t, resp)
|
require.Len(t, pluginsResp.Inactive, 0)
|
||||||
require.Nil(t, manifest)
|
|
||||||
|
|
||||||
plugins := env.PrepackagedPlugins()
|
// Should fail to install unknown prepackaged plugin
|
||||||
require.Len(t, plugins, 1)
|
pRequest := &model.InstallMarketplacePluginRequest{Id: "testplugin", Version: "0.0.2"}
|
||||||
require.Equal(t, "testplugin", plugins[0].Manifest.Id)
|
manifest, resp := client.InstallMarketplacePlugin(pRequest)
|
||||||
require.Equal(t, pluginSignatureData, plugins[0].Signature)
|
CheckInternalErrorStatus(t, resp)
|
||||||
|
require.Nil(t, manifest)
|
||||||
|
|
||||||
pluginsResp, resp = th.SystemAdminClient.GetPlugins()
|
plugins := env.PrepackagedPlugins()
|
||||||
CheckNoError(t, resp)
|
require.Len(t, plugins, 1)
|
||||||
require.Len(t, pluginsResp.Active, 0)
|
require.Equal(t, "testplugin", plugins[0].Manifest.Id)
|
||||||
require.Len(t, pluginsResp.Inactive, 0)
|
require.Equal(t, pluginSignatureData, plugins[0].Signature)
|
||||||
|
|
||||||
pRequest = &model.InstallMarketplacePluginRequest{Id: "testplugin", Version: "0.0.1"}
|
pluginsResp, resp = client.GetPlugins()
|
||||||
manifest1, resp := th.SystemAdminClient.InstallMarketplacePlugin(pRequest)
|
CheckNoError(t, resp)
|
||||||
CheckNoError(t, resp)
|
require.Len(t, pluginsResp.Active, 0)
|
||||||
require.NotNil(t, manifest1)
|
require.Len(t, pluginsResp.Inactive, 0)
|
||||||
require.Equal(t, "testplugin", manifest1.Id)
|
|
||||||
require.Equal(t, "0.0.1", manifest1.Version)
|
|
||||||
|
|
||||||
pluginsResp, resp = th.SystemAdminClient.GetPlugins()
|
pRequest = &model.InstallMarketplacePluginRequest{Id: "testplugin", Version: "0.0.1"}
|
||||||
CheckNoError(t, resp)
|
manifest1, resp := client.InstallMarketplacePlugin(pRequest)
|
||||||
require.Len(t, pluginsResp.Active, 0)
|
CheckNoError(t, resp)
|
||||||
require.Equal(t, pluginsResp.Inactive, []*model.PluginInfo{{
|
require.NotNil(t, manifest1)
|
||||||
Manifest: *manifest1,
|
require.Equal(t, "testplugin", manifest1.Id)
|
||||||
}})
|
require.Equal(t, "0.0.1", manifest1.Version)
|
||||||
|
|
||||||
// Try to install remote marketplace plugin
|
pluginsResp, resp = client.GetPlugins()
|
||||||
pRequest = &model.InstallMarketplacePluginRequest{Id: "testplugin2", Version: "1.2.3"}
|
CheckNoError(t, resp)
|
||||||
manifest, resp = th.SystemAdminClient.InstallMarketplacePlugin(pRequest)
|
require.Len(t, pluginsResp.Active, 0)
|
||||||
CheckInternalErrorStatus(t, resp)
|
require.Equal(t, pluginsResp.Inactive, []*model.PluginInfo{{
|
||||||
require.Nil(t, manifest)
|
|
||||||
|
|
||||||
// Enable remote marketplace
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
|
||||||
*cfg.PluginSettings.EnableMarketplace = true
|
|
||||||
*cfg.PluginSettings.EnableRemoteMarketplace = true
|
|
||||||
*cfg.PluginSettings.MarketplaceUrl = testServer.URL
|
|
||||||
*cfg.PluginSettings.AllowInsecureDownloadUrl = true
|
|
||||||
})
|
|
||||||
|
|
||||||
pRequest = &model.InstallMarketplacePluginRequest{Id: "testplugin2", Version: "1.2.3"}
|
|
||||||
manifest2, resp := th.SystemAdminClient.InstallMarketplacePlugin(pRequest)
|
|
||||||
CheckNoError(t, resp)
|
|
||||||
require.NotNil(t, manifest2)
|
|
||||||
require.Equal(t, "testplugin2", manifest2.Id)
|
|
||||||
require.Equal(t, "1.2.3", manifest2.Version)
|
|
||||||
|
|
||||||
pluginsResp, resp = th.SystemAdminClient.GetPlugins()
|
|
||||||
CheckNoError(t, resp)
|
|
||||||
require.Len(t, pluginsResp.Active, 0)
|
|
||||||
require.ElementsMatch(t, pluginsResp.Inactive, []*model.PluginInfo{
|
|
||||||
{
|
|
||||||
Manifest: *manifest1,
|
Manifest: *manifest1,
|
||||||
},
|
}})
|
||||||
{
|
|
||||||
Manifest: *manifest2,
|
// Try to install remote marketplace plugin
|
||||||
},
|
pRequest = &model.InstallMarketplacePluginRequest{Id: "testplugin2", Version: "1.2.3"}
|
||||||
|
manifest, resp = client.InstallMarketplacePlugin(pRequest)
|
||||||
|
CheckInternalErrorStatus(t, resp)
|
||||||
|
require.Nil(t, manifest)
|
||||||
|
|
||||||
|
// Enable remote marketplace
|
||||||
|
th2.App.UpdateConfig(func(cfg *model.Config) {
|
||||||
|
*cfg.PluginSettings.EnableMarketplace = true
|
||||||
|
*cfg.PluginSettings.EnableRemoteMarketplace = true
|
||||||
|
*cfg.PluginSettings.MarketplaceUrl = testServer.URL
|
||||||
|
*cfg.PluginSettings.AllowInsecureDownloadUrl = true
|
||||||
|
})
|
||||||
|
|
||||||
|
pRequest = &model.InstallMarketplacePluginRequest{Id: "testplugin2", Version: "1.2.3"}
|
||||||
|
manifest2, resp := client.InstallMarketplacePlugin(pRequest)
|
||||||
|
CheckNoError(t, resp)
|
||||||
|
require.NotNil(t, manifest2)
|
||||||
|
require.Equal(t, "testplugin2", manifest2.Id)
|
||||||
|
require.Equal(t, "1.2.3", manifest2.Version)
|
||||||
|
|
||||||
|
pluginsResp, resp = client.GetPlugins()
|
||||||
|
CheckNoError(t, resp)
|
||||||
|
require.Len(t, pluginsResp.Active, 0)
|
||||||
|
require.ElementsMatch(t, pluginsResp.Inactive, []*model.PluginInfo{
|
||||||
|
{
|
||||||
|
Manifest: *manifest1,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Manifest: *manifest2,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
// Clean up
|
||||||
|
ok, resp := client.RemovePlugin(manifest1.Id)
|
||||||
|
CheckNoError(t, resp)
|
||||||
|
assert.True(t, ok)
|
||||||
|
|
||||||
|
ok, resp = client.RemovePlugin(manifest2.Id)
|
||||||
|
CheckNoError(t, resp)
|
||||||
|
assert.True(t, ok)
|
||||||
|
|
||||||
|
appErr = th2.App.DeletePublicKey("pub_key")
|
||||||
|
require.Nil(t, appErr)
|
||||||
})
|
})
|
||||||
|
|
||||||
// Clean up
|
|
||||||
ok, resp := th.SystemAdminClient.RemovePlugin(manifest1.Id)
|
|
||||||
CheckNoError(t, resp)
|
|
||||||
assert.True(t, ok)
|
|
||||||
|
|
||||||
ok, resp = th.SystemAdminClient.RemovePlugin(manifest2.Id)
|
|
||||||
CheckNoError(t, resp)
|
|
||||||
assert.True(t, ok)
|
|
||||||
|
|
||||||
appErr = th.App.DeletePublicKey("pub_key")
|
|
||||||
require.Nil(t, appErr)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("missing prepackaged and remote plugin signatures", func(t *testing.T) {
|
th.TestForSystemAdminAndLocal(t, func(t *testing.T, client *model.Client4) {
|
||||||
prepackagedPluginsDir := "prepackaged_plugins"
|
prepackagedPluginsDir := "prepackaged_plugins"
|
||||||
|
|
||||||
os.RemoveAll(prepackagedPluginsDir)
|
os.RemoveAll(prepackagedPluginsDir)
|
||||||
@@ -1661,27 +1663,27 @@ func TestInstallMarketplacePlugin(t *testing.T) {
|
|||||||
require.Equal(t, "testplugin", plugins[0].Manifest.Id)
|
require.Equal(t, "testplugin", plugins[0].Manifest.Id)
|
||||||
require.Empty(t, plugins[0].Signature)
|
require.Empty(t, plugins[0].Signature)
|
||||||
|
|
||||||
pluginsResp, resp := th.SystemAdminClient.GetPlugins()
|
pluginsResp, resp := client.GetPlugins()
|
||||||
CheckNoError(t, resp)
|
CheckNoError(t, resp)
|
||||||
require.Len(t, pluginsResp.Active, 0)
|
require.Len(t, pluginsResp.Active, 0)
|
||||||
require.Len(t, pluginsResp.Inactive, 0)
|
require.Len(t, pluginsResp.Inactive, 0)
|
||||||
|
|
||||||
pRequest := &model.InstallMarketplacePluginRequest{Id: "testplugin", Version: "0.0.1"}
|
pRequest := &model.InstallMarketplacePluginRequest{Id: "testplugin", Version: "0.0.1"}
|
||||||
manifest, resp := th.SystemAdminClient.InstallMarketplacePlugin(pRequest)
|
manifest, resp := client.InstallMarketplacePlugin(pRequest)
|
||||||
CheckInternalErrorStatus(t, resp)
|
CheckInternalErrorStatus(t, resp)
|
||||||
require.Nil(t, manifest)
|
require.Nil(t, manifest)
|
||||||
|
|
||||||
pluginsResp, resp = th.SystemAdminClient.GetPlugins()
|
pluginsResp, resp = client.GetPlugins()
|
||||||
CheckNoError(t, resp)
|
CheckNoError(t, resp)
|
||||||
require.Len(t, pluginsResp.Active, 0)
|
require.Len(t, pluginsResp.Active, 0)
|
||||||
require.Len(t, pluginsResp.Inactive, 0)
|
require.Len(t, pluginsResp.Inactive, 0)
|
||||||
|
|
||||||
pRequest = &model.InstallMarketplacePluginRequest{Id: "testplugin2", Version: "1.2.3"}
|
pRequest = &model.InstallMarketplacePluginRequest{Id: "testplugin2", Version: "1.2.3"}
|
||||||
manifest, resp = th.SystemAdminClient.InstallMarketplacePlugin(pRequest)
|
manifest, resp = client.InstallMarketplacePlugin(pRequest)
|
||||||
CheckInternalErrorStatus(t, resp)
|
CheckInternalErrorStatus(t, resp)
|
||||||
require.Nil(t, manifest)
|
require.Nil(t, manifest)
|
||||||
|
|
||||||
pluginsResp, resp = th.SystemAdminClient.GetPlugins()
|
pluginsResp, resp = client.GetPlugins()
|
||||||
CheckNoError(t, resp)
|
CheckNoError(t, resp)
|
||||||
require.Len(t, pluginsResp.Active, 0)
|
require.Len(t, pluginsResp.Active, 0)
|
||||||
require.Len(t, pluginsResp.Inactive, 0)
|
require.Len(t, pluginsResp.Inactive, 0)
|
||||||
@@ -1689,7 +1691,7 @@ func TestInstallMarketplacePlugin(t *testing.T) {
|
|||||||
// Clean up
|
// Clean up
|
||||||
appErr = th.App.DeletePublicKey("pub_key")
|
appErr = th.App.DeletePublicKey("pub_key")
|
||||||
require.Nil(t, appErr)
|
require.Nil(t, appErr)
|
||||||
})
|
}, "missing prepackaged and remote plugin signatures")
|
||||||
}
|
}
|
||||||
|
|
||||||
func findClusterMessages(event string, msgs []*model.ClusterMessage) []*model.ClusterMessage {
|
func findClusterMessages(event string, msgs []*model.ClusterMessage) []*model.ClusterMessage {
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user