@@ -2,9 +2,11 @@ package tests
2
2
3
3
import (
4
4
"bytes"
5
+ "github.com/matrix-org/complement/runtime"
5
6
"image/jpeg"
6
7
"image/png"
7
8
"io"
9
+ "net/http"
8
10
"net/url"
9
11
"strings"
10
12
"testing"
@@ -29,7 +31,12 @@ func TestLocalPngThumbnail(t *testing.T) {
29
31
30
32
uri := alice .UploadContent (t , data .LargePng , fileName , contentType )
31
33
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
+
33
40
}
34
41
35
42
// sytest: Remote media can be thumbnailed
@@ -45,15 +52,36 @@ func TestRemotePngThumbnail(t *testing.T) {
45
52
46
53
uri := alice .UploadContent (t , data .LargePng , fileName , contentType )
47
54
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
+ }
49
69
}
50
70
51
- func fetchAndValidateThumbnail (t * testing.T , c * client.CSAPI , mxcUri string ) {
71
+ func fetchAndValidateThumbnail (t * testing.T , c * client.CSAPI , mxcUri string , authenticated bool ) {
52
72
t .Helper ()
53
73
54
74
origin , mediaId := client .SplitMxc (mxcUri )
55
75
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 {
57
85
"width" : []string {"32" },
58
86
"height" : []string {"32" },
59
87
"method" : []string {"scale" },
0 commit comments