mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-05-04 13:54:56 -04:00
Quarantine media by ID or user ID (#6681)
This commit is contained in:
parent
47f4f493f0
commit
1177d3f3a3
7 changed files with 636 additions and 15 deletions
|
@ -21,6 +21,8 @@ import time
|
|||
|
||||
import attr
|
||||
|
||||
from twisted.web.resource import Resource
|
||||
|
||||
from synapse.api.constants import Membership
|
||||
|
||||
from tests.server import make_request, render
|
||||
|
@ -160,3 +162,38 @@ class RestHelper(object):
|
|||
)
|
||||
|
||||
return channel.json_body
|
||||
|
||||
def upload_media(
|
||||
self,
|
||||
resource: Resource,
|
||||
image_data: bytes,
|
||||
tok: str,
|
||||
filename: str = "test.png",
|
||||
expect_code: int = 200,
|
||||
) -> dict:
|
||||
"""Upload a piece of test media to the media repo
|
||||
Args:
|
||||
resource: The resource that will handle the upload request
|
||||
image_data: The image data to upload
|
||||
tok: The user token to use during the upload
|
||||
filename: The filename of the media to be uploaded
|
||||
expect_code: The return code to expect from attempting to upload the media
|
||||
"""
|
||||
image_length = len(image_data)
|
||||
path = "/_matrix/media/r0/upload?filename=%s" % (filename,)
|
||||
request, channel = make_request(
|
||||
self.hs.get_reactor(), "POST", path, content=image_data, access_token=tok
|
||||
)
|
||||
request.requestHeaders.addRawHeader(
|
||||
b"Content-Length", str(image_length).encode("UTF-8")
|
||||
)
|
||||
request.render(resource)
|
||||
self.hs.get_reactor().pump([100])
|
||||
|
||||
assert channel.code == expect_code, "Expected: %d, got: %d, resp: %r" % (
|
||||
expect_code,
|
||||
int(channel.result["code"]),
|
||||
channel.result["body"],
|
||||
)
|
||||
|
||||
return channel.json_body
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue