Skip to content

Commit

Permalink
🔒 Make downloading media API authenticated.
Browse files Browse the repository at this point in the history
  • Loading branch information
Danieloni1 committed May 28, 2024
1 parent 218b000 commit 10bb402
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion api/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func buildRoutes() http.Handler {
// Standard (spec) features
register([]string{"PUT"}, PrefixMedia, "upload/:server/:mediaId", mxV3, router, makeRoute(_routers.RequireAccessToken(r0.UploadMediaAsync), "upload_async", counter))
register([]string{"POST"}, PrefixMedia, "upload", mxSpecV3Transition, router, makeRoute(_routers.RequireAccessToken(r0.UploadMediaSync), "upload", counter))
downloadRoute := makeRoute(_routers.OptionalAccessToken(r0.DownloadMedia), "download", counter)
downloadRoute := makeRoute(_routers.RequireAccessToken(r0.DownloadMedia), "download", counter)
register([]string{"GET"}, PrefixMedia, "download/:server/:mediaId/:filename", mxSpecV3Transition, router, downloadRoute)
register([]string{"GET"}, PrefixMedia, "download/:server/:mediaId", mxSpecV3Transition, router, downloadRoute)
register([]string{"GET"}, PrefixMedia, "thumbnail/:server/:mediaId", mxSpecV3Transition, router, makeRoute(_routers.OptionalAccessToken(r0.ThumbnailMedia), "thumbnail", counter))
Expand Down
16 changes: 8 additions & 8 deletions test/upload_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ func (s *UploadTestSuite) TestUpload() {

client1 := s.deps.Homeservers[0].UnprivilegedUsers[0].WithCsUrl(s.deps.Machines[0].HttpUrl)
client2 := &test_internals.MatrixClient{
ClientServerUrl: s.deps.Machines[1].HttpUrl, // deliberately the second machine
ServerName: s.deps.Homeservers[1].ServerName, // deliberately the second machine
AccessToken: "", // no auth for downloads
UserId: "", // no auth for downloads
ClientServerUrl: s.deps.Machines[1].HttpUrl, // deliberately the second machine
ServerName: s.deps.Homeservers[1].ServerName, // deliberately the second machine
AccessToken: s.deps.Homeservers[1].UnprivilegedUsers[0].AccessToken, // GK CUSTOMIZATION: auth for downloads
UserId: s.deps.Homeservers[1].UnprivilegedUsers[0].UserId, // GK CUSTOMIZATION: auth for downloads
}

contentType, img, err := test_internals.MakeTestImage(512, 512)
Expand Down Expand Up @@ -256,10 +256,10 @@ func (s *UploadTestSuite) TestUploadAsyncFlow() {

client1 := s.deps.Homeservers[0].UnprivilegedUsers[0].WithCsUrl(s.deps.Machines[0].HttpUrl)
client2 := &test_internals.MatrixClient{
ClientServerUrl: s.deps.Machines[1].HttpUrl, // deliberately the second machine
ServerName: s.deps.Homeservers[1].ServerName, // deliberately the second machine
AccessToken: "", // no auth for downloads
UserId: "", // no auth for downloads
ClientServerUrl: s.deps.Machines[1].HttpUrl, // deliberately the second machine
ServerName: s.deps.Homeservers[1].ServerName, // deliberately the second machine
AccessToken: s.deps.Homeservers[1].UnprivilegedUsers[0].AccessToken, // GK CUSTOMIZATION: auth for downloads
UserId: s.deps.Homeservers[1].UnprivilegedUsers[0].UserId, // GK CUSTOMIZATION: auth for downloads
}

contentType, img, err := test_internals.MakeTestImage(512, 512)
Expand Down

0 comments on commit 10bb402

Please sign in to comment.