added content-type serving exception tests
This commit is contained in:
@@ -459,7 +459,7 @@ func (s *System) Serve(res http.ResponseWriter, req *http.Request, fileKey strin
|
|||||||
// make an exception for specific content types and force a custom
|
// make an exception for specific content types and force a custom
|
||||||
// content type to send in the response so that it can be loaded properly
|
// content type to send in the response so that it can be loaded properly
|
||||||
extContentType := realContentType
|
extContentType := realContentType
|
||||||
if ct, found := manualExtensionContentTypes[filepath.Ext(name)]; found {
|
if ct, found := manualExtensionContentTypes[filepath.Ext(fileKey)]; found {
|
||||||
extContentType = ct
|
extContentType = ct
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -405,12 +405,12 @@ func TestFileSystemServe(t *testing.T) {
|
|||||||
{
|
{
|
||||||
// svg exception
|
// svg exception
|
||||||
"image.svg",
|
"image.svg",
|
||||||
"test_name.svg",
|
"test_name.abc",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
false,
|
false,
|
||||||
map[string]string{
|
map[string]string{
|
||||||
"Content-Disposition": "attachment; filename=test_name.svg",
|
"Content-Disposition": "attachment; filename=test_name.abc",
|
||||||
"Content-Type": "image/svg+xml",
|
"Content-Type": "image/svg+xml",
|
||||||
"Content-Length": "0",
|
"Content-Length": "0",
|
||||||
"Content-Security-Policy": csp,
|
"Content-Security-Policy": csp,
|
||||||
@@ -420,12 +420,12 @@ func TestFileSystemServe(t *testing.T) {
|
|||||||
{
|
{
|
||||||
// css exception
|
// css exception
|
||||||
"style.css",
|
"style.css",
|
||||||
"test_name.css",
|
"test_name",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
false,
|
false,
|
||||||
map[string]string{
|
map[string]string{
|
||||||
"Content-Disposition": "attachment; filename=test_name.css",
|
"Content-Disposition": "attachment; filename=test_name",
|
||||||
"Content-Type": "text/css",
|
"Content-Type": "text/css",
|
||||||
"Content-Length": "0",
|
"Content-Length": "0",
|
||||||
"Content-Security-Policy": csp,
|
"Content-Security-Policy": csp,
|
||||||
@@ -435,12 +435,12 @@ func TestFileSystemServe(t *testing.T) {
|
|||||||
{
|
{
|
||||||
// js exception
|
// js exception
|
||||||
"main.js",
|
"main.js",
|
||||||
"test_name.js",
|
"test_name.abc",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
false,
|
false,
|
||||||
map[string]string{
|
map[string]string{
|
||||||
"Content-Disposition": "attachment; filename=test_name.js",
|
"Content-Disposition": "attachment; filename=test_name.abc",
|
||||||
"Content-Type": "text/javascript",
|
"Content-Type": "text/javascript",
|
||||||
"Content-Length": "0",
|
"Content-Length": "0",
|
||||||
"Content-Security-Policy": csp,
|
"Content-Security-Policy": csp,
|
||||||
@@ -450,18 +450,63 @@ func TestFileSystemServe(t *testing.T) {
|
|||||||
{
|
{
|
||||||
// mjs exception
|
// mjs exception
|
||||||
"main.mjs",
|
"main.mjs",
|
||||||
"test_name.mjs",
|
"test_name.abc",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
false,
|
false,
|
||||||
map[string]string{
|
map[string]string{
|
||||||
"Content-Disposition": "attachment; filename=test_name.mjs",
|
"Content-Disposition": "attachment; filename=test_name.abc",
|
||||||
"Content-Type": "text/javascript",
|
"Content-Type": "text/javascript",
|
||||||
"Content-Length": "0",
|
"Content-Length": "0",
|
||||||
"Content-Security-Policy": csp,
|
"Content-Security-Policy": csp,
|
||||||
"Cache-Control": cacheControl,
|
"Cache-Control": cacheControl,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
// xlsx exception
|
||||||
|
"dummy.xlsx",
|
||||||
|
"test_name.abc",
|
||||||
|
nil,
|
||||||
|
nil,
|
||||||
|
false,
|
||||||
|
map[string]string{
|
||||||
|
"Content-Disposition": "attachment; filename=test_name.abc",
|
||||||
|
"Content-Type": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
||||||
|
"Content-Length": "0",
|
||||||
|
"Content-Security-Policy": csp,
|
||||||
|
"Cache-Control": cacheControl,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
// docx exception
|
||||||
|
"dummy.docx",
|
||||||
|
"test_name.abc",
|
||||||
|
nil,
|
||||||
|
nil,
|
||||||
|
false,
|
||||||
|
map[string]string{
|
||||||
|
"Content-Disposition": "attachment; filename=test_name.abc",
|
||||||
|
"Content-Type": "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
||||||
|
"Content-Length": "0",
|
||||||
|
"Content-Security-Policy": csp,
|
||||||
|
"Cache-Control": cacheControl,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
// pptx exception
|
||||||
|
"dummy.pptx",
|
||||||
|
"test_name.abc",
|
||||||
|
nil,
|
||||||
|
nil,
|
||||||
|
false,
|
||||||
|
map[string]string{
|
||||||
|
"Content-Disposition": "attachment; filename=test_name.abc",
|
||||||
|
"Content-Type": "application/vnd.openxmlformats-officedocument.presentationml.presentation",
|
||||||
|
"Content-Length": "0",
|
||||||
|
"Content-Security-Policy": csp,
|
||||||
|
"Cache-Control": cacheControl,
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
// custom header
|
// custom header
|
||||||
"test/sub2.txt",
|
"test/sub2.txt",
|
||||||
@@ -716,6 +761,9 @@ func TestFileSystemList(t *testing.T) {
|
|||||||
"style.css",
|
"style.css",
|
||||||
"main.js",
|
"main.js",
|
||||||
"main.mjs",
|
"main.mjs",
|
||||||
|
"dummy.xlsx",
|
||||||
|
"dummy.docx",
|
||||||
|
"dummy.pptx",
|
||||||
"test/sub1.txt",
|
"test/sub1.txt",
|
||||||
"test/sub2.txt",
|
"test/sub2.txt",
|
||||||
},
|
},
|
||||||
@@ -1041,5 +1089,32 @@ func createTestDir(t *testing.T) string {
|
|||||||
file.Close()
|
file.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// "docx" (we are interested only in the extension)
|
||||||
|
{
|
||||||
|
file, err := os.OpenFile(filepath.Join(dir, "dummy.docx"), os.O_WRONLY|os.O_CREATE, 0644)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
file.Close()
|
||||||
|
}
|
||||||
|
|
||||||
|
// "xlsx" (we are interested only in the extension)
|
||||||
|
{
|
||||||
|
file, err := os.OpenFile(filepath.Join(dir, "dummy.xlsx"), os.O_WRONLY|os.O_CREATE, 0644)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
file.Close()
|
||||||
|
}
|
||||||
|
|
||||||
|
// "pptx" (we are interested only in the extension)
|
||||||
|
{
|
||||||
|
file, err := os.OpenFile(filepath.Join(dir, "dummy.pptx"), os.O_WRONLY|os.O_CREATE, 0644)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
file.Close()
|
||||||
|
}
|
||||||
|
|
||||||
return dir
|
return dir
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user