Skip to content

Commit

Permalink
split content test into federation/local and test authentication
Browse files Browse the repository at this point in the history
  • Loading branch information
H-Shay committed Jun 29, 2024
1 parent 5b25add commit b9a2198
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 5 deletions.
17 changes: 12 additions & 5 deletions tests/csapi/apidoc_content_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package csapi_tests

import (
"bytes"
"net/http"
"testing"

"github.com/matrix-org/complement"
Expand Down Expand Up @@ -30,20 +31,26 @@ func TestContent(t *testing.T) {

// same as above but testing _matrix/client/v1/media/download
func TestContentCSAPIMediaV1(t *testing.T) {
deployment := complement.Deploy(t, 2)
deployment := complement.Deploy(t, 1)
defer deployment.Destroy(t)

hs1 := deployment.Register(t, "hs1", helpers.RegistrationOpts{})
hs2 := deployment.Register(t, "hs2", helpers.RegistrationOpts{})
alice := deployment.Register(t, "hs1", helpers.RegistrationOpts{})

wantContentType := "img/png"
mxcUri := hs1.UploadContent(t, data.MatrixPng, "test.png", wantContentType)
mxcUri := alice.UploadContent(t, data.MatrixPng, "test.png", wantContentType)

content, contentType := hs2.DownloadContentAuthenticated(t, mxcUri)
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)
}
}
28 changes: 28 additions & 0 deletions tests/federation_media_content_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package tests

import (
"bytes"
"github.com/matrix-org/complement"
"github.com/matrix-org/complement/helpers"
"github.com/matrix-org/complement/internal/data"
"testing"
)

func TestContentMediaV1(t *testing.T) {
deployment := complement.Deploy(t, 2)
defer deployment.Destroy(t)

hs1 := deployment.Register(t, "hs1", helpers.RegistrationOpts{})
hs2 := deployment.Register(t, "hs2", helpers.RegistrationOpts{})

wantContentType := "img/png"
mxcUri := hs1.UploadContent(t, data.MatrixPng, "test.png", wantContentType)

content, contentType := hs2.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)
}
}

0 comments on commit b9a2198

Please sign in to comment.