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:
parent
837859838c
commit
4fe810748f
@ -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)
|
||||
}
|
||||
|
71
server/integrationtests/file_test.go
Normal file
71
server/integrationtests/file_test.go
Normal 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)
|
||||
})
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user