kopia lustrzana https://github.com/snarfed/bridgy-fed
Protocol.receive: post age bug fix, handle missing timezone
fixes https://console.cloud.google.com/errors/detail/CIXMq_WGs6KuSQ;locations=global;time=P30D?project=bridgy-federatedpull/1740/head
rodzic
7d6b30f67e
commit
ece5592421
|
|
@ -1,6 +1,6 @@
|
|||
"""Base protocol class and common code."""
|
||||
import copy
|
||||
from datetime import datetime, timedelta
|
||||
from datetime import datetime, timedelta, timezone
|
||||
import logging
|
||||
import os
|
||||
import re
|
||||
|
|
@ -965,7 +965,10 @@ class Protocol:
|
|||
if obj.type == 'post':
|
||||
if published := inner_obj_as1.get('published'):
|
||||
try:
|
||||
age = util.now() - util.parse_iso8601(published)
|
||||
published_dt = util.parse_iso8601(published)
|
||||
if not published_dt.tzinfo:
|
||||
published_dt = published_dt.replace(tzinfo=timezone.utc)
|
||||
age = util.now() - published_dt
|
||||
if age > CREATE_MAX_AGE:
|
||||
error(f'Ignoring, too old, {age} is over {CREATE_MAX_AGE}',
|
||||
status=204)
|
||||
|
|
|
|||
|
|
@ -3050,6 +3050,21 @@ class ProtocolReceiveTest(TestCase):
|
|||
self.assertEqual([], Fake.sent)
|
||||
self.assertEqual([], OtherFake.sent)
|
||||
|
||||
def test_too_old_published_without_timezone(self):
|
||||
Follower.get_or_create(to=self.user, from_=self.alice)
|
||||
|
||||
with self.assertRaises(NoContent):
|
||||
Fake.receive_as1({
|
||||
'id': 'fake:post',
|
||||
'objectType': 'note',
|
||||
'author': 'fake:user',
|
||||
'published': '2021-12-14T03:04:05', # NOW - 2w
|
||||
})
|
||||
self.assertIsNone(Object.get_by_id('fake:post'))
|
||||
|
||||
self.assertEqual([], Fake.sent)
|
||||
self.assertEqual([], OtherFake.sent)
|
||||
|
||||
def test_receive_activity_lease(self):
|
||||
Follower.get_or_create(to=self.user, from_=self.alice)
|
||||
|
||||
|
|
|
|||
Ładowanie…
Reference in New Issue