@@ -43,9 +43,10 @@ func TestMediaFilenames(t *testing.T) {
4343
4444 mxcUri := alice .UploadContent (t , data .MatrixPng , filename , "image/png" )
4545
46- name := downloadForFilename (t , alice , mxcUri , "" )
46+ name , isAttachment := downloadForFilename (t , alice , mxcUri , "" )
4747
48- if name != filename {
48+ // filename is not required, but if it's an attachment then check it matches
49+ if isAttachment && name != filename {
4950 t .Fatalf ("Incorrect filename '%s', expected '%s'" , name , filename )
5051 }
5152 })
@@ -58,8 +59,9 @@ func TestMediaFilenames(t *testing.T) {
5859 mxcUri := alice .UploadContent (t , data .MatrixPng , "test.png" , "image/png" )
5960
6061 const altName = "file.png"
61- filename := downloadForFilename (t , alice , mxcUri , altName )
62- if filename != altName {
62+ filename , isAttachment := downloadForFilename (t , alice , mxcUri , altName )
63+
64+ if isAttachment && filename != altName {
6365 t .Fatalf ("filename did not match, expected '%s', got '%s'" , altName , filename )
6466 }
6567 })
@@ -83,8 +85,9 @@ func TestMediaFilenames(t *testing.T) {
8385
8486 const diffUnicodeFilename = "\u2615 " // coffee emoji
8587
86- filename := downloadForFilename (t , alice , mxcUri , diffUnicodeFilename )
87- if filename != diffUnicodeFilename {
88+ filename , isAttachment := downloadForFilename (t , alice , mxcUri , diffUnicodeFilename )
89+
90+ if isAttachment && filename != diffUnicodeFilename {
8891 t .Fatalf ("filename did not match, expected '%s', got '%s'" , diffUnicodeFilename , filename )
8992 }
9093 })
@@ -95,9 +98,9 @@ func TestMediaFilenames(t *testing.T) {
9598
9699 mxcUri := alice .UploadContent (t , data .MatrixPng , unicodeFileName , "image/png" )
97100
98- filename := downloadForFilename (t , alice , mxcUri , "" )
101+ filename , isAttachment := downloadForFilename (t , alice , mxcUri , "" )
99102
100- if filename != unicodeFileName {
103+ if isAttachment && filename != unicodeFileName {
101104 t .Fatalf ("filename did not match, expected '%s', got '%s'" , unicodeFileName , filename )
102105 }
103106 })
@@ -108,9 +111,9 @@ func TestMediaFilenames(t *testing.T) {
108111
109112 mxcUri := alice .UploadContent (t , data .MatrixPng , unicodeFileName , "image/png" )
110113
111- filename := downloadForFilename (t , bob , mxcUri , "" )
114+ filename , isAttachment := downloadForFilename (t , bob , mxcUri , "" )
112115
113- if filename != unicodeFileName {
116+ if isAttachment && filename != unicodeFileName {
114117 t .Fatalf ("filename did not match, expected '%s', got '%s'" , unicodeFileName , filename )
115118 }
116119 })
@@ -119,7 +122,7 @@ func TestMediaFilenames(t *testing.T) {
119122}
120123
121124// Returns content disposition information like (mediatype, filename)
122- func downloadForFilename (t * testing.T , c * client.CSAPI , mxcUri string , diffName string ) string {
125+ func downloadForFilename (t * testing.T , c * client.CSAPI , mxcUri string , diffName string ) ( filename string , isAttachment bool ) {
123126 t .Helper ()
124127
125128 origin , mediaId := client .SplitMxc (mxcUri )
@@ -139,15 +142,16 @@ func downloadForFilename(t *testing.T, c *client.CSAPI, mxcUri string, diffName
139142 t .Fatalf ("Got err when parsing content disposition: %s" , err )
140143 }
141144
142- if mediaType != "attachment" {
143- t .Fatalf ("Found unexpected mediatype %s, expected attachment" , mediaType )
145+ if mediaType = "attachment" || {
146+ if filename , ok := params ["filename" ]; ok {
147+ return filename , true
148+ } else {
149+ t .Fatalf ("Content Disposition did not have filename" )
150+ return "" , true
151+ }
144152 }
145-
146- if filename , ok := params ["filename" ]; ok {
147- return filename
148- } else {
149- t .Fatalf ("Content Disposition did not have filename" )
150-
151- return ""
153+ if mediaType != "inline" {
154+ t .Fatalf ("Found unexpected mediatype %s, expected attachment" , mediaType )
152155 }
156+ return "" , false
153157}
0 commit comments