1
0
mirror of https://github.com/mattermost/focalboard.git synced 2025-04-07 21:18:42 +02:00

Adding integration tests for the file size limit

This commit is contained in:
Jesús Espino 2022-03-29 15:56:57 +02:00
parent 837859838c
commit 4fe810748f
2 changed files with 76 additions and 0 deletions

View File

@ -285,3 +285,8 @@ func (th *TestHelper) CheckForbidden(r *client.Response) {
require.Equal(th.T, http.StatusForbidden, r.StatusCode)
require.Error(th.T, r.Error)
}
func (th *TestHelper) CheckRequestEntityTooLarge(r *client.Response) {
require.Equal(th.T, http.StatusRequestEntityTooLarge, r.StatusCode)
require.Error(th.T, r.Error)
}

View File

@ -0,0 +1,71 @@
package integrationtests
import (
"bytes"
"testing"
"github.com/mattermost/focalboard/server/model"
"github.com/stretchr/testify/require"
)
func TestUploadFile(t *testing.T) {
const (
testTeamID = "team-id"
)
t.Run("a non authenticated user should be rejected", func(t *testing.T) {
th := SetupTestHelper(t).InitBasic()
defer th.TearDown()
th.Logout(th.Client)
file, resp := th.Client.TeamUploadFile(testTeamID, "test-board-id", bytes.NewBuffer([]byte("test")))
th.CheckUnauthorized(resp)
require.Nil(t, file)
})
t.Run("upload a file to an existing team and board without permissions", func(t *testing.T) {
th := SetupTestHelper(t).InitBasic()
defer th.TearDown()
file, resp := th.Client.TeamUploadFile(testTeamID, "not-valid-board", bytes.NewBuffer([]byte("test")))
th.CheckForbidden(resp)
require.Nil(t, file)
})
t.Run("upload a file to an existing team and board with permissions", func(t *testing.T) {
th := SetupTestHelper(t).InitBasic()
defer th.TearDown()
testBoard := th.CreateBoard(testTeamID, model.BoardTypeOpen)
file, resp := th.Client.TeamUploadFile(testTeamID, testBoard.ID, bytes.NewBuffer([]byte("test")))
th.CheckOK(resp)
require.NoError(t, resp.Error)
require.NotNil(t, file)
require.NotNil(t, file.FileID)
})
t.Run("upload a file to an existing team and board with permissions but reaching the MaxFileLimit", func(t *testing.T) {
th := SetupTestHelper(t).InitBasic()
defer th.TearDown()
testBoard := th.CreateBoard(testTeamID, model.BoardTypeOpen)
config := th.Server.App().GetConfig()
config.MaxFileSize = 1
th.Server.App().SetConfig(config)
file, resp := th.Client.TeamUploadFile(testTeamID, testBoard.ID, bytes.NewBuffer([]byte("test")))
th.CheckRequestEntityTooLarge(resp)
require.Nil(t, file)
config.MaxFileSize = 100000
th.Server.App().SetConfig(config)
file, resp = th.Client.TeamUploadFile(testTeamID, testBoard.ID, bytes.NewBuffer([]byte("test")))
th.CheckOK(resp)
require.NoError(t, resp.Error)
require.NotNil(t, file)
require.NotNil(t, file.FileID)
})
}