|
@@ -9,14 +9,14 @@ import (
|
|
|
|
|
|
func TestSniffWriter_WriteHTML(t *testing.T) {
|
|
func TestSniffWriter_WriteHTML(t *testing.T) {
|
|
rr := httptest.NewRecorder()
|
|
rr := httptest.NewRecorder()
|
|
- sw := NewContentTypeWriter(rr)
|
|
|
|
|
|
+ sw := NewContentTypeWriter(rr, "")
|
|
sw.Write([]byte("<script>alert('hi')</script>"))
|
|
sw.Write([]byte("<script>alert('hi')</script>"))
|
|
require.Equal(t, "text/plain; charset=utf-8", rr.Header().Get("Content-Type"))
|
|
require.Equal(t, "text/plain; charset=utf-8", rr.Header().Get("Content-Type"))
|
|
}
|
|
}
|
|
|
|
|
|
func TestSniffWriter_WriteTwoWriteCalls(t *testing.T) {
|
|
func TestSniffWriter_WriteTwoWriteCalls(t *testing.T) {
|
|
rr := httptest.NewRecorder()
|
|
rr := httptest.NewRecorder()
|
|
- sw := NewContentTypeWriter(rr)
|
|
|
|
|
|
+ sw := NewContentTypeWriter(rr, "")
|
|
sw.Write([]byte{0x25, 0x50, 0x44, 0x46, 0x2d, 0x11, 0x22, 0x33})
|
|
sw.Write([]byte{0x25, 0x50, 0x44, 0x46, 0x2d, 0x11, 0x22, 0x33})
|
|
sw.Write([]byte("<script>alert('hi')</script>"))
|
|
sw.Write([]byte("<script>alert('hi')</script>"))
|
|
require.Equal(t, "application/pdf", rr.Header().Get("Content-Type"))
|
|
require.Equal(t, "application/pdf", rr.Header().Get("Content-Type"))
|
|
@@ -34,7 +34,7 @@ func TestSniffWriter_WriteHTMLSplitIntoTwoWrites(t *testing.T) {
|
|
// This test shows how splitting the HTML into two Write() calls will still yield text/plain
|
|
// This test shows how splitting the HTML into two Write() calls will still yield text/plain
|
|
|
|
|
|
rr := httptest.NewRecorder()
|
|
rr := httptest.NewRecorder()
|
|
- sw := NewContentTypeWriter(rr)
|
|
|
|
|
|
+ sw := NewContentTypeWriter(rr, "")
|
|
sw.Write([]byte("<scr"))
|
|
sw.Write([]byte("<scr"))
|
|
sw.Write([]byte("ipt>alert('hi')</script>"))
|
|
sw.Write([]byte("ipt>alert('hi')</script>"))
|
|
require.Equal(t, "text/plain; charset=utf-8", rr.Header().Get("Content-Type"))
|
|
require.Equal(t, "text/plain; charset=utf-8", rr.Header().Get("Content-Type"))
|
|
@@ -42,9 +42,16 @@ func TestSniffWriter_WriteHTMLSplitIntoTwoWrites(t *testing.T) {
|
|
|
|
|
|
func TestSniffWriter_WriteUnknownMimeType(t *testing.T) {
|
|
func TestSniffWriter_WriteUnknownMimeType(t *testing.T) {
|
|
rr := httptest.NewRecorder()
|
|
rr := httptest.NewRecorder()
|
|
- sw := NewContentTypeWriter(rr)
|
|
|
|
|
|
+ sw := NewContentTypeWriter(rr, "")
|
|
randomBytes := make([]byte, 199)
|
|
randomBytes := make([]byte, 199)
|
|
rand.Read(randomBytes)
|
|
rand.Read(randomBytes)
|
|
sw.Write(randomBytes)
|
|
sw.Write(randomBytes)
|
|
require.Equal(t, "application/octet-stream", rr.Header().Get("Content-Type"))
|
|
require.Equal(t, "application/octet-stream", rr.Header().Get("Content-Type"))
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+func TestSniffWriter_WriteWithFilenameAPK(t *testing.T) {
|
|
|
|
+ rr := httptest.NewRecorder()
|
|
|
|
+ sw := NewContentTypeWriter(rr, "https://example.com/ntfy.apk")
|
|
|
|
+ sw.Write([]byte{0x50, 0x4B, 0x03, 0x04})
|
|
|
|
+ require.Equal(t, "application/vnd.android.package-archive", rr.Header().Get("Content-Type"))
|
|
|
|
+}
|