incoming follow bug fix, handle www and use_instead

fixes #314
pull/338/head
Ryan Barrett 2022-12-06 14:09:44 -08:00
rodzic eaea3803cd
commit a95c2c4b55
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 6BE31FDF4776E9D4
3 zmienionych plików z 32 dodań i 5 usunięć

Wyświetl plik

@ -169,8 +169,10 @@ def accept_follow(follow, follow_unwrapped, user):
error('Follow actor requires id and inbox. Got: %s', follower)
# store Follower
user_domain = util.domain_from_link(followee_unwrapped, minimize=False)
follower = Follower.get_or_create(dest=user_domain, src=follower_id,
followee_domain = util.domain_from_link(followee_unwrapped, minimize=False)
# follow use_instead, if any
followee_domain = User.get_or_create(followee_domain).key.id()
follower = Follower.get_or_create(dest=followee_domain, src=follower_id,
last_follow=json_dumps(follow))
follower.status = 'active'
follower.put()
@ -179,7 +181,7 @@ def accept_follow(follow, follow_unwrapped, user):
accept = {
'@context': 'https://www.w3.org/ns/activitystreams',
'id': util.tag_uri(request.host, 'accept/%s/%s' % (
(user_domain, follow.get('id')))),
(followee_domain, follow.get('id')))),
'type': 'Accept',
'actor': followee,
'object': {

Wyświetl plik

@ -57,7 +57,7 @@ class User(StringIdModel):
@staticmethod
@ndb.transactional()
def get_or_create(domain):
def get_or_create(domain, **kwargs):
"""Loads and returns a User. Creates it if necessary."""
user = User.get_by_id(domain)
@ -66,7 +66,7 @@ class User(StringIdModel):
# while depending on the amount of randomness available.
pubexp, mod, privexp = magicsigs.generate()
user = User(id=domain, mod=mod, public_exponent=pubexp,
private_exponent=privexp)
private_exponent=privexp, **kwargs)
user.put()
elif user.use_instead:
user = user.use_instead.get()

Wyświetl plik

@ -442,6 +442,31 @@ class ActivityPubTest(testutil.TestCase):
self.assertEqual('active', follower.status)
self.assertEqual(FOLLOW_WRAPPED_WITH_ACTOR, json_loads(follower.last_follow))
def test_inbox_follow_use_instead_strip_www(self, mock_head, mock_get, mock_post):
root = User.get_or_create('realize.be')
User.get_or_create('www.realize.be', use_instead=root.key)
mock_head.return_value = requests_response(url='https://www.realize.be/')
mock_get.side_effect = [
# source actor
requests_response(ACTOR, content_type=common.CONTENT_TYPE_AS2),
# target post webmention discovery
requests_response('<html></html>'),
]
mock_post.return_value = requests_response()
follow = copy.deepcopy(FOLLOW_WRAPPED)
follow['object'] = 'http://localhost/realize.be'
got = self.client.post('/foo.com/inbox', json=follow)
self.assertEqual(200, got.status_code)
# check that the Follower doesn't have www
follower = Follower.get_by_id(f'realize.be {ACTOR["id"]}')
self.assertEqual('active', follower.status)
follow['actor'] = ACTOR
self.assertEqual(follow, json_loads(follower.last_follow))
def test_inbox_undo_follow(self, mock_head, mock_get, mock_post):
mock_head.return_value = requests_response(url='https://www.realize.be/')