From 6f8d3869bb7644296773a3c1d3e71ff7bd859549 Mon Sep 17 00:00:00 2001 From: Patrick Cloke Date: Fri, 22 Sep 2023 13:21:29 -0400 Subject: [PATCH] Add an additional test. --- tests/media_filename_test.go | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/tests/media_filename_test.go b/tests/media_filename_test.go index 71b8bec0..cd4ee669 100644 --- a/tests/media_filename_test.go +++ b/tests/media_filename_test.go @@ -119,6 +119,24 @@ func TestMediaFilenames(t *testing.T) { } }) + t.Run("Will serve safe media types as inline", func(t *testing.T) { + if runtime.Homeserver != runtime.Synapse { + // We need to check that this security behaviour is being correctly run in + // Synapse, but since this is not part of the Matrix spec we do not assume + // other homeservers are doing so. + t.Skip("Skipping test of Content-Disposition header requirements on non-Synapse homeserver") + } + t.Parallel() + + mxcUri := alice.UploadContent(t, data.MatrixPng, "", "image/png") + + _, isAttachment := downloadForFilename(t, bob, mxcUri, "") + + if isAttachment { + t.Fatal("Expected file to be served as inline") + } + }) + t.Run("Will serve unsafe media types as attachments", func(t *testing.T) { if runtime.Homeserver != runtime.Synapse { // We need to check that this security behaviour is being correctly run in @@ -128,12 +146,12 @@ func TestMediaFilenames(t *testing.T) { } t.Parallel() - mxcUri := alice.UploadContent(t, data.MatrixSvg, asciiFileName, "image/svg") + mxcUri := alice.UploadContent(t, data.MatrixSvg, "", "image/svg") _, isAttachment := downloadForFilename(t, bob, mxcUri, "") if !isAttachment { - t.Fatal("Expected file type to be an attachment but ") + t.Fatal("Expected file to be served as an attachment") } }) })