-
Notifications
You must be signed in to change notification settings - Fork 54
/
Copy pathapidoc_content_test.go
56 lines (46 loc) · 1.92 KB
/
apidoc_content_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package csapi_tests
import (
"bytes"
"net/http"
"testing"
"github.com/matrix-org/complement"
"github.com/matrix-org/complement/helpers"
"github.com/matrix-org/complement/internal/data"
)
func TestContent(t *testing.T) {
deployment := complement.Deploy(t, 1)
defer deployment.Destroy(t)
alice := deployment.Register(t, "hs1", helpers.RegistrationOpts{})
wantContentType := "image/png"
// sytest: POST /media/v3/upload can create an upload
mxcUri := alice.UploadContent(t, data.MatrixPng, "test.png", wantContentType)
// sytest: GET /media/v3/download can fetch the value again
content, contentType := alice.DownloadContent(t, mxcUri)
if !bytes.Equal(data.MatrixPng, content) {
t.Fatalf("uploaded and downloaded content doesn't match: want %v\ngot\n%v", data.MatrixPng, content)
}
if contentType != wantContentType {
t.Fatalf("expected contentType to be %s, got %s", wantContentType, contentType)
}
}
// same as above but testing _matrix/client/v1/media/download
func TestContentCSAPIMediaV1(t *testing.T) {
deployment := complement.Deploy(t, 1)
defer deployment.Destroy(t)
alice := deployment.Register(t, "hs1", helpers.RegistrationOpts{})
wantContentType := "img/png"
mxcUri := alice.UploadContent(t, data.MatrixPng, "test.png", wantContentType)
content, contentType := alice.DownloadContentAuthenticated(t, mxcUri)
if !bytes.Equal(data.MatrixPng, content) {
t.Fatalf("uploaded and downloaded content doesn't match: want %v\ngot\n%v", data.MatrixPng, content)
}
if contentType != wantContentType {
t.Fatalf("expected contentType to be \n %s, got \n %s", wantContentType, contentType)
}
// Remove the AccessToken and try again, this should now return a 401.
alice.AccessToken = ""
res := alice.Do(t, "GET", []string{"_matrix", "client", "v1", "media", "download", "hs1", mxcUri})
if res.StatusCode != http.StatusUnauthorized {
t.Fatalf("expected HTTP status: %d, got %d", http.StatusUnauthorized, res.StatusCode)
}
}