Skip to content

Commit ece5592

Browse files
committed
1 parent 7d6b30f commit ece5592

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

protocol.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""Base protocol class and common code."""
22
import copy
3-
from datetime import datetime, timedelta
3+
from datetime import datetime, timedelta, timezone
44
import logging
55
import os
66
import re
@@ -965,7 +965,10 @@ def receive(from_cls, obj, authed_as=None, internal=False, received_at=None):
965965
if obj.type == 'post':
966966
if published := inner_obj_as1.get('published'):
967967
try:
968-
age = util.now() - util.parse_iso8601(published)
968+
published_dt = util.parse_iso8601(published)
969+
if not published_dt.tzinfo:
970+
published_dt = published_dt.replace(tzinfo=timezone.utc)
971+
age = util.now() - published_dt
969972
if age > CREATE_MAX_AGE:
970973
error(f'Ignoring, too old, {age} is over {CREATE_MAX_AGE}',
971974
status=204)

tests/test_protocol.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3050,6 +3050,21 @@ def test_too_old(self):
30503050
self.assertEqual([], Fake.sent)
30513051
self.assertEqual([], OtherFake.sent)
30523052

3053+
def test_too_old_published_without_timezone(self):
3054+
Follower.get_or_create(to=self.user, from_=self.alice)
3055+
3056+
with self.assertRaises(NoContent):
3057+
Fake.receive_as1({
3058+
'id': 'fake:post',
3059+
'objectType': 'note',
3060+
'author': 'fake:user',
3061+
'published': '2021-12-14T03:04:05', # NOW - 2w
3062+
})
3063+
self.assertIsNone(Object.get_by_id('fake:post'))
3064+
3065+
self.assertEqual([], Fake.sent)
3066+
self.assertEqual([], OtherFake.sent)
3067+
30533068
def test_receive_activity_lease(self):
30543069
Follower.get_or_create(to=self.user, from_=self.alice)
30553070

0 commit comments

Comments
 (0)