From fadd9514f6e71590aba781a7035e1de4150137b0 Mon Sep 17 00:00:00 2001 From: Joram Wilander Date: Wed, 4 Oct 2017 11:42:38 -0400 Subject: PLT-7718 Patch for files (#7564) * Patch for files * Fix merge * Fix tests * Fix another test --- api/file_test.go | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'api') diff --git a/api/file_test.go b/api/file_test.go index 6d6338395..405e3e7d1 100644 --- a/api/file_test.go +++ b/api/file_test.go @@ -24,7 +24,7 @@ import ( ) func TestUploadFile(t *testing.T) { - th := Setup().InitBasic() + th := Setup().InitBasic().InitSystemAdmin() defer th.TearDown() if *utils.Cfg.FileSettings.DriverName == "" { @@ -38,7 +38,9 @@ func TestUploadFile(t *testing.T) { channel := th.BasicChannel var uploadInfo *model.FileInfo - if data, err := readTestFile("test.png"); err != nil { + var data []byte + var err error + if data, err = readTestFile("test.png"); err != nil { t.Fatal(err) } else if resp, err := Client.UploadPostAttachment(data, channel.Id, "test.png"); err != nil { t.Fatal(err) @@ -103,6 +105,22 @@ func TestUploadFile(t *testing.T) { t.Fatalf("file preview should've been saved in %v", expectedPreviewPath) } + if _, err := Client.UploadPostAttachment(data, model.NewId(), "test.png"); err == nil || err.StatusCode != http.StatusForbidden { + t.Fatal("should have failed - bad channel id") + } + + if _, err := Client.UploadPostAttachment(data, "../../junk", "test.png"); err == nil || err.StatusCode != http.StatusForbidden { + t.Fatal("should have failed - bad channel id") + } + + if _, err := th.SystemAdminClient.UploadPostAttachment(data, model.NewId(), "test.png"); err == nil || err.StatusCode != http.StatusForbidden { + t.Fatal("should have failed - bad channel id") + } + + if _, err := th.SystemAdminClient.UploadPostAttachment(data, "../../junk", "test.png"); err == nil || err.StatusCode != http.StatusForbidden { + t.Fatal("should have failed - bad channel id") + } + enableFileAttachments := *utils.Cfg.FileSettings.EnableFileAttachments defer func() { *utils.Cfg.FileSettings.EnableFileAttachments = enableFileAttachments -- cgit v1.2.3-1-g7c22