Skip to content

Commit

Permalink
Skip tests requiring unauthenticated media on Synapse (#747)
Browse files Browse the repository at this point in the history
These will be expected to fail when Synapse enforces
authenticated media by default in
element-hq/synapse#17889
  • Loading branch information
reivilibre authored Nov 20, 2024
1 parent fde26d9 commit 9e9f6d3
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 12 deletions.
4 changes: 4 additions & 0 deletions tests/csapi/apidoc_content_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@ import (
"github.com/matrix-org/complement"
"github.com/matrix-org/complement/helpers"
"github.com/matrix-org/complement/internal/data"
"github.com/matrix-org/complement/runtime"
)

func TestContent(t *testing.T) {
// Synapse no longer allows downloads over the unauthenticated media endpoints by default
runtime.SkipIf(t, runtime.Synapse)

deployment := complement.Deploy(t, 1)
defer deployment.Destroy(t)

Expand Down
31 changes: 22 additions & 9 deletions tests/media_filename_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ func TestMediaFilenames(t *testing.T) {
var filename = filename

t.Run(fmt.Sprintf("Can download file '%s'", filename), func(t *testing.T) {
// Synapse no longer allows downloads over the unauthenticated media endpoints by default
runtime.SkipIf(t, runtime.Synapse)
t.Parallel()

mxcUri := alice.UploadContent(t, data.MatrixPng, filename, "image/png")
Expand Down Expand Up @@ -69,6 +71,8 @@ func TestMediaFilenames(t *testing.T) {

// sytest: Can download specifying a different ASCII file name
t.Run("Can download specifying a different ASCII file name", func(t *testing.T) {
// Synapse no longer allows downloads over the unauthenticated media endpoints by default
runtime.SkipIf(t, runtime.Synapse)
t.Parallel()

mxcUri := alice.UploadContent(t, data.MatrixPng, asciiFileName, "image/png")
Expand Down Expand Up @@ -107,6 +111,8 @@ func TestMediaFilenames(t *testing.T) {

// sytest: Can download specifying a different Unicode file name
t.Run("Can download specifying a different Unicode file name", func(t *testing.T) {
// Synapse no longer allows downloads over the unauthenticated media endpoints by default
runtime.SkipIf(t, runtime.Synapse)
t.Parallel()

mxcUri := alice.UploadContent(t, data.MatrixPng, unicodeFileName, "image/png")
Expand Down Expand Up @@ -136,6 +142,8 @@ func TestMediaFilenames(t *testing.T) {

// sytest: Can download with Unicode file name locally
t.Run("Can download with Unicode file name locally", func(t *testing.T) {
// Synapse no longer allows downloads over the unauthenticated media endpoints by default
runtime.SkipIf(t, runtime.Synapse)
t.Parallel()

mxcUri := alice.UploadContent(t, data.MatrixPng, unicodeFileName, "image/png")
Expand All @@ -161,6 +169,8 @@ func TestMediaFilenames(t *testing.T) {

// sytest: Can download with Unicode file name over federation
t.Run("Can download with Unicode file name over federation", func(t *testing.T) {
// Synapse no longer allows downloads over the unauthenticated media endpoints by default
runtime.SkipIf(t, runtime.Synapse)
t.Parallel()

mxcUri := alice.UploadContent(t, data.MatrixPng, unicodeFileName, "image/png")
Expand All @@ -185,11 +195,12 @@ func TestMediaFilenames(t *testing.T) {
})

t.Run("Will serve safe media types as inline", func(t *testing.T) {
if runtime.Homeserver != runtime.Synapse && runtime.Homeserver != runtime.Conduwuit {
if runtime.Homeserver != runtime.Conduwuit {
// We need to check that this security behaviour is being correctly run in
// Synapse or conduwuit, but since this is not part of the Matrix spec we do not assume
// conduwuit, 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 and non-conduwuit homeserver")
// Skip Synapse because it no longer allows downloads over the unauthenticated media endpoints by default
t.Skip("Skipping test of Content-Disposition header requirements on non-conduwuit homeserver")
}
t.Parallel()

Expand Down Expand Up @@ -221,11 +232,12 @@ func TestMediaFilenames(t *testing.T) {
})

t.Run("Will serve safe media types with parameters as inline", func(t *testing.T) {
if runtime.Homeserver != runtime.Synapse && runtime.Homeserver != runtime.Conduwuit {
if runtime.Homeserver != runtime.Conduwuit {
// We need to check that this security behaviour is being correctly run in
// Synapse or conduwuit, but since this is not part of the Matrix spec we do not assume
// conduwuit, 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 and non-conduwuit homeserver")
// Skip Synapse because it no longer allows downloads over the unauthenticated media endpoints by default
t.Skip("Skipping test of Content-Disposition header requirements on non-conduwuit homeserver")
}
t.Parallel()

Expand Down Expand Up @@ -259,11 +271,12 @@ func TestMediaFilenames(t *testing.T) {
})

t.Run("Will serve unsafe media types as attachments", func(t *testing.T) {
if runtime.Homeserver != runtime.Synapse && runtime.Homeserver != runtime.Conduwuit {
if runtime.Homeserver != runtime.Conduwuit {
// We need to check that this security behaviour is being correctly run in
// Synapse or conduwuit, but since this is not part of the Matrix spec we do not assume
// conduwuit, 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 and non-conduwuit homeserver")
// Skip Synapse because it no longer allows downloads over the unauthenticated media endpoints by default
t.Skip("Skipping test of Content-Disposition header requirements on non-conduwuit homeserver")
}
t.Parallel()

Expand Down
4 changes: 4 additions & 0 deletions tests/media_nofilename_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,14 @@ import (
"github.com/matrix-org/complement/federation"
"github.com/matrix-org/complement/helpers"
"github.com/matrix-org/complement/must"
"github.com/matrix-org/complement/runtime"
)

// Can handle uploads and remote/local downloads without a file name
func TestMediaWithoutFileName(t *testing.T) {
// Synapse no longer allows downloads over the unauthenticated media endpoints by default
runtime.SkipIf(t, runtime.Synapse)

deployment := complement.Deploy(t, 1)
defer deployment.Destroy(t)

Expand Down
15 changes: 12 additions & 3 deletions tests/media_thumbnail_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,12 @@ func TestLocalPngThumbnail(t *testing.T) {

uri := alice.UploadContent(t, data.LargePng, fileName, contentType)

fetchAndValidateThumbnail(t, alice, uri, false)
t.Run("test /_matrix/media/v3 endpoint", func(t *testing.T) {
// Synapse no longer allows downloads over the unauthenticated media endpoints by default
runtime.SkipIf(t, runtime.Synapse)
fetchAndValidateThumbnail(t, alice, uri, false)
})

t.Run("test /_matrix/client/v1/media endpoint", func(t *testing.T) {
runtime.SkipIf(t, runtime.Dendrite)
fetchAndValidateThumbnail(t, alice, uri, true)
Expand All @@ -57,7 +62,11 @@ func TestRemotePngThumbnail(t *testing.T) {

uri := alice.UploadContent(t, data.LargePng, fileName, contentType)

fetchAndValidateThumbnail(t, bob, uri, false)
t.Run("test /_matrix/media/v3 endpoint", func(t *testing.T) {
// Synapse no longer allows downloads over the unauthenticated media endpoints by default
runtime.SkipIf(t, runtime.Synapse)
fetchAndValidateThumbnail(t, bob, uri, false)
})

t.Run("test /_matrix/client/v1/media endpoint", func(t *testing.T) {
runtime.SkipIf(t, runtime.Dendrite)
Expand Down Expand Up @@ -94,7 +103,7 @@ func TestFederationThumbnail(t *testing.T) {
uri := alice.UploadContent(t, data.LargePng, fileName, contentType)
mediaOrigin, mediaId := client.SplitMxc(uri)

path := []string{"_matrix", "media", "v3", "thumbnail", mediaOrigin, mediaId}
path := []string{"_matrix", "client", "v1", "media", "thumbnail", mediaOrigin, mediaId}
res := alice.MustDo(t, "GET", path, client.WithQueries(url.Values{
"width": []string{"32"},
"height": []string{"32"},
Expand Down

0 comments on commit 9e9f6d3

Please sign in to comment.