diff options
author | GitLab Release Tools Bot <delivery-team+release-tools@gitlab.com> | 2023-05-02 09:10:30 +0000 |
---|---|---|
committer | GitLab Release Tools Bot <delivery-team+release-tools@gitlab.com> | 2023-05-02 09:10:30 +0000 |
commit | ea55554522a3f220d5ed9e1a2d22833119f7768f (patch) | |
tree | e7494d54d7b9edfede9bebd3021eb54057854e0f /workhorse/internal/headers/content_headers_test.go | |
parent | 55221b7969b0c2ca237abcdb00675ef9665ef4a2 (diff) | |
parent | 22f3fab9f647bb1ea6e19330b5ca0e877d7ff344 (diff) | |
download | gitlab-ce-ea55554522a3f220d5ed9e1a2d22833119f7768f.tar.gz |
Merge remote-tracking branch 'dev/15-10-stable' into 15-10-stable
Diffstat (limited to 'workhorse/internal/headers/content_headers_test.go')
-rw-r--r-- | workhorse/internal/headers/content_headers_test.go | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/workhorse/internal/headers/content_headers_test.go b/workhorse/internal/headers/content_headers_test.go new file mode 100644 index 00000000000..7cfce335d88 --- /dev/null +++ b/workhorse/internal/headers/content_headers_test.go @@ -0,0 +1,56 @@ +package headers + +import ( + "os" + "testing" + + "github.com/stretchr/testify/require" +) + +func fileContents(fileName string) []byte { + fileContents, _ := os.ReadFile(fileName) + return fileContents +} + +func TestHeaders(t *testing.T) { + tests := []struct { + desc string + fileContents []byte + expectedContentType string + expectedContentDisposition string + }{ + { + desc: "XML file", + fileContents: fileContents("../../testdata/test.xml"), + expectedContentType: "text/plain; charset=utf-8", + expectedContentDisposition: "inline; filename=blob", + }, + { + desc: "XHTML file", + fileContents: fileContents("../../testdata/index.xhtml"), + expectedContentType: "text/plain; charset=utf-8", + expectedContentDisposition: "inline; filename=blob", + }, + { + desc: "svg+xml file", + fileContents: fileContents("../../testdata/xml.svg"), + expectedContentType: "image/svg+xml", + expectedContentDisposition: "attachment", + }, + { + desc: "text file", + fileContents: []byte(`a text file`), + expectedContentType: "text/plain; charset=utf-8", + expectedContentDisposition: "inline", + }, + } + + for _, test := range tests { + t.Run(test.desc, func(t *testing.T) { + contentType, newContentDisposition := SafeContentHeaders(test.fileContents, "") + + require.Equal(t, test.expectedContentType, contentType) + require.Equal(t, test.expectedContentDisposition, newContentDisposition) + }) + } +} |