Skip to content

Commit

Permalink
Protocol.receive: when fetching actor, fetch profile id
Browse files Browse the repository at this point in the history
also update tests to test profile vs actor id with Fake users more
  • Loading branch information
snarfed committed Jan 28, 2025
1 parent bf9957f commit ca86534
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 24 deletions.
3 changes: 2 additions & 1 deletion protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -1042,7 +1042,8 @@ def receive(from_cls, obj, authed_as=None, internal=False, received_at=None):
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': {
Expand Down
4 changes: 2 additions & 2 deletions tests/test_pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ def test_update_profile(self):
['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,
Expand All @@ -248,7 +248,7 @@ def test_update_profile(self):
'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)
Expand Down
39 changes: 18 additions & 21 deletions tests/test_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -1518,11 +1518,7 @@ def test_create_post_use_instead(self):
'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',
}
Expand Down Expand Up @@ -1635,7 +1631,7 @@ def test_update_post_fetch_object(self):
_, 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',
Expand All @@ -1655,7 +1651,7 @@ def test_update_post_fetch_object_fails(self):
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):
Expand Down Expand Up @@ -2157,19 +2153,20 @@ def test_update_profile(self):

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)

Expand Down Expand Up @@ -2427,11 +2424,11 @@ def test_follow_accept(self, _, **extra):
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',
Expand Down Expand Up @@ -2462,12 +2459,12 @@ def test_stop_following_doesnt_exist(self):
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',
Expand Down Expand Up @@ -2690,7 +2687,7 @@ def test_resolve_ids_follow(self):
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)

Expand Down
1 change: 1 addition & 0 deletions tests/testutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import router

logger = logging.getLogger(__name__)
logging.getLogger('memcache').setLevel(logging.INFO)

ATPROTO_KEY = arroba.util.new_key(2349823483510) # deterministic seed

Expand Down

0 comments on commit ca86534

Please sign in to comment.