From 0c0bc01432e8db3535a39cfb209261320bfbb23f Mon Sep 17 00:00:00 2001 From: Marius Date: Thu, 13 Oct 2016 19:03:18 +0200 Subject: [PATCH] Add tests for various invalid header values --- concat_test.go | 16 ++++++++++++++++ patch_test.go | 36 ++++++++++++++++++++++++++++++++++++ post_test.go | 16 ++++++++++++++++ 3 files changed, 68 insertions(+) diff --git a/concat_test.go b/concat_test.go index 03fbaf3..8cfd138 100644 --- a/concat_test.go +++ b/concat_test.go @@ -229,5 +229,21 @@ func TestConcat(t *testing.T) { Code: http.StatusForbidden, }).Run(handler, t) }) + + SubTest(t, "InvalidConcatHeaderFail", func(t *testing.T, store *MockFullDataStore) { + handler, _ := NewHandler(Config{ + DataStore: store, + }) + + (&httpTest{ + Method: "POST", + URL: "", + ReqHeader: map[string]string{ + "Tus-Resumable": "1.0.0", + "Upload-Concat": "final; ", + }, + Code: http.StatusBadRequest, + }).Run(handler, t) + }) }) } diff --git a/patch_test.go b/patch_test.go index 48c8598..d84b518 100644 --- a/patch_test.go +++ b/patch_test.go @@ -175,6 +175,42 @@ func TestPatch(t *testing.T) { }).Run(handler, t) }) + SubTest(t, "InvalidContentTypeFail", func(t *testing.T, store *MockFullDataStore) { + handler, _ := NewHandler(Config{ + DataStore: store, + }) + + (&httpTest{ + Method: "PATCH", + URL: "yes", + ReqHeader: map[string]string{ + "Tus-Resumable": "1.0.0", + "Content-Type": "application/fail", + "Upload-Offset": "5", + }, + ReqBody: strings.NewReader("hellothisismorethan15bytes"), + Code: http.StatusBadRequest, + }).Run(handler, t) + }) + + SubTest(t, "InvalidOffsetFail", func(t *testing.T, store *MockFullDataStore) { + handler, _ := NewHandler(Config{ + DataStore: store, + }) + + (&httpTest{ + Method: "PATCH", + URL: "yes", + ReqHeader: map[string]string{ + "Tus-Resumable": "1.0.0", + "Content-Type": "application/offset+octet-stream", + "Upload-Offset": "-5", + }, + ReqBody: strings.NewReader("hellothisismorethan15bytes"), + Code: http.StatusBadRequest, + }).Run(handler, t) + }) + SubTest(t, "OverflowWithoutLength", func(t *testing.T, store *MockFullDataStore) { // In this test we attempt to upload more than 15 bytes to an upload // which has only space for 15 bytes (offset of 5 and size of 20). diff --git a/post_test.go b/post_test.go index c5ccef7..901f5fb 100644 --- a/post_test.go +++ b/post_test.go @@ -60,6 +60,22 @@ func TestPost(t *testing.T) { }).Run(handler, t) }) + SubTest(t, "InvalidUploadLengthFail", func(t *testing.T, store *MockFullDataStore) { + handler, _ := NewHandler(Config{ + DataStore: store, + }) + + (&httpTest{ + Method: "POST", + URL: "", + ReqHeader: map[string]string{ + "Tus-Resumable": "1.0.0", + "Upload-Length": "-5", + }, + Code: http.StatusBadRequest, + }).Run(handler, t) + }) + SubTest(t, "ForwardHeaders", func(t *testing.T, store *MockFullDataStore) { SubTest(t, "IgnoreXForwarded", func(t *testing.T, store *MockFullDataStore) { store.EXPECT().NewUpload(FileInfo{