Ryan Barrett 2023-08-01 07:52:36 -07:00
rodzic d4035d867a
commit 62ba627bc9
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 6BE31FDF4776E9D4
2 zmienionych plików z 43 dodań i 6 usunięć

Wyświetl plik

@ -121,7 +121,8 @@ class FollowCallback(indieauth.Callback):
return redirect(g.user.user_page_path('following'))
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:
flash(f"AS2 profile {as2_url} missing id or inbox")
return redirect(g.user.user_page_path('following'))
@ -132,7 +133,7 @@ class FollowCallback(indieauth.Callback):
'@context': 'https://www.w3.org/ns/activitystreams',
'type': 'Follow',
'id': follow_id,
'object': followee.as2,
'object': followee_as2,
'actor': g.user.ap_actor(),
'to': [as2.PUBLIC_AUDIENCE],
}

Wyświetl plik

@ -186,6 +186,39 @@ class FollowTest(TestCase):
resp = self.client.get(f'/follow/callback?code=my_code&state={state}')
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):
"""https://console.cloud.google.com/errors/detail/CKmLytj-nPv9RQ;time=P30D?project=bridgy-federated"""
followee = {
@ -215,15 +248,18 @@ class FollowTest(TestCase):
expected_follow['object'] = followee
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('/web/alice.com/following', resp.headers['Location'])
self.assertEqual([f'Followed <a href="https://bar/url">{input}</a>.'],
get_flashed_messages())
mock_get.assert_has_calls((
self.as2_req('https://bar/actor'),
))
if fetched_followee:
mock_get.assert_has_calls((
self.as2_req('https://bar/actor'),
))
inbox_args, inbox_kwargs = mock_post.call_args
self.assertEqual(('http://bar/inbox',), inbox_args)
self.assert_equals(expected_follow, json_loads(inbox_kwargs['data']))