diff options
Diffstat (limited to 'workhorse/internal/headers/content_headers_test.go')
-rw-r--r-- | workhorse/internal/headers/content_headers_test.go | 42 |
1 files changed, 36 insertions, 6 deletions
diff --git a/workhorse/internal/headers/content_headers_test.go b/workhorse/internal/headers/content_headers_test.go index 7cfce335d88..bd329dbc199 100644 --- a/workhorse/internal/headers/content_headers_test.go +++ b/workhorse/internal/headers/content_headers_test.go @@ -13,33 +13,63 @@ func fileContents(fileName string) []byte { } func TestHeaders(t *testing.T) { + xmlFileContents := fileContents("../../testdata/test.xml") + svgFileContents := fileContents("../../testdata/xml.svg") + xhtmlFileContents := fileContents("../../testdata/index.xhtml") + tests := []struct { desc string fileContents []byte + contentDisposition string expectedContentType string expectedContentDisposition string }{ { - desc: "XML file", - fileContents: fileContents("../../testdata/test.xml"), + desc: "inline XML file", + fileContents: xmlFileContents, + contentDisposition: "inline; filename=test.xml", expectedContentType: "text/plain; charset=utf-8", expectedContentDisposition: "inline; filename=blob", }, { - desc: "XHTML file", - fileContents: fileContents("../../testdata/index.xhtml"), + desc: "attachment XML file", + fileContents: xmlFileContents, + contentDisposition: "attachment; filename=test.xml", + expectedContentType: "application/octet-stream", + expectedContentDisposition: "attachment; filename=test.xml", + }, + { + desc: "inline XHTML file", + fileContents: xhtmlFileContents, + contentDisposition: "inline; filename=index.xhtml", expectedContentType: "text/plain; charset=utf-8", expectedContentDisposition: "inline; filename=blob", }, { + desc: "attachment XHTML file", + fileContents: xhtmlFileContents, + contentDisposition: "attachment; filename=index.xhtml", + expectedContentType: "application/octet-stream", + expectedContentDisposition: "attachment; filename=index.xhtml", + }, + { desc: "svg+xml file", - fileContents: fileContents("../../testdata/xml.svg"), + fileContents: svgFileContents, + contentDisposition: "", expectedContentType: "image/svg+xml", expectedContentDisposition: "attachment", }, { + desc: "svg+xml file", + fileContents: svgFileContents, + contentDisposition: "inline; filename=xml.svg", + expectedContentType: "image/svg+xml", + expectedContentDisposition: "attachment; filename=xml.svg", + }, + { desc: "text file", fileContents: []byte(`a text file`), + contentDisposition: "", expectedContentType: "text/plain; charset=utf-8", expectedContentDisposition: "inline", }, @@ -47,7 +77,7 @@ func TestHeaders(t *testing.T) { for _, test := range tests { t.Run(test.desc, func(t *testing.T) { - contentType, newContentDisposition := SafeContentHeaders(test.fileContents, "") + contentType, newContentDisposition := SafeContentHeaders(test.fileContents, test.contentDisposition) require.Equal(t, test.expectedContentType, contentType) require.Equal(t, test.expectedContentDisposition, newContentDisposition) |