Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Refactor oEmbed previews #10814

Merged
merged 21 commits into from
Sep 21, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions tests/rest/media/v1/test_url_preview.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import json
import os
import re
from binascii import unhexlify

from twisted.internet._resolver import HostResolution
from twisted.internet.address import IPv4Address, IPv6Address
Expand Down Expand Up @@ -576,11 +577,10 @@ def test_oembed_photo(self):
}
oembed_content = json.dumps(result).encode("utf-8")

end_content = (
b"<html><head>"
b"<title>Some Title</title>"
b'<meta property="og:description" content="hi" />'
b"</head></html>"
end_content = unhexlify(
b"89504e470d0a1a0a0000000d4948445200000001000000010806"
b"0000001f15c4890000000a49444154789c63000100000500010d"
b"0a2db40000000049454e44ae426082"
clokep marked this conversation as resolved.
Show resolved Hide resolved
)

channel = self.make_request(
Expand All @@ -606,25 +606,30 @@ def test_oembed_photo(self):

self.pump()

# Ensure a second request is made to the photo URL.
client = self.reactor.tcpClients[1][2].buildProtocol(None)
server = AccumulatingProtocol()
server.makeConnection(FakeTransport(client, self.reactor))
client.makeConnection(FakeTransport(server, self.reactor))
client.dataReceived(
(
b"HTTP/1.0 200 OK\r\nContent-Length: %d\r\n"
b'Content-Type: text/html; charset="utf8"\r\n\r\n'
b'Content-Type: image/png; charset="utf8"\r\n\r\n'
clokep marked this conversation as resolved.
Show resolved Hide resolved
)
% (len(end_content),)
+ end_content
)

self.pump()

# Ensure the URL is what was requested.
self.assertIn(b"/matrixdotorg", server.data)

self.assertEqual(channel.code, 200)
self.assertEqual(
channel.json_body, {"og:title": "Some Title", "og:description": "hi"}
)
self.assertTrue(channel.json_body["og:image"].startswith("mxc://"))
self.assertEqual(channel.json_body["og:image:height"], 1)
self.assertEqual(channel.json_body["og:image:width"], 1)
self.assertTrue(channel.json_body["og:image:type"].startswith("image/png"))

def test_oembed_rich(self):
"""Test an oEmbed endpoint which returns HTML content via the 'rich' type."""
Expand Down