Protocol.receive: when fetching actor, fetch profile id

also update tests to test profile vs actor id with Fake users more
pull/1731/head
Ryan Barrett 2025-01-27 16:47:33 -08:00
rodzic bf9957f889
commit ca86534f21
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 6BE31FDF4776E9D4
4 zmienionych plików z 23 dodań i 24 usunięć

Wyświetl plik

@ -1042,7 +1042,8 @@ class Protocol:
if (actor and actor.keys() == set(['id'])
and obj.type not in ('delete', 'undo')):
logger.debug('Fetching actor so we have name, profile photo, etc')
actor_obj = from_cls.load(actor['id'], raise_=False)
actor_obj = from_cls.load(ids.profile_id(id=actor['id'], proto=from_cls),
raise_=False)
if actor_obj and actor_obj.as1:
obj.our_as1 = {
**obj.as1, 'actor': {

Wyświetl plik

@ -238,7 +238,7 @@ class PagesTest(TestCase):
['Updating profile from <a href="web:fake:user">fake:handle:user</a>...'],
get_flashed_messages())
self.assertEqual(['fake:profile:user', 'fake:user'], Fake.fetched)
self.assertEqual(['fake:profile:user'], Fake.fetched)
actor['updated'] = '2022-01-02T03:04:05+00:00'
self.assert_object('fake:profile:user', source_protocol='fake', our_as1=actor,
@ -248,7 +248,7 @@ class PagesTest(TestCase):
'objectType': 'activity',
'verb': 'update',
'id': 'fake:profile:user#bridgy-fed-update-2022-01-02T03:04:05+00:00',
'actor': 'fake:user',
'actor': {**actor, 'id': 'fake:user'},
'object': actor,
}
self.assertEqual([('other:bob:target', update)], OtherFake.sent)

Wyświetl plik

@ -1518,11 +1518,7 @@ class ProtocolReceiveTest(TestCase):
'objectType': 'activity',
'verb': 'post',
'id': 'fake:post#bridgy-fed-create',
'actor': {
'objectType': 'person',
'id': 'fake:user',
'url': 'fake:user',
},
'actor': 'fake:user',
'object': note_as1,
'published': '2022-01-02T03:04:05+00:00',
}
@ -1635,7 +1631,7 @@ class ProtocolReceiveTest(TestCase):
_, status = Fake.receive_as1(update)
self.assertEqual(204, status)
self.assertEqual(['fake:post'], Fake.fetched)
self.assertEqual(['fake:profile:user', 'fake:post'], Fake.fetched)
self.assert_object('fake:post',
our_as1=post,
type='note',
@ -1655,7 +1651,7 @@ class ProtocolReceiveTest(TestCase):
with self.assertRaises(ErrorButDoNotRetryTask):
Fake.receive_as1(update)
self.assertEqual(['fake:post'], Fake.fetched)
self.assertEqual(['fake:profile:user', 'fake:post'], Fake.fetched)
self.assertIsNone(Object.get_by_id('fake:update'))
def test_create_reply(self):
@ -2157,19 +2153,20 @@ class ProtocolReceiveTest(TestCase):
self.make_followers()
actor = {
'objectType': 'person',
'id': 'fake:user',
'displayName': 'Ms. ☕ Baz',
'urls': [{'displayName': 'Ms. ☕ Baz', 'value': 'https://user.com/'}],
'updated': '2022-01-02T03:04:05+00:00',
}
id = 'fake:user#update-2022-01-02T03:04:05+00:00'
update_as1 = {
'objectType': 'activity',
'verb': 'update',
'id': id,
'actor': 'fake:user',
'object': {
'objectType': 'person',
'id': 'fake:profile:user',
'displayName': 'Ms. ☕ Baz',
'urls': [{'displayName': 'Ms. ☕ Baz', 'value': 'https://user.com/'}],
'updated': '2022-01-02T03:04:05+00:00',
},
'actor': actor,
'object': {**actor, 'id': 'fake:profile:user'},
}
Fake.receive_as1(update_as1)
@ -2427,11 +2424,11 @@ class ProtocolReceiveTest(TestCase):
self.assertEqual([('efake:follow:target', accept_as1)], ExplicitFake.sent)
def test_stop_following(self):
follower = Follower.get_or_create(to=self.user, from_=self.alice)
self.user.obj.our_as1 = {'id': 'fake:user'}
self.user.obj.put()
follower = Follower.get_or_create(to=self.user, from_=self.alice)
stop_as1 = {
'id': 'other:stop-following',
'objectType': 'activity',
@ -2462,12 +2459,12 @@ class ProtocolReceiveTest(TestCase):
self.assertEqual([('fake:user:target', stop_following_as1)], Fake.sent)
def test_stop_following_inactive(self):
follower = Follower.get_or_create(to=self.user, from_=self.alice,
status='inactive')
OtherFake.fetchable['other:alice'] = {}
self.user.obj.our_as1 = {'id': 'fake:user'}
self.user.obj.put()
follower = Follower.get_or_create(to=self.user, from_=self.alice,
status='inactive')
stop_following_as1 = {
'id': 'other:stop-following',
'objectType': 'activity',
@ -2690,7 +2687,7 @@ class ProtocolReceiveTest(TestCase):
self.assertEqual(('OK', 202), Fake.receive(obj, authed_as='fake:user'))
self.assert_equals({
**follow,
'actor': {'id': 'fake:user'},
'actor': 'fake:user',
'object': 'other:alice',
}, Object.get_by_id('fake:follow').our_as1)

Wyświetl plik

@ -42,6 +42,7 @@ import protocol
import router
logger = logging.getLogger(__name__)
logging.getLogger('memcache').setLevel(logging.INFO)
ATPROTO_KEY = arroba.util.new_key(2349823483510) # deterministic seed