Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a basic test fetching thumbnail from _matrix/federation/v1/media/thumbnail #732

Merged
merged 3 commits into from
Aug 22, 2024

Conversation

H-Shay
Copy link
Contributor

@H-Shay H-Shay commented Aug 6, 2024

As the title states. element-hq/synapse#17518 was missed because Synapse does not request thumbnails via this endpoint, rather fetches the media over the /download endpoint and then generates the thumbnails. This PR adds a test to ensure the basic functionality of the /thumbnail endpoint.

@H-Shay H-Shay marked this pull request as ready for review August 6, 2024 22:23
@H-Shay
Copy link
Contributor Author

H-Shay commented Aug 6, 2024

(note that Synapse failure would be expected since the test can't pull in my fork)

body, err := io.ReadAll(resp.Body)
length := len(body)

contentLength, err := strconv.Atoi(resp.Header.Get("Content-Length"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we instead compare the received boddy to test.png? I don't think we necessarily should mandate that servers set Content-Length in the black box test suite.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will that still fail if the Content-Length is set, but incorrect? That's what the synapse bug is.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it probably makes sense to move the content-length check to the existing Synapse-specific tests for this endpoint: https://github.com/element-hq/synapse/blob/70b0e386032ed2f3ecf25fcf9a4b6c31335ffdc4/tests/federation/test_federation_media.py#L152

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Complement should definitely be checking Content-Length for all requests on all implementations - maybe it already is and was just missing a call to the federation thumbnail endpoint, I don't know.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To expand: HTTP servers can either respond with Content-Length or chunked transfer encoding, and I don't think we should be mandating one or the other. We could do this by explicitly checking for the two cases, but what we actually care about is that the file was correctly transmitted (and it won't be if the Content-Length is wrong, unless golang HTTP client does something non-HTTP-spec compliant).

Copy link
Member

@erikjohnston erikjohnston left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Otherwise LGTM

t.Fatalf("body does not match uploaded file")
}
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a check after the loop to make sure that an image was actually included in the response, mostly to make it clear that we are actually checking the image. Just something like have_checked_image = true; ...; assert have_changed_image

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right this is sorted - if you're happy with the change can you hit the merge button for me (as I no longer posses the power). Thanks so much!

@erikjohnston erikjohnston merged commit 39733c1 into matrix-org:main Aug 22, 2024
3 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants