kopia lustrzana https://github.com/snarfed/bridgy-fed
bug fix for interactive follow with followee Object without as2
fixes https://console.cloud.google.com/errors/detail/CIeL-MyNk9z5LQ;time=P30D?project=bridgy-federated , https://console.cloud.google.com/errors/detail/COLs4IvxloWVUg;time=P30D?project=bridgy-federatedpull/608/head
rodzic
d4035d867a
commit
62ba627bc9
|
@ -121,7 +121,8 @@ class FollowCallback(indieauth.Callback):
|
||||||
return redirect(g.user.user_page_path('following'))
|
return redirect(g.user.user_page_path('following'))
|
||||||
|
|
||||||
followee_id = followee.as1.get('id')
|
followee_id = followee.as1.get('id')
|
||||||
inbox = followee.as2.get('inbox')
|
followee_as2 = followee.as_as2()
|
||||||
|
inbox = followee_as2.get('inbox')
|
||||||
if not followee_id or not inbox:
|
if not followee_id or not inbox:
|
||||||
flash(f"AS2 profile {as2_url} missing id or inbox")
|
flash(f"AS2 profile {as2_url} missing id or inbox")
|
||||||
return redirect(g.user.user_page_path('following'))
|
return redirect(g.user.user_page_path('following'))
|
||||||
|
@ -132,7 +133,7 @@ class FollowCallback(indieauth.Callback):
|
||||||
'@context': 'https://www.w3.org/ns/activitystreams',
|
'@context': 'https://www.w3.org/ns/activitystreams',
|
||||||
'type': 'Follow',
|
'type': 'Follow',
|
||||||
'id': follow_id,
|
'id': follow_id,
|
||||||
'object': followee.as2,
|
'object': followee_as2,
|
||||||
'actor': g.user.ap_actor(),
|
'actor': g.user.ap_actor(),
|
||||||
'to': [as2.PUBLIC_AUDIENCE],
|
'to': [as2.PUBLIC_AUDIENCE],
|
||||||
}
|
}
|
||||||
|
|
|
@ -186,6 +186,39 @@ class FollowTest(TestCase):
|
||||||
resp = self.client.get(f'/follow/callback?code=my_code&state={state}')
|
resp = self.client.get(f'/follow/callback?code=my_code&state={state}')
|
||||||
self.check('https://bar/actor', resp, FOLLOW_URL, mock_get, mock_post)
|
self.check('https://bar/actor', resp, FOLLOW_URL, mock_get, mock_post)
|
||||||
|
|
||||||
|
def test_callback_stored_followee_with_our_as1(self, mock_get, mock_post):
|
||||||
|
self.store_object(id='https://bar/id', our_as1=as2.to_as1({
|
||||||
|
**FOLLOWEE,
|
||||||
|
# 'id': 'https://bar/actor',
|
||||||
|
}))
|
||||||
|
|
||||||
|
mock_get.side_effect = (
|
||||||
|
requests_response(''),
|
||||||
|
)
|
||||||
|
mock_post.side_effect = (
|
||||||
|
requests_response('me=https://alice.com'),
|
||||||
|
requests_response('OK'), # AP Follow to inbox
|
||||||
|
)
|
||||||
|
|
||||||
|
self.state['state'] = 'https://bar/id'
|
||||||
|
state = util.encode_oauth_state(self.state)
|
||||||
|
resp = self.client.get(f'/follow/callback?code=my_code&state={state}')
|
||||||
|
|
||||||
|
follow_with_profile_link = {
|
||||||
|
**FOLLOW_URL,
|
||||||
|
'id': f'http://localhost/web/alice.com/following#2022-01-02T03:04:05-https://bar/id',
|
||||||
|
'object': {
|
||||||
|
**FOLLOWEE,
|
||||||
|
'attachment': [{
|
||||||
|
'type': 'PropertyValue',
|
||||||
|
'name': 'Link',
|
||||||
|
'value': '<a rel="me" href="https://bar/url"><span class="invisible">https://</span>bar/url<span class="invisible"></span></a>',
|
||||||
|
}],
|
||||||
|
},
|
||||||
|
}
|
||||||
|
self.check('https://bar/id', resp, follow_with_profile_link, mock_get,
|
||||||
|
mock_post, fetched_followee=False)
|
||||||
|
|
||||||
def test_callback_composite_url_field(self, mock_get, mock_post):
|
def test_callback_composite_url_field(self, mock_get, mock_post):
|
||||||
"""https://console.cloud.google.com/errors/detail/CKmLytj-nPv9RQ;time=P30D?project=bridgy-federated"""
|
"""https://console.cloud.google.com/errors/detail/CKmLytj-nPv9RQ;time=P30D?project=bridgy-federated"""
|
||||||
followee = {
|
followee = {
|
||||||
|
@ -215,15 +248,18 @@ class FollowTest(TestCase):
|
||||||
expected_follow['object'] = followee
|
expected_follow['object'] = followee
|
||||||
self.check('https://bar/actor', resp, expected_follow, mock_get, mock_post)
|
self.check('https://bar/actor', resp, expected_follow, mock_get, mock_post)
|
||||||
|
|
||||||
def check(self, input, resp, expected_follow, mock_get, mock_post):
|
def check(self, input, resp, expected_follow, mock_get, mock_post,
|
||||||
|
fetched_followee=True):
|
||||||
self.assertEqual(302, resp.status_code)
|
self.assertEqual(302, resp.status_code)
|
||||||
self.assertEqual('/web/alice.com/following', resp.headers['Location'])
|
self.assertEqual('/web/alice.com/following', resp.headers['Location'])
|
||||||
self.assertEqual([f'Followed <a href="https://bar/url">{input}</a>.'],
|
self.assertEqual([f'Followed <a href="https://bar/url">{input}</a>.'],
|
||||||
get_flashed_messages())
|
get_flashed_messages())
|
||||||
|
|
||||||
mock_get.assert_has_calls((
|
if fetched_followee:
|
||||||
self.as2_req('https://bar/actor'),
|
mock_get.assert_has_calls((
|
||||||
))
|
self.as2_req('https://bar/actor'),
|
||||||
|
))
|
||||||
|
|
||||||
inbox_args, inbox_kwargs = mock_post.call_args
|
inbox_args, inbox_kwargs = mock_post.call_args
|
||||||
self.assertEqual(('http://bar/inbox',), inbox_args)
|
self.assertEqual(('http://bar/inbox',), inbox_args)
|
||||||
self.assert_equals(expected_follow, json_loads(inbox_kwargs['data']))
|
self.assert_equals(expected_follow, json_loads(inbox_kwargs['data']))
|
||||||
|
|
Ładowanie…
Reference in New Issue