Fixed broken attachment fetching with long filename

environments/review-front-serv-f1ybnc/deployments/3672
Eliot Berriot 2020-01-02 14:23:05 +01:00
rodzic f0b72c8204
commit 7d528ba235
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 6B501DFD73514E14
2 zmienionych plików z 25 dodań i 3 usunięć

Wyświetl plik

@ -80,9 +80,10 @@ def fetch_remote_attachment(attachment, filename=None, save=True):
for chunk in r.iter_content():
tf.write(chunk)
tf.seek(0)
attachment.file.save(
filename or attachment.url.split("/")[-1], File(tf), save=save
)
if not filename:
filename = attachment.url.split("/")[-1]
filename = filename[-50:]
attachment.file.save(filename, File(tf), save=save)
@celery.app.task(name="common.prune_unattached_attachments")

Wyświetl plik

@ -216,6 +216,27 @@ def test_attachment_proxy_redirects_original(
assert response["Location"] == urls[expected]
def test_attachment_proxy_dont_crash_on_long_filename(
factories, logged_in_api_client, avatar, r_mock, now
):
long_filename = "a" * 400
attachment = factories["common.Attachment"](
file=None, url="https://domain/{}.jpg".format(long_filename)
)
avatar_content = avatar.read()
r_mock.get(attachment.url, body=io.BytesIO(avatar_content))
proxy_url = reverse("api:v1:attachments-proxy", kwargs={"uuid": attachment.uuid})
response = logged_in_api_client.get(proxy_url, {"next": next})
attachment.refresh_from_db()
assert response.status_code == 302
assert attachment.file.read() == avatar_content
assert attachment.file.name.endswith("/{}.jpg".format("a" * 46))
assert attachment.last_fetch_date == now
def test_attachment_create(logged_in_api_client, avatar):
actor = logged_in_api_client.user.create_actor()
url = reverse("api:v1:attachments-list")