Channels/api4 testing improvements (#22938)
* api4/post_test: fix missing TearDown * api4/plugin_test: dont test timeout, saving 120s * api4/channel_test: dont try to delete town square * api4/channel_test: check public channel names deterministically * api4/file_test: fix darwin assertions on go files * api4/notify_admin_test: fix expect/actual order * api4/team_test: make TestGetAllTeams deterministic * api4/plugin_test: avoid nested test helpers * api4/post_test: avoid nested test helpers * api4/websocket_test: externalize log buffer * testlib/helper: unset common env * linting issues * simplify TestGetFileHeaders * team_test: leverage ElementsMatch
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
dd2b1db420
Коммит
89f2ebc836
@@ -1093,12 +1093,6 @@ func CheckErrorMessage(tb testing.TB, err error, message string) {
|
|||||||
require.Equalf(tb, message, appError.Message, "incorrect error message, actual: %s, expected: %s", appError.Id, message)
|
require.Equalf(tb, message, appError.Message, "incorrect error message, actual: %s, expected: %s", appError.Id, message)
|
||||||
}
|
}
|
||||||
|
|
||||||
func CheckStartsWith(tb testing.TB, value, prefix, message string) {
|
|
||||||
tb.Helper()
|
|
||||||
|
|
||||||
require.True(tb, strings.HasPrefix(value, prefix), message, value)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Similar to s3.New() but allows initialization of signature v2 or signature v4 client.
|
// Similar to s3.New() but allows initialization of signature v2 or signature v4 client.
|
||||||
// If signV2 input is false, function always returns signature v4.
|
// If signV2 input is false, function always returns signature v4.
|
||||||
//
|
//
|
||||||
|
|||||||
@@ -859,14 +859,23 @@ func TestGetPublicChannelsForTeam(t *testing.T) {
|
|||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Len(t, channels, 4, "wrong path")
|
require.Len(t, channels, 4, "wrong path")
|
||||||
|
|
||||||
for i, c := range channels {
|
var foundPublicChannel1, foundPublicChannel2 bool
|
||||||
|
for _, c := range channels {
|
||||||
// check all channels included are open
|
// check all channels included are open
|
||||||
require.Equal(t, model.ChannelTypeOpen, c.Type, "should include open channel only")
|
require.Equal(t, model.ChannelTypeOpen, c.Type, "should include open channel only")
|
||||||
|
|
||||||
// only check the created 2 public channels
|
// only check the created 2 public channels
|
||||||
require.False(t, i < 2 && !(c.DisplayName == publicChannel1.DisplayName || c.DisplayName == publicChannel2.DisplayName), "should match public channel display name")
|
switch c.DisplayName {
|
||||||
|
case publicChannel1.DisplayName:
|
||||||
|
foundPublicChannel1 = true
|
||||||
|
case publicChannel2.DisplayName:
|
||||||
|
foundPublicChannel2 = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
require.True(t, foundPublicChannel1, "failed to find publicChannel1")
|
||||||
|
require.True(t, foundPublicChannel2, "failed to find publicChannel2")
|
||||||
|
|
||||||
privateChannel := th.CreatePrivateChannel()
|
privateChannel := th.CreatePrivateChannel()
|
||||||
channels, _, err = client.GetPublicChannelsForTeam(team.Id, 0, 100, "")
|
channels, _, err = client.GetPublicChannelsForTeam(team.Id, 0, 100, "")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
@@ -1135,9 +1144,14 @@ func TestGetAllChannels(t *testing.T) {
|
|||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
beforeCount := len(channels)
|
beforeCount := len(channels)
|
||||||
|
|
||||||
firstChannel := channels[0].Channel
|
deletedChannel := channels[0].Channel
|
||||||
|
|
||||||
_, err = client.DeleteChannel(firstChannel.Id)
|
// Never try to delete the default channel
|
||||||
|
if deletedChannel.Name == "town-square" {
|
||||||
|
deletedChannel = channels[1].Channel
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = client.DeleteChannel(deletedChannel.Id)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
channels, _, err = client.GetAllChannels(0, 10000, "")
|
channels, _, err = client.GetAllChannels(0, 10000, "")
|
||||||
@@ -1147,7 +1161,7 @@ func TestGetAllChannels(t *testing.T) {
|
|||||||
}
|
}
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Len(t, channels, beforeCount-1)
|
require.Len(t, channels, beforeCount-1)
|
||||||
require.NotContains(t, ids, firstChannel.Id)
|
require.NotContains(t, ids, deletedChannel.Id)
|
||||||
|
|
||||||
channels, _, err = client.GetAllChannelsIncludeDeleted(0, 10000, "")
|
channels, _, err = client.GetAllChannelsIncludeDeleted(0, 10000, "")
|
||||||
ids = []string{}
|
ids = []string{}
|
||||||
@@ -1156,7 +1170,7 @@ func TestGetAllChannels(t *testing.T) {
|
|||||||
}
|
}
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.True(t, len(channels) > beforeCount)
|
require.True(t, len(channels) > beforeCount)
|
||||||
require.Contains(t, ids, firstChannel.Id)
|
require.Contains(t, ids, deletedChannel.Id)
|
||||||
})
|
})
|
||||||
|
|
||||||
_, resp, err := client.GetAllChannels(0, 20, "")
|
_, resp, err := client.GetAllChannels(0, 20, "")
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ import (
|
|||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
@@ -790,6 +789,12 @@ func TestGetFileHeaders(t *testing.T) {
|
|||||||
t.Skip("skipping because no file driver is enabled")
|
t.Skip("skipping because no file driver is enabled")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CheckStartsWith := func(tb testing.TB, value, prefix, message string) {
|
||||||
|
tb.Helper()
|
||||||
|
|
||||||
|
require.True(tb, strings.HasPrefix(value, prefix), fmt.Sprintf("%s: %s", message, value))
|
||||||
|
}
|
||||||
|
|
||||||
testHeaders := func(data []byte, filename string, expectedContentType string, getInline bool, loadFile bool) func(*testing.T) {
|
testHeaders := func(data []byte, filename string, expectedContentType string, getInline bool, loadFile bool) func(*testing.T) {
|
||||||
return func(t *testing.T) {
|
return func(t *testing.T) {
|
||||||
if loadFile {
|
if loadFile {
|
||||||
@@ -832,11 +837,8 @@ func TestGetFileHeaders(t *testing.T) {
|
|||||||
t.Run("txt", testHeaders(data, "test.txt", "text/plain", false, false))
|
t.Run("txt", testHeaders(data, "test.txt", "text/plain", false, false))
|
||||||
t.Run("html", testHeaders(data, "test.html", "text/plain", false, false))
|
t.Run("html", testHeaders(data, "test.html", "text/plain", false, false))
|
||||||
t.Run("js", testHeaders(data, "test.js", "text/plain", false, false))
|
t.Run("js", testHeaders(data, "test.js", "text/plain", false, false))
|
||||||
if os.Getenv("IS_CI") == "true" {
|
// *.go are categorized differently by different platforms
|
||||||
t.Run("go", testHeaders(data, "test.go", "application/octet-stream", false, false))
|
// t.Run("go", testHeaders(data, "test.go", "text/x-go; charset=utf-8", false, false))
|
||||||
} else if runtime.GOOS == "linux" || runtime.GOOS == "darwin" {
|
|
||||||
t.Run("go", testHeaders(data, "test.go", "text/x-go; charset=utf-8", false, false))
|
|
||||||
}
|
|
||||||
t.Run("zip", testHeaders(data, "test.zip", "application/zip", false, false))
|
t.Run("zip", testHeaders(data, "test.zip", "application/zip", false, false))
|
||||||
// Not every platform can recognize these
|
// Not every platform can recognize these
|
||||||
//t.Run("exe", testHeaders(data, "test.exe", "application/x-ms", false))
|
//t.Run("exe", testHeaders(data, "test.exe", "application/x-ms", false))
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ func TestNotifyAdmin(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
require.Equal(t, err.Error(), ": Unable to save notify data.")
|
require.Equal(t, ": Unable to save notify data.", err.Error())
|
||||||
require.Equal(t, http.StatusInternalServerError, statusCode)
|
require.Equal(t, http.StatusInternalServerError, statusCode)
|
||||||
|
|
||||||
})
|
})
|
||||||
@@ -38,7 +38,7 @@ func TestNotifyAdmin(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
require.Equal(t, err.Error(), ": Unable to save notify data.")
|
require.Equal(t, ": Unable to save notify data.", err.Error())
|
||||||
require.Equal(t, http.StatusInternalServerError, statusCode)
|
require.Equal(t, http.StatusInternalServerError, statusCode)
|
||||||
|
|
||||||
})
|
})
|
||||||
@@ -53,7 +53,7 @@ func TestNotifyAdmin(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
require.Equal(t, err.Error(), ": Unable to save notify data.")
|
require.Equal(t, ": Unable to save notify data.", err.Error())
|
||||||
require.Equal(t, http.StatusInternalServerError, statusCode)
|
require.Equal(t, http.StatusInternalServerError, statusCode)
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -68,7 +68,7 @@ func TestNotifyAdmin(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
require.Equal(t, err.Error(), ": Unable to save notify data.")
|
require.Equal(t, ": Unable to save notify data.", err.Error())
|
||||||
require.Equal(t, http.StatusInternalServerError, statusCode)
|
require.Equal(t, http.StatusInternalServerError, statusCode)
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -90,7 +90,7 @@ func TestNotifyAdmin(t *testing.T) {
|
|||||||
})
|
})
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
|
|
||||||
require.Equal(t, err.Error(), ": Already notified admin")
|
require.Equal(t, ": Already notified admin", err.Error())
|
||||||
require.Equal(t, http.StatusForbidden, statusCode)
|
require.Equal(t, http.StatusForbidden, statusCode)
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -118,7 +118,7 @@ func TestTriggerNotifyAdmin(t *testing.T) {
|
|||||||
statusCode, err := th.SystemAdminClient.TriggerNotifyAdmin(&model.NotifyAdminToUpgradeRequest{})
|
statusCode, err := th.SystemAdminClient.TriggerNotifyAdmin(&model.NotifyAdminToUpgradeRequest{})
|
||||||
|
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
require.Equal(t, err.Error(), ": Internal error during cloud api request.")
|
require.Equal(t, ": Internal error during cloud api request.", err.Error())
|
||||||
require.Equal(t, http.StatusForbidden, statusCode)
|
require.Equal(t, http.StatusForbidden, statusCode)
|
||||||
|
|
||||||
})
|
})
|
||||||
@@ -132,7 +132,7 @@ func TestTriggerNotifyAdmin(t *testing.T) {
|
|||||||
statusCode, err := th.Client.TriggerNotifyAdmin(&model.NotifyAdminToUpgradeRequest{})
|
statusCode, err := th.Client.TriggerNotifyAdmin(&model.NotifyAdminToUpgradeRequest{})
|
||||||
|
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
require.Equal(t, err.Error(), ": You do not have the appropriate permissions.")
|
require.Equal(t, ": You do not have the appropriate permissions.", err.Error())
|
||||||
require.Equal(t, http.StatusForbidden, statusCode)
|
require.Equal(t, http.StatusForbidden, statusCode)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -76,24 +76,6 @@ func TestPlugin(t *testing.T) {
|
|||||||
_, err = client.RemovePlugin(manifest.Id)
|
_, err = client.RemovePlugin(manifest.Id)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
t.Run("install plugin from URL with slow response time", func(t *testing.T) {
|
|
||||||
if testing.Short() {
|
|
||||||
t.Skip("skipping test to install plugin from a slow response server")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Install from URL - slow server to simulate longer bundle download times
|
|
||||||
slowTestServer := httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) {
|
|
||||||
time.Sleep(60 * time.Second) // Wait longer than the previous default 30 seconds timeout
|
|
||||||
res.WriteHeader(http.StatusOK)
|
|
||||||
res.Write(tarData)
|
|
||||||
}))
|
|
||||||
defer func() { slowTestServer.Close() }()
|
|
||||||
|
|
||||||
manifest, _, err = client.InstallPluginFromURL(slowTestServer.URL, true)
|
|
||||||
require.NoError(t, err)
|
|
||||||
assert.Equal(t, "testplugin", manifest.Id)
|
|
||||||
})
|
|
||||||
|
|
||||||
th.App.Channels().RemovePlugin(manifest.Id)
|
th.App.Channels().RemovePlugin(manifest.Id)
|
||||||
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.PluginSettings.Enable = false })
|
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.PluginSettings.Enable = false })
|
||||||
@@ -121,6 +103,7 @@ func TestPlugin(t *testing.T) {
|
|||||||
// Successful upload
|
// Successful upload
|
||||||
manifest, _, err = client.UploadPlugin(bytes.NewReader(tarData))
|
manifest, _, err = client.UploadPlugin(bytes.NewReader(tarData))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
assert.Equal(t, "testplugin", manifest.Id)
|
||||||
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.PluginSettings.EnableUploads = true })
|
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.PluginSettings.EnableUploads = true })
|
||||||
|
|
||||||
@@ -1652,6 +1635,59 @@ func TestInstallMarketplacePlugin(t *testing.T) {
|
|||||||
require.Nil(t, manifest)
|
require.Nil(t, manifest)
|
||||||
assert.True(t, requestHandled)
|
assert.True(t, requestHandled)
|
||||||
}, "verify EnterprisePlugins is true for E20")
|
}, "verify EnterprisePlugins is true for E20")
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestInstallMarketplacePluginPrepackagedDisabled(t *testing.T) {
|
||||||
|
path, _ := fileutils.FindDir("tests")
|
||||||
|
|
||||||
|
signatureFilename := "testplugin2.tar.gz.sig"
|
||||||
|
signatureFileReader, err := os.Open(filepath.Join(path, signatureFilename))
|
||||||
|
require.NoError(t, err)
|
||||||
|
sigFile, err := io.ReadAll(signatureFileReader)
|
||||||
|
require.NoError(t, err)
|
||||||
|
pluginSignature := base64.StdEncoding.EncodeToString(sigFile)
|
||||||
|
|
||||||
|
tarData, err := os.ReadFile(filepath.Join(path, "testplugin2.tar.gz"))
|
||||||
|
require.NoError(t, err)
|
||||||
|
pluginServer := httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) {
|
||||||
|
res.WriteHeader(http.StatusOK)
|
||||||
|
res.Write(tarData)
|
||||||
|
}))
|
||||||
|
defer pluginServer.Close()
|
||||||
|
|
||||||
|
samplePlugins := []*model.MarketplacePlugin{
|
||||||
|
{
|
||||||
|
BaseMarketplacePlugin: &model.BaseMarketplacePlugin{
|
||||||
|
HomepageURL: "https://example.com/mattermost/mattermost-plugin-nps",
|
||||||
|
IconData: "https://example.com/icon.svg",
|
||||||
|
DownloadURL: pluginServer.URL,
|
||||||
|
Manifest: &model.Manifest{
|
||||||
|
Id: "testplugin2",
|
||||||
|
Name: "testplugin2",
|
||||||
|
Description: "a second plugin",
|
||||||
|
Version: "1.2.2",
|
||||||
|
MinServerVersion: "",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
InstalledVersion: "",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
BaseMarketplacePlugin: &model.BaseMarketplacePlugin{
|
||||||
|
HomepageURL: "https://example.com/mattermost/mattermost-plugin-nps",
|
||||||
|
IconData: "https://example.com/icon.svg",
|
||||||
|
DownloadURL: pluginServer.URL,
|
||||||
|
Manifest: &model.Manifest{
|
||||||
|
Id: "testplugin2",
|
||||||
|
Name: "testplugin2",
|
||||||
|
Description: "a second plugin",
|
||||||
|
Version: "1.2.3",
|
||||||
|
MinServerVersion: "",
|
||||||
|
},
|
||||||
|
Signature: pluginSignature,
|
||||||
|
},
|
||||||
|
InstalledVersion: "",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
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"
|
||||||
@@ -1669,13 +1705,13 @@ func TestInstallMarketplacePlugin(t *testing.T) {
|
|||||||
err = testlib.CopyFile(filepath.Join(path, "testplugin.tar.gz.asc"), filepath.Join(prepackagedPluginsDir, "testplugin.tar.gz.sig"))
|
err = testlib.CopyFile(filepath.Join(path, "testplugin.tar.gz.asc"), filepath.Join(prepackagedPluginsDir, "testplugin.tar.gz.sig"))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
th2 := SetupConfig(t, func(cfg *model.Config) {
|
th := 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 th2.TearDown()
|
defer th.TearDown()
|
||||||
|
|
||||||
th2.TestForSystemAdminAndLocal(t, func(t *testing.T, client *model.Client4) {
|
th.TestForSystemAdminAndLocal(t, func(t *testing.T, client *model.Client4) {
|
||||||
pluginSignatureFile, err := os.Open(filepath.Join(path, "testplugin.tar.gz.asc"))
|
pluginSignatureFile, err := os.Open(filepath.Join(path, "testplugin.tar.gz.asc"))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
pluginSignatureData, err := io.ReadAll(pluginSignatureFile)
|
pluginSignatureData, err := io.ReadAll(pluginSignatureFile)
|
||||||
@@ -1683,7 +1719,7 @@ func TestInstallMarketplacePlugin(t *testing.T) {
|
|||||||
|
|
||||||
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)
|
require.NoError(t, err)
|
||||||
appErr := th2.App.AddPublicKey("pub_key", key)
|
appErr := th.App.AddPublicKey("pub_key", key)
|
||||||
require.Nil(t, appErr)
|
require.Nil(t, appErr)
|
||||||
|
|
||||||
testServer := httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) {
|
testServer := httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) {
|
||||||
@@ -1698,14 +1734,14 @@ func TestInstallMarketplacePlugin(t *testing.T) {
|
|||||||
}))
|
}))
|
||||||
defer testServer.Close()
|
defer testServer.Close()
|
||||||
|
|
||||||
th2.App.UpdateConfig(func(cfg *model.Config) {
|
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||||
*cfg.PluginSettings.EnableMarketplace = true
|
*cfg.PluginSettings.EnableMarketplace = true
|
||||||
*cfg.PluginSettings.EnableRemoteMarketplace = false
|
*cfg.PluginSettings.EnableRemoteMarketplace = false
|
||||||
*cfg.PluginSettings.MarketplaceURL = testServer.URL
|
*cfg.PluginSettings.MarketplaceURL = testServer.URL
|
||||||
*cfg.PluginSettings.AllowInsecureDownloadURL = false
|
*cfg.PluginSettings.AllowInsecureDownloadURL = false
|
||||||
})
|
})
|
||||||
|
|
||||||
env := th2.App.GetPluginsEnvironment()
|
env := th.App.GetPluginsEnvironment()
|
||||||
|
|
||||||
pluginsResp, _, err := client.GetPlugins()
|
pluginsResp, _, err := client.GetPlugins()
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
@@ -1751,7 +1787,7 @@ func TestInstallMarketplacePlugin(t *testing.T) {
|
|||||||
require.Nil(t, manifest)
|
require.Nil(t, manifest)
|
||||||
|
|
||||||
// Enable remote marketplace
|
// Enable remote marketplace
|
||||||
th2.App.UpdateConfig(func(cfg *model.Config) {
|
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||||
*cfg.PluginSettings.EnableMarketplace = true
|
*cfg.PluginSettings.EnableMarketplace = true
|
||||||
*cfg.PluginSettings.EnableRemoteMarketplace = true
|
*cfg.PluginSettings.EnableRemoteMarketplace = true
|
||||||
*cfg.PluginSettings.MarketplaceURL = testServer.URL
|
*cfg.PluginSettings.MarketplaceURL = testServer.URL
|
||||||
@@ -1784,12 +1820,12 @@ func TestInstallMarketplacePlugin(t *testing.T) {
|
|||||||
_, err = client.RemovePlugin(manifest2.Id)
|
_, err = client.RemovePlugin(manifest2.Id)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
appErr = th2.App.DeletePublicKey("pub_key")
|
appErr = th.App.DeletePublicKey("pub_key")
|
||||||
require.Nil(t, appErr)
|
require.Nil(t, appErr)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
th.TestForSystemAdminAndLocal(t, func(t *testing.T, client *model.Client4) {
|
t.Run("missing prepackaged and remote plugin signatures", func(t *testing.T) {
|
||||||
prepackagedPluginsDir := "prepackaged_plugins"
|
prepackagedPluginsDir := "prepackaged_plugins"
|
||||||
|
|
||||||
os.RemoveAll(prepackagedPluginsDir)
|
os.RemoveAll(prepackagedPluginsDir)
|
||||||
@@ -1809,70 +1845,72 @@ func TestInstallMarketplacePlugin(t *testing.T) {
|
|||||||
}).InitBasic()
|
}).InitBasic()
|
||||||
defer th.TearDown()
|
defer th.TearDown()
|
||||||
|
|
||||||
key, err := os.Open(filepath.Join(path, "development-private-key.asc"))
|
th.TestForSystemAdminAndLocal(t, func(t *testing.T, client *model.Client4) {
|
||||||
require.NoError(t, err)
|
key, err := os.Open(filepath.Join(path, "development-private-key.asc"))
|
||||||
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)
|
|
||||||
|
|
||||||
mPlugins := []*model.MarketplacePlugin{samplePlugins[0]}
|
|
||||||
require.Empty(t, mPlugins[0].Signature)
|
|
||||||
res.WriteHeader(http.StatusOK)
|
|
||||||
var out []byte
|
|
||||||
out, err = json.Marshal(mPlugins)
|
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
res.Write(out)
|
appErr := th.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 = true
|
require.NotEmpty(t, serverVersion)
|
||||||
*cfg.PluginSettings.MarketplaceURL = testServer.URL
|
require.Equal(t, model.CurrentVersion, serverVersion)
|
||||||
*cfg.PluginSettings.AllowInsecureDownloadURL = true
|
|
||||||
|
mPlugins := []*model.MarketplacePlugin{samplePlugins[0]}
|
||||||
|
require.Empty(t, mPlugins[0].Signature)
|
||||||
|
res.WriteHeader(http.StatusOK)
|
||||||
|
var out []byte
|
||||||
|
out, err = json.Marshal(mPlugins)
|
||||||
|
require.NoError(t, err)
|
||||||
|
res.Write(out)
|
||||||
|
}))
|
||||||
|
defer testServer.Close()
|
||||||
|
|
||||||
|
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||||
|
*cfg.PluginSettings.EnableMarketplace = true
|
||||||
|
*cfg.PluginSettings.EnableRemoteMarketplace = true
|
||||||
|
*cfg.PluginSettings.MarketplaceURL = testServer.URL
|
||||||
|
*cfg.PluginSettings.AllowInsecureDownloadURL = true
|
||||||
|
})
|
||||||
|
|
||||||
|
env := th.App.GetPluginsEnvironment()
|
||||||
|
plugins := env.PrepackagedPlugins()
|
||||||
|
require.Len(t, plugins, 1)
|
||||||
|
require.Equal(t, "testplugin", plugins[0].Manifest.Id)
|
||||||
|
require.Empty(t, plugins[0].Signature)
|
||||||
|
|
||||||
|
pluginsResp, _, err := client.GetPlugins()
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Len(t, pluginsResp.Active, 0)
|
||||||
|
require.Len(t, pluginsResp.Inactive, 0)
|
||||||
|
|
||||||
|
pRequest := &model.InstallMarketplacePluginRequest{Id: "testplugin"}
|
||||||
|
manifest, resp, err := client.InstallMarketplacePlugin(pRequest)
|
||||||
|
require.Error(t, err)
|
||||||
|
CheckInternalErrorStatus(t, resp)
|
||||||
|
require.Nil(t, manifest)
|
||||||
|
|
||||||
|
pluginsResp, _, err = client.GetPlugins()
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Len(t, pluginsResp.Active, 0)
|
||||||
|
require.Len(t, pluginsResp.Inactive, 0)
|
||||||
|
|
||||||
|
pRequest = &model.InstallMarketplacePluginRequest{Id: "testplugin2"}
|
||||||
|
manifest, resp, err = client.InstallMarketplacePlugin(pRequest)
|
||||||
|
require.Error(t, err)
|
||||||
|
CheckInternalErrorStatus(t, resp)
|
||||||
|
require.Nil(t, manifest)
|
||||||
|
|
||||||
|
pluginsResp, _, err = client.GetPlugins()
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Len(t, pluginsResp.Active, 0)
|
||||||
|
require.Len(t, pluginsResp.Inactive, 0)
|
||||||
|
|
||||||
|
// Clean up
|
||||||
|
appErr = th.App.DeletePublicKey("pub_key")
|
||||||
|
require.Nil(t, appErr)
|
||||||
})
|
})
|
||||||
|
})
|
||||||
env := th.App.GetPluginsEnvironment()
|
|
||||||
plugins := env.PrepackagedPlugins()
|
|
||||||
require.Len(t, plugins, 1)
|
|
||||||
require.Equal(t, "testplugin", plugins[0].Manifest.Id)
|
|
||||||
require.Empty(t, plugins[0].Signature)
|
|
||||||
|
|
||||||
pluginsResp, _, err := client.GetPlugins()
|
|
||||||
require.NoError(t, err)
|
|
||||||
require.Len(t, pluginsResp.Active, 0)
|
|
||||||
require.Len(t, pluginsResp.Inactive, 0)
|
|
||||||
|
|
||||||
pRequest := &model.InstallMarketplacePluginRequest{Id: "testplugin"}
|
|
||||||
manifest, resp, err := client.InstallMarketplacePlugin(pRequest)
|
|
||||||
require.Error(t, err)
|
|
||||||
CheckInternalErrorStatus(t, resp)
|
|
||||||
require.Nil(t, manifest)
|
|
||||||
|
|
||||||
pluginsResp, _, err = client.GetPlugins()
|
|
||||||
require.NoError(t, err)
|
|
||||||
require.Len(t, pluginsResp.Active, 0)
|
|
||||||
require.Len(t, pluginsResp.Inactive, 0)
|
|
||||||
|
|
||||||
pRequest = &model.InstallMarketplacePluginRequest{Id: "testplugin2"}
|
|
||||||
manifest, resp, err = client.InstallMarketplacePlugin(pRequest)
|
|
||||||
require.Error(t, err)
|
|
||||||
CheckInternalErrorStatus(t, resp)
|
|
||||||
require.Nil(t, manifest)
|
|
||||||
|
|
||||||
pluginsResp, _, err = client.GetPlugins()
|
|
||||||
require.NoError(t, err)
|
|
||||||
require.Len(t, pluginsResp.Active, 0)
|
|
||||||
require.Len(t, pluginsResp.Inactive, 0)
|
|
||||||
|
|
||||||
// Clean up
|
|
||||||
appErr = th.App.DeletePublicKey("pub_key")
|
|
||||||
require.Nil(t, appErr)
|
|
||||||
}, "missing prepackaged and remote plugin signatures")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func findClusterMessages(event model.ClusterEvent, msgs []*model.ClusterMessage) []*model.ClusterMessage {
|
func findClusterMessages(event model.ClusterEvent, msgs []*model.ClusterMessage) []*model.ClusterMessage {
|
||||||
|
|||||||
@@ -452,32 +452,68 @@ func testCreatePostWithOutgoingHook(
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestCreatePostWithOutgoingHook_form_urlencoded(t *testing.T) {
|
func TestCreatePostWithOutgoingHook_form_urlencoded(t *testing.T) {
|
||||||
testCreatePostWithOutgoingHook(t, "application/x-www-form-urlencoded", "application/x-www-form-urlencoded", "triggerword lorem ipsum", "triggerword", []string{"file_id_1"}, app.TriggerwordsExactMatch, false)
|
t.Run("Case 1", func(t *testing.T) {
|
||||||
testCreatePostWithOutgoingHook(t, "application/x-www-form-urlencoded", "application/x-www-form-urlencoded", "triggerwordaaazzz lorem ipsum", "triggerword", []string{"file_id_1"}, app.TriggerwordsStartsWith, false)
|
testCreatePostWithOutgoingHook(t, "application/x-www-form-urlencoded", "application/x-www-form-urlencoded", "triggerword lorem ipsum", "triggerword", []string{"file_id_1"}, app.TriggerwordsExactMatch, false)
|
||||||
testCreatePostWithOutgoingHook(t, "application/x-www-form-urlencoded", "application/x-www-form-urlencoded", "", "", []string{"file_id_1"}, app.TriggerwordsExactMatch, false)
|
})
|
||||||
testCreatePostWithOutgoingHook(t, "application/x-www-form-urlencoded", "application/x-www-form-urlencoded", "", "", []string{"file_id_1"}, app.TriggerwordsStartsWith, false)
|
t.Run("Case 2", func(t *testing.T) {
|
||||||
testCreatePostWithOutgoingHook(t, "application/x-www-form-urlencoded", "application/x-www-form-urlencoded", "triggerword lorem ipsum", "triggerword", []string{"file_id_1"}, app.TriggerwordsExactMatch, true)
|
testCreatePostWithOutgoingHook(t, "application/x-www-form-urlencoded", "application/x-www-form-urlencoded", "triggerwordaaazzz lorem ipsum", "triggerword", []string{"file_id_1"}, app.TriggerwordsStartsWith, false)
|
||||||
testCreatePostWithOutgoingHook(t, "application/x-www-form-urlencoded", "application/x-www-form-urlencoded", "triggerwordaaazzz lorem ipsum", "triggerword", []string{"file_id_1"}, app.TriggerwordsStartsWith, true)
|
})
|
||||||
|
t.Run("Case 3", func(t *testing.T) {
|
||||||
|
testCreatePostWithOutgoingHook(t, "application/x-www-form-urlencoded", "application/x-www-form-urlencoded", "", "", []string{"file_id_1"}, app.TriggerwordsExactMatch, false)
|
||||||
|
})
|
||||||
|
t.Run("Case 4", func(t *testing.T) {
|
||||||
|
testCreatePostWithOutgoingHook(t, "application/x-www-form-urlencoded", "application/x-www-form-urlencoded", "", "", []string{"file_id_1"}, app.TriggerwordsStartsWith, false)
|
||||||
|
})
|
||||||
|
t.Run("Case 5", func(t *testing.T) {
|
||||||
|
testCreatePostWithOutgoingHook(t, "application/x-www-form-urlencoded", "application/x-www-form-urlencoded", "triggerword lorem ipsum", "triggerword", []string{"file_id_1"}, app.TriggerwordsExactMatch, true)
|
||||||
|
})
|
||||||
|
t.Run("Case 6", func(t *testing.T) {
|
||||||
|
testCreatePostWithOutgoingHook(t, "application/x-www-form-urlencoded", "application/x-www-form-urlencoded", "triggerwordaaazzz lorem ipsum", "triggerword", []string{"file_id_1"}, app.TriggerwordsStartsWith, true)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCreatePostWithOutgoingHook_json(t *testing.T) {
|
func TestCreatePostWithOutgoingHook_json(t *testing.T) {
|
||||||
testCreatePostWithOutgoingHook(t, "application/json", "application/json", "triggerword lorem ipsum", "triggerword", []string{"file_id_1, file_id_2"}, app.TriggerwordsExactMatch, false)
|
t.Run("Case 1", func(t *testing.T) {
|
||||||
testCreatePostWithOutgoingHook(t, "application/json", "application/json", "triggerwordaaazzz lorem ipsum", "triggerword", []string{"file_id_1, file_id_2"}, app.TriggerwordsStartsWith, false)
|
testCreatePostWithOutgoingHook(t, "application/json", "application/json", "triggerword lorem ipsum", "triggerword", []string{"file_id_1, file_id_2"}, app.TriggerwordsExactMatch, false)
|
||||||
testCreatePostWithOutgoingHook(t, "application/json", "application/json", "triggerword lorem ipsum", "", []string{"file_id_1"}, app.TriggerwordsExactMatch, false)
|
})
|
||||||
testCreatePostWithOutgoingHook(t, "application/json", "application/json", "triggerwordaaazzz lorem ipsum", "", []string{"file_id_1"}, app.TriggerwordsStartsWith, false)
|
t.Run("Case 2", func(t *testing.T) {
|
||||||
testCreatePostWithOutgoingHook(t, "application/json", "application/json", "triggerword lorem ipsum", "triggerword", []string{"file_id_1, file_id_2"}, app.TriggerwordsExactMatch, true)
|
testCreatePostWithOutgoingHook(t, "application/json", "application/json", "triggerwordaaazzz lorem ipsum", "triggerword", []string{"file_id_1, file_id_2"}, app.TriggerwordsStartsWith, false)
|
||||||
testCreatePostWithOutgoingHook(t, "application/json", "application/json", "triggerwordaaazzz lorem ipsum", "", []string{"file_id_1"}, app.TriggerwordsStartsWith, true)
|
})
|
||||||
|
t.Run("Case 3", func(t *testing.T) {
|
||||||
|
testCreatePostWithOutgoingHook(t, "application/json", "application/json", "triggerword lorem ipsum", "", []string{"file_id_1"}, app.TriggerwordsExactMatch, false)
|
||||||
|
})
|
||||||
|
t.Run("Case 4", func(t *testing.T) {
|
||||||
|
testCreatePostWithOutgoingHook(t, "application/json", "application/json", "triggerwordaaazzz lorem ipsum", "", []string{"file_id_1"}, app.TriggerwordsStartsWith, false)
|
||||||
|
})
|
||||||
|
t.Run("Case 5", func(t *testing.T) {
|
||||||
|
testCreatePostWithOutgoingHook(t, "application/json", "application/json", "triggerword lorem ipsum", "triggerword", []string{"file_id_1, file_id_2"}, app.TriggerwordsExactMatch, true)
|
||||||
|
})
|
||||||
|
t.Run("Case 6", func(t *testing.T) {
|
||||||
|
testCreatePostWithOutgoingHook(t, "application/json", "application/json", "triggerwordaaazzz lorem ipsum", "", []string{"file_id_1"}, app.TriggerwordsStartsWith, true)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// hooks created before we added the ContentType field should be considered as
|
// hooks created before we added the ContentType field should be considered as
|
||||||
// application/x-www-form-urlencoded
|
// application/x-www-form-urlencoded
|
||||||
func TestCreatePostWithOutgoingHook_no_content_type(t *testing.T) {
|
func TestCreatePostWithOutgoingHook_no_content_type(t *testing.T) {
|
||||||
testCreatePostWithOutgoingHook(t, "", "application/x-www-form-urlencoded", "triggerword lorem ipsum", "triggerword", []string{"file_id_1"}, app.TriggerwordsExactMatch, false)
|
t.Run("Case 1", func(t *testing.T) {
|
||||||
testCreatePostWithOutgoingHook(t, "", "application/x-www-form-urlencoded", "triggerwordaaazzz lorem ipsum", "triggerword", []string{"file_id_1"}, app.TriggerwordsStartsWith, false)
|
testCreatePostWithOutgoingHook(t, "", "application/x-www-form-urlencoded", "triggerword lorem ipsum", "triggerword", []string{"file_id_1"}, app.TriggerwordsExactMatch, false)
|
||||||
testCreatePostWithOutgoingHook(t, "", "application/x-www-form-urlencoded", "triggerword lorem ipsum", "", []string{"file_id_1, file_id_2"}, app.TriggerwordsExactMatch, false)
|
})
|
||||||
testCreatePostWithOutgoingHook(t, "", "application/x-www-form-urlencoded", "triggerwordaaazzz lorem ipsum", "", []string{"file_id_1, file_id_2"}, app.TriggerwordsStartsWith, false)
|
t.Run("Case 2", func(t *testing.T) {
|
||||||
testCreatePostWithOutgoingHook(t, "", "application/x-www-form-urlencoded", "triggerword lorem ipsum", "triggerword", []string{"file_id_1"}, app.TriggerwordsExactMatch, true)
|
testCreatePostWithOutgoingHook(t, "", "application/x-www-form-urlencoded", "triggerwordaaazzz lorem ipsum", "triggerword", []string{"file_id_1"}, app.TriggerwordsStartsWith, false)
|
||||||
testCreatePostWithOutgoingHook(t, "", "application/x-www-form-urlencoded", "triggerword lorem ipsum", "", []string{"file_id_1, file_id_2"}, app.TriggerwordsExactMatch, true)
|
})
|
||||||
|
t.Run("Case 3", func(t *testing.T) {
|
||||||
|
testCreatePostWithOutgoingHook(t, "", "application/x-www-form-urlencoded", "triggerword lorem ipsum", "", []string{"file_id_1, file_id_2"}, app.TriggerwordsExactMatch, false)
|
||||||
|
})
|
||||||
|
t.Run("Case 4", func(t *testing.T) {
|
||||||
|
testCreatePostWithOutgoingHook(t, "", "application/x-www-form-urlencoded", "triggerwordaaazzz lorem ipsum", "", []string{"file_id_1, file_id_2"}, app.TriggerwordsStartsWith, false)
|
||||||
|
})
|
||||||
|
t.Run("Case 5", func(t *testing.T) {
|
||||||
|
testCreatePostWithOutgoingHook(t, "", "application/x-www-form-urlencoded", "triggerword lorem ipsum", "triggerword", []string{"file_id_1"}, app.TriggerwordsExactMatch, true)
|
||||||
|
})
|
||||||
|
t.Run("Case 6", func(t *testing.T) {
|
||||||
|
testCreatePostWithOutgoingHook(t, "", "application/x-www-form-urlencoded", "triggerword lorem ipsum", "", []string{"file_id_1, file_id_2"}, app.TriggerwordsExactMatch, true)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCreatePostPublic(t *testing.T) {
|
func TestCreatePostPublic(t *testing.T) {
|
||||||
@@ -3199,6 +3235,7 @@ func TestGetEditHistoryForPost(t *testing.T) {
|
|||||||
|
|
||||||
func TestCreatePostNotificationsWithCRT(t *testing.T) {
|
func TestCreatePostNotificationsWithCRT(t *testing.T) {
|
||||||
th := Setup(t).InitBasic()
|
th := Setup(t).InitBasic()
|
||||||
|
defer th.TearDown()
|
||||||
rpost := th.CreatePost()
|
rpost := th.CreatePost()
|
||||||
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||||
|
|||||||
@@ -1173,11 +1173,10 @@ func TestGetAllTeams(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var teams []*model.Team
|
var teams []*model.Team
|
||||||
var count int64
|
|
||||||
var resp *model.Response
|
var resp *model.Response
|
||||||
var err2 error
|
var err2 error
|
||||||
if tc.WithCount {
|
if tc.WithCount {
|
||||||
teams, count, resp, err2 = client.GetAllTeamsWithTotalCount("", tc.Page, tc.PerPage)
|
teams, _, resp, err2 = client.GetAllTeamsWithTotalCount("", tc.Page, tc.PerPage)
|
||||||
} else {
|
} else {
|
||||||
teams, resp, err2 = client.GetAllTeams("", tc.Page, tc.PerPage)
|
teams, resp, err2 = client.GetAllTeams("", tc.Page, tc.PerPage)
|
||||||
}
|
}
|
||||||
@@ -1187,11 +1186,12 @@ func TestGetAllTeams(t *testing.T) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
require.NoError(t, err2)
|
require.NoError(t, err2)
|
||||||
require.Equal(t, len(tc.ExpectedTeams), len(teams))
|
|
||||||
for idx, team := range teams {
|
actualTeamIds := make([]string, 0, len(tc.ExpectedTeams))
|
||||||
assert.Equal(t, tc.ExpectedTeams[idx], team.Id)
|
for _, team := range teams {
|
||||||
|
actualTeamIds = append(actualTeamIds, team.Id)
|
||||||
}
|
}
|
||||||
require.Equal(t, tc.ExpectedCount, count)
|
require.ElementsMatch(t, tc.ExpectedTeams, actualTeamIds)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -424,10 +424,14 @@ func TestWebSocketUpgrade(t *testing.T) {
|
|||||||
th := Setup(t)
|
th := Setup(t)
|
||||||
defer th.TearDown()
|
defer th.TearDown()
|
||||||
|
|
||||||
|
buffer := &mlog.Buffer{}
|
||||||
|
err := mlog.AddWriterTarget(th.TestLogger, buffer, true, mlog.StdAll...)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
url := fmt.Sprintf("http://localhost:%v", th.App.Srv().ListenAddr.Port) + model.APIURLSuffix + "/websocket"
|
url := fmt.Sprintf("http://localhost:%v", th.App.Srv().ListenAddr.Port) + model.APIURLSuffix + "/websocket"
|
||||||
resp, err := http.Get(url)
|
resp, err := http.Get(url)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, resp.StatusCode, http.StatusBadRequest)
|
require.Equal(t, resp.StatusCode, http.StatusBadRequest)
|
||||||
require.NoError(t, th.TestLogger.Flush())
|
require.NoError(t, th.TestLogger.Flush())
|
||||||
testlib.AssertLog(t, th.LogBuffer, mlog.LvlDebug.Name, "Failed to upgrade websocket connection.")
|
testlib.AssertLog(t, buffer, mlog.LvlDebug.Name, "Failed to upgrade websocket connection.")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -58,6 +58,11 @@ func NewMainHelperWithOptions(options *HelperOptions) *MainHelper {
|
|||||||
os.Unsetenv("MM_SQLSETTINGS_DATASOURCE")
|
os.Unsetenv("MM_SQLSETTINGS_DATASOURCE")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Unset environment variables commonly set for development that interfere with tests.
|
||||||
|
os.Unsetenv("MM_SERVICESETTINGS_SITEURL")
|
||||||
|
os.Unsetenv("MM_SERVICESETTINGS_LISTENADDRESS")
|
||||||
|
os.Unsetenv("MM_SERVICESETTINGS_ENABLEDEVELOPER")
|
||||||
|
|
||||||
var mainHelper MainHelper
|
var mainHelper MainHelper
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user