Skip to content

Commit

Permalink
add a basic test fetching thumbnail from federation endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
H-Shay committed Aug 6, 2024
1 parent 6e4426a commit ec506d5
Showing 1 changed file with 52 additions and 5 deletions.
57 changes: 52 additions & 5 deletions tests/media_thumbnail_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,22 @@ package tests

import (
"bytes"
"context"
"github.com/matrix-org/complement"
"github.com/matrix-org/complement/client"
"github.com/matrix-org/complement/federation"
"github.com/matrix-org/complement/helpers"
"github.com/matrix-org/complement/internal/data"
"github.com/matrix-org/complement/runtime"
"github.com/matrix-org/gomatrixserverlib/fclient"
"github.com/matrix-org/gomatrixserverlib/spec"
"image/jpeg"
"image/png"
"io"
"net/http"
"net/url"
"strings"
"testing"

"github.com/matrix-org/complement"
"github.com/matrix-org/complement/client"
"github.com/matrix-org/complement/helpers"
"github.com/matrix-org/complement/internal/data"
)

// TODO: add JPEG testing
Expand Down Expand Up @@ -68,6 +71,50 @@ func TestRemotePngThumbnail(t *testing.T) {
}
}

func TestFederationThumbnail(t *testing.T) {
runtime.SkipIf(t, runtime.Dendrite)

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

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

srv := federation.NewServer(t, deployment,
federation.HandleKeyRequests(),
)
cancel := srv.Listen()
defer cancel()
origin := spec.ServerName(srv.ServerName())

fileName := "test.png"
contentType := "image/png"

uri := alice.UploadContent(t, data.LargePng, fileName, contentType)
_, mediaId := client.SplitMxc(uri)

fedReq := fclient.NewFederationRequest(
"GET",
origin,
"hs1",
"/_matrix/federation/v1/media/thumbnail/"+mediaId+"?method=crop&width=14&height=14&animated=false",
)

resp, err := srv.DoFederationRequest(context.Background(), t, deployment, fedReq)
if err != nil {
t.Fatalf("thumbnail request for uploaded file failed: %s", err)
}
if resp.StatusCode != http.StatusOK {
t.Fatalf("thumbnail request for uploaded file failed with status code: %s", resp.StatusCode)

Check failure on line 107 in tests/media_thumbnail_test.go

View workflow job for this annotation

GitHub Actions / Complement (Synapse)

(*testing.common).Fatalf format %s has arg resp.StatusCode of wrong type int

Check failure on line 107 in tests/media_thumbnail_test.go

View workflow job for this annotation

GitHub Actions / Complement (Dendrite)

(*testing.common).Fatalf format %s has arg resp.StatusCode of wrong type int
}

resType := resp.Header.Get("Content-Type")
mimeType := strings.Split(resType, ";")[0]

if mimeType != "multipart/mixed" {
t.Fatalf("thumbnail request did not return multipart/mixed response, returned %s instead", mimeType)
}
}

func fetchAndValidateThumbnail(t *testing.T, c *client.CSAPI, mxcUri string, authenticated bool) {
t.Helper()

Expand Down

0 comments on commit ec506d5

Please sign in to comment.