Skip to content

Commit 0d14432

Browse files
authored
Update thumbnail tests to include _matrix/client/v1/media/thumbnail endpoint (#728)
* update thumbnail tests to include _matrix/client/v1/media endpoint * add subtests for new endpoints * skip dendrite for now
1 parent bc97f1d commit 0d14432

File tree

1 file changed

+32
-4
lines changed

1 file changed

+32
-4
lines changed

tests/media_thumbnail_test.go

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ package tests
22

33
import (
44
"bytes"
5+
"github.com/matrix-org/complement/runtime"
56
"image/jpeg"
67
"image/png"
78
"io"
9+
"net/http"
810
"net/url"
911
"strings"
1012
"testing"
@@ -29,7 +31,12 @@ func TestLocalPngThumbnail(t *testing.T) {
2931

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

32-
fetchAndValidateThumbnail(t, alice, uri)
34+
fetchAndValidateThumbnail(t, alice, uri, false)
35+
t.Run("test /_matrix/client/v1/media endpoint", func(t *testing.T) {
36+
runtime.SkipIf(t, runtime.Dendrite)
37+
fetchAndValidateThumbnail(t, alice, uri, true)
38+
})
39+
3340
}
3441

3542
// sytest: Remote media can be thumbnailed
@@ -45,15 +52,36 @@ func TestRemotePngThumbnail(t *testing.T) {
4552

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

48-
fetchAndValidateThumbnail(t, bob, uri)
55+
fetchAndValidateThumbnail(t, bob, uri, false)
56+
57+
t.Run("test /_matrix/client/v1/media endpoint", func(t *testing.T) {
58+
runtime.SkipIf(t, runtime.Dendrite)
59+
fetchAndValidateThumbnail(t, bob, uri, true)
60+
})
61+
62+
// Remove the AccessToken and try again, this should now return a 401.
63+
alice.AccessToken = ""
64+
origin, mediaId := client.SplitMxc(uri)
65+
res := alice.Do(t, "GET", []string{"_matrix", "client", "v1", "media", "thumbnail", origin, mediaId})
66+
if res.StatusCode != http.StatusUnauthorized {
67+
t.Fatalf("expected HTTP status: %d, got %d", http.StatusUnauthorized, res.StatusCode)
68+
}
4969
}
5070

51-
func fetchAndValidateThumbnail(t *testing.T, c *client.CSAPI, mxcUri string) {
71+
func fetchAndValidateThumbnail(t *testing.T, c *client.CSAPI, mxcUri string, authenticated bool) {
5272
t.Helper()
5373

5474
origin, mediaId := client.SplitMxc(mxcUri)
5575

56-
res := c.MustDo(t, "GET", []string{"_matrix", "media", "v3", "thumbnail", origin, mediaId}, client.WithQueries(url.Values{
76+
var path []string
77+
78+
if authenticated {
79+
path = []string{"_matrix", "client", "v1", "media", "thumbnail", origin, mediaId}
80+
} else {
81+
path = []string{"_matrix", "media", "v3", "thumbnail", origin, mediaId}
82+
}
83+
84+
res := c.MustDo(t, "GET", path, client.WithQueries(url.Values{
5785
"width": []string{"32"},
5886
"height": []string{"32"},
5987
"method": []string{"scale"},

0 commit comments

Comments
 (0)