snapshot of https://github.com/mattermost/mattermost.git (master, 2026-09-16; blobs > 131072B omitted)
Some checks failed
Server CI / Postgres (shard 0) (push) Has been skipped
Server CI / Postgres (shard 3) (push) Has been skipped
BuildEnv Docker Image / build-image (push) Failing after 4s
BuildEnv Docker Image / build-image-fips (push) Failing after 4s
Migration Review & Release Notes / Generate migration review & release notes (push) Failing after 3s
Server CI / Build Environment (push) Failing after 3s
Server CI / Postgres (shard 1) (push) Has been skipped
Tools CI / check-style (mattermost-govet) (push) Failing after 4s
Server CI / Postgres (shard 2) (push) Has been skipped
Tools CI / check-style (mmgotool) (push) Failing after 3s
Server CI / Elasticsearch v8 Compatibility (push) Has been skipped
Server CI / OpenSearch v2 Compatibility (push) Has been skipped
Server CI / Postgres FIPS (shard 0) (push) Has been skipped
Tools CI / Test (mattermost-govet) (push) Failing after 3s
Server CI / Postgres FIPS (shard 1) (push) Has been skipped
Server CI / Postgres FIPS (shard 2) (push) Has been skipped
Tools CI / Test (mmgotool) (push) Failing after 3s
Server CI / Postgres FIPS (shard 3) (push) Has been skipped
Server CI / Run mmctl tests (push) Has been skipped
Server CI / Run mmctl tests (FIPS) (push) Has been skipped
Server CI / Merge Postgres Test Results (push) Has been skipped
Server CI / Merge Postgres FIPS Test Results (push) Has been skipped
Server CI / Check backport migrations (push) Has been skipped
Server CI / Check generated files (push) Has been skipped
Server CI / check-style (push) Has been skipped
Server CI / Vet API (push) Has been skipped
Server CI / Build mattermost server app (push) Has been skipped
Server CI / Server CI Complete (push) Failing after 2s
Server CI / Server CI Artifacts (push) Has been skipped
Server CI / Sentry Upload (push) Has been skipped
Server CI / Server CI Report (push) Failing after 5m1s
Server CI Nightly Race / Race Detector (push) Has been skipped
CodeQL / Analyze (go) (push) Has been cancelled
CodeQL / Analyze (javascript) (push) Has been cancelled
Webapp CI Cache Warm / Warm Webapp node_modules Cache (push) Has been cancelled
E2E CI Cache Warm / Warm E2E npm Registry Cache (push) Has been cancelled
API / build (push) Has been cancelled
Web App CI / check-types (push) Has been cancelled
Web App CI / check-lint (push) Has been cancelled
Web App CI / check-i18n (push) Has been cancelled
Web App CI / check-external-links (push) Has been cancelled
Web App CI / test (platform) (push) Has been cancelled
Web App CI / test (mattermost-redux) (push) Has been cancelled
Web App CI / test (channels shard 1/4) (push) Has been cancelled
Web App CI / test (channels shard 2/4) (push) Has been cancelled
Web App CI / test (channels shard 3/4) (push) Has been cancelled
Web App CI / test (channels shard 4/4) (push) Has been cancelled
Web App CI / upload-coverage (push) Has been cancelled
Web App CI / build (push) Has been cancelled
YAML Lint / yamllint (push) Has been cancelled
Push mirrored docker images / cd/Push mirrored docker images (push) Has been cancelled
docs-cd / Build and deploy docs (push) Has been cancelled
Docs CI / build (push) Has been cancelled
E2E Cache Warm: Cypress deps / Warm Cypress deps cache (push) Has been cancelled
Scorecards supply-chain security / Scorecard analysis (push) Has been cancelled
Server CI Weekly / Postgres FIPS (push) Has been skipped
Server CI Weekly / Run mmctl tests (FIPS) (push) Has been skipped
Server CI Weekly / Postgres with binary parameters (push) Has been skipped
Server CI Weekly / Build Environment (push) Failing after 1s
Server CI Cache Warm / Warm Go Module and Build Cache (push) Failing after 2s
Server CI Nightly Race / Build Environment (push) Failing after 1s

This commit is contained in:
upstream-mirror
2026-09-16 00:29:55 +05:00
commit 240db4e2a7
15309 changed files with 2173406 additions and 0 deletions

View File

@@ -0,0 +1,184 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package api4
import (
"context"
"os"
"path"
"path/filepath"
"testing"
"time"
"github.com/stretchr/testify/require"
"github.com/mattermost/mattermost/server/public/model"
"github.com/mattermost/mattermost/server/public/shared/mlog"
"github.com/mattermost/mattermost/server/v8/channels/app"
"github.com/mattermost/mattermost/server/v8/channels/utils/fileutils"
)
// Helper function to upload a new import file
func uploadNewImport(th *TestHelper, c *model.Client4, t *testing.T) string {
testsDir, _ := fileutils.FindDir("tests")
require.NotEmpty(t, testsDir)
file, err := os.Open(testsDir + "/import_test.zip")
require.NoError(t, err)
info, err := file.Stat()
require.NoError(t, err)
us := &model.UploadSession{
Filename: info.Name(),
FileSize: info.Size(),
Type: model.UploadTypeImport,
}
if c == th.LocalClient {
us.UserId = model.UploadNoUserID
}
u, _, err := c.CreateUpload(context.Background(), us)
require.NoError(t, err)
require.NotNil(t, u)
finfo, _, err := c.UploadData(context.Background(), u.Id, file)
require.NoError(t, err)
require.NotNil(t, finfo)
return u.Id
}
func TestListImports(t *testing.T) {
mainHelper.Parallel(t)
th := Setup(t)
t.Run("no permissions", func(t *testing.T) {
imports, _, err := th.Client.ListImports(context.Background())
require.Error(t, err)
CheckErrorID(t, err, "api.context.permissions.app_error")
require.Nil(t, imports)
})
dataDir := *th.App.Config().FileSettings.Directory
th.TestForSystemAdminAndLocal(t, func(t *testing.T, c *model.Client4) {
imports, _, err := c.ListImports(context.Background())
require.NoError(t, err)
require.Empty(t, imports)
}, "no imports")
th.TestForSystemAdminAndLocal(t, func(t *testing.T, c *model.Client4) {
id := uploadNewImport(th, c, t)
id2 := uploadNewImport(th, c, t)
importDir := filepath.Join(dataDir, "import")
f, err := os.Create(filepath.Join(importDir, "import.zip.tmp"))
require.NoError(t, err)
f.Close()
imports, _, err := c.ListImports(context.Background())
require.NoError(t, err)
require.NotEmpty(t, imports)
require.Len(t, imports, 2)
require.Contains(t, imports, id+"_import_test.zip")
require.Contains(t, imports, id2+"_import_test.zip")
require.NoError(t, os.RemoveAll(importDir))
}, "expected imports")
th.TestForSystemAdminAndLocal(t, func(t *testing.T, c *model.Client4) {
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ImportSettings.Directory = "import_new" })
defer th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ImportSettings.Directory = "import" })
importDir := filepath.Join(dataDir, "import_new")
imports, _, err := c.ListImports(context.Background())
require.NoError(t, err)
require.Empty(t, imports)
id := uploadNewImport(th, c, t)
imports, _, err = c.ListImports(context.Background())
require.NoError(t, err)
require.NotEmpty(t, imports)
require.Len(t, imports, 1)
require.Equal(t, id+"_import_test.zip", imports[0])
require.NoError(t, os.RemoveAll(importDir))
}, "change import directory")
}
func TestImportInLocalMode(t *testing.T) {
mainHelper.Parallel(t)
th := SetupWithServerOptions(t, []app.Option{app.RunEssentialJobs})
testsDir, _ := fileutils.FindDir("tests")
require.NotEmpty(t, testsDir)
job := &model.Job{
Type: model.JobTypeImportProcess,
Data: map[string]string{
"import_file": path.Join(testsDir, "import_test.zip"),
"local_mode": "true",
},
}
received, _, err := th.SystemAdminClient.CreateJob(context.Background(), job)
require.NoError(t, err)
defer func() {
_, err = th.App.Srv().Store().Job().Delete(received.Id)
require.NoError(t, err, "Failed to delete job")
}()
cnt1, err := th.App.Srv().Store().Post().AnalyticsPostCount(&model.PostCountOptions{UsersPostsOnly: true})
require.NoError(t, err)
var appErr *model.AppError
for !(received.Status == model.JobStatusSuccess || received.Status == model.JobStatusError) {
received, appErr = th.App.GetJob(th.Context, received.Id)
require.Nil(t, appErr)
time.Sleep(5 * time.Second)
th.Context.Logger().Debug("Job status", mlog.String("status", received.Status))
}
require.Equal(t, model.JobStatusSuccess, received.Status)
cnt2, err := th.App.Srv().Store().Post().AnalyticsPostCount(&model.PostCountOptions{UsersPostsOnly: true})
require.NoError(t, err)
// Just a sanity check to ensure new posts are actually added in the system.
require.Greater(t, cnt2, cnt1)
}
func TestDeleteImport(t *testing.T) {
th := Setup(t)
t.Run("no delete permissions", func(t *testing.T) {
response, err := th.Client.DeleteImport(context.Background(), "import_test.zip")
require.Error(t, err)
CheckErrorID(t, err, "api.context.permissions.app_error")
require.Equal(t, 403, response.StatusCode)
})
th.TestForSystemAdminAndLocal(t, func(t *testing.T, c *model.Client4) {
id := uploadNewImport(th, th.SystemAdminClient, t)
id2 := uploadNewImport(th, th.SystemAdminClient, t)
response, delErr := th.SystemAdminClient.DeleteImport(context.Background(), id+"_import_test.zip")
require.Equal(t, 200, response.StatusCode)
require.NoError(t, delErr)
imports, _, err := th.SystemAdminClient.ListImports(context.Background())
require.NoError(t, err)
require.NotEmpty(t, imports)
require.Len(t, imports, 1)
require.Contains(t, imports, id2+"_import_test.zip")
require.NotContains(t, imports, id+"_import_test.zip")
_, err = th.SystemAdminClient.DeleteImport(context.Background(), id2+"_import_test.zip")
require.NoError(t, err)
//idempotency check
_, err = th.SystemAdminClient.DeleteImport(context.Background(), id2+"_import_test.zip")
require.NoError(t, err)
}, "successful deletion")
}