kopia lustrzana https://github.com/snarfed/bridgy-fed
rodzic
a3df7d6d30
commit
15e3daff5e
|
@ -44,8 +44,8 @@ def convert(src, dest, _):
|
|||
path_prefix = f'convert/{src}/{dest}/'
|
||||
url = request.url.removeprefix(request.root_url).removeprefix(path_prefix)
|
||||
|
||||
# some browsers collapse repeated /s in the path down to a single slash.
|
||||
# if that happened to this URL, expand it back to two /s.
|
||||
# our redirects evidently collapse :// down to :/ , maybe to prevent URL
|
||||
# parsing bugs? if that happened to this URL, expand it back to ://
|
||||
url = re.sub(r'^(https?:/)([^/])', r'\1/\2', url)
|
||||
|
||||
if not util.is_web(url):
|
||||
|
|
|
@ -425,7 +425,7 @@ class Object(StringIdModel):
|
|||
"""
|
||||
assert '^^' not in self.key.id()
|
||||
id = self.key.id().replace('#', '^^')
|
||||
return common.host_url('render?' + urllib.parse.urlencode({'id': id}))
|
||||
return common.host_url(f'convert/{self.source_protocol}/webmention/{id}')
|
||||
|
||||
def actor_link(self):
|
||||
"""Returns a pretty actor link with their name and profile picture."""
|
||||
|
|
|
@ -344,14 +344,14 @@ class ActivityPubTest(testutil.TestCase):
|
|||
got = self.post('/user.com/inbox', json=reply)
|
||||
self.assertEqual(200, got.status_code, got.get_data(as_text=True))
|
||||
self.assert_req(mock_get, 'https://user.com/post')
|
||||
expected_id = urllib.parse.quote_plus(reply['id'])
|
||||
convert_id = reply['id'].replace('://', ':/')
|
||||
self.assert_req(
|
||||
mock_post,
|
||||
'https://user.com/webmention',
|
||||
headers={'Accept': '*/*'},
|
||||
allow_redirects=False,
|
||||
data={
|
||||
'source': f'http://localhost/render?id={expected_id}',
|
||||
'source': f'http://localhost/convert/activitypub/webmention/{convert_id}',
|
||||
'target': 'https://user.com/post',
|
||||
},
|
||||
)
|
||||
|
@ -436,14 +436,14 @@ class ActivityPubTest(testutil.TestCase):
|
|||
got = self.post('/user.com/inbox', json=repost)
|
||||
self.assertEqual(200, got.status_code, got.get_data(as_text=True))
|
||||
|
||||
source_url = f'http://localhost/render?id={urllib.parse.quote_plus(REPOST["id"])}'
|
||||
convert_id = REPOST['id'].replace('://', ':/')
|
||||
self.assert_req(
|
||||
mock_post,
|
||||
'https://user.com/webmention',
|
||||
headers={'Accept': '*/*'},
|
||||
allow_redirects=False,
|
||||
data={
|
||||
'source': source_url,
|
||||
'source': f'http://localhost/convert/activitypub/webmention/{convert_id}',
|
||||
'target': orig_url,
|
||||
},
|
||||
)
|
||||
|
@ -561,14 +561,14 @@ class ActivityPubTest(testutil.TestCase):
|
|||
got = self.post('/user.com/inbox', json=mention)
|
||||
self.assertEqual(200, got.status_code, got.get_data(as_text=True))
|
||||
self.assert_req(mock_get, 'https://tar.get/')
|
||||
expected_id = urllib.parse.quote_plus(mention['id'])
|
||||
convert_id = mention['id'].replace('://', ':/')
|
||||
self.assert_req(
|
||||
mock_post,
|
||||
'https://tar.get/webmention',
|
||||
headers={'Accept': '*/*'},
|
||||
allow_redirects=False,
|
||||
data={
|
||||
'source': f'http://localhost/render?id={expected_id}',
|
||||
'source': f'http://localhost/convert/activitypub/webmention/{convert_id}',
|
||||
'target': 'https://tar.get/',
|
||||
},
|
||||
)
|
||||
|
@ -602,7 +602,7 @@ class ActivityPubTest(testutil.TestCase):
|
|||
args, kwargs = mock_post.call_args
|
||||
self.assertEqual(('https://user.com/webmention',), args)
|
||||
self.assertEqual({
|
||||
'source': 'http://localhost/render?id=http%3A%2F%2Fmas.to%2Flike%5E%5Eok',
|
||||
'source': 'http://localhost/convert/activitypub/webmention/http:/mas.to/like^^ok',
|
||||
'target': 'https://user.com/post',
|
||||
}, kwargs['data'])
|
||||
|
||||
|
@ -696,7 +696,7 @@ class ActivityPubTest(testutil.TestCase):
|
|||
args, kwargs = mock_post.call_args_list[1]
|
||||
self.assertEqual(('https://user.com/webmention',), args)
|
||||
self.assertEqual({
|
||||
'source': 'http://localhost/render?id=https%3A%2F%2Fmas.to%2F6d1a',
|
||||
'source': 'http://localhost/convert/activitypub/webmention/https:/mas.to/6d1a',
|
||||
'target': 'https://user.com/',
|
||||
}, kwargs['data'])
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ from granary.tests.test_bluesky import ACTOR_PROFILE_BSKY
|
|||
from multiformats import CID
|
||||
from oauth_dropins.webutil.testutil import NOW, requests_response
|
||||
|
||||
from app import app
|
||||
from flask_app import app
|
||||
import common
|
||||
from models import AtpNode, Follower, Object, OBJECT_EXPIRE_AGE, User
|
||||
import protocol
|
||||
|
@ -278,11 +278,13 @@ class ObjectTest(testutil.TestCase):
|
|||
super().tearDown()
|
||||
|
||||
def test_proxy_url(self):
|
||||
obj = Object(id='abc', as2={})
|
||||
self.assertEqual('http://localhost/render?id=abc', obj.proxy_url())
|
||||
obj = Object(id='abc', source_protocol='bluesky')
|
||||
self.assertEqual('http://localhost/convert/bluesky/webmention/abc',
|
||||
obj.proxy_url())
|
||||
|
||||
obj = Object(id='ab#c', as2={})
|
||||
self.assertEqual('http://localhost/render?id=ab%5E%5Ec', obj.proxy_url())
|
||||
obj = Object(id='ab#c', source_protocol='ui')
|
||||
self.assertEqual('http://localhost/convert/ui/webmention/ab^^c',
|
||||
obj.proxy_url())
|
||||
|
||||
def test_put(self):
|
||||
with self.assertRaises(AssertionError):
|
||||
|
|
|
@ -1433,14 +1433,14 @@ class WebmentionUtilTest(testutil.TestCase):
|
|||
mock_get.return_value = WEBMENTION_REL_LINK
|
||||
mock_post.return_value = requests_response()
|
||||
|
||||
obj = Object(id='http://mas.to/like#ok', as2=LIKE)
|
||||
obj = Object(id='http://mas.to/like#ok', as2=LIKE, source_protocol='ui')
|
||||
self.assertTrue(Webmention.send(obj, 'https://user.com/post'))
|
||||
|
||||
self.assert_req(mock_get, 'https://user.com/post')
|
||||
args, kwargs = mock_post.call_args
|
||||
self.assertEqual(('https://user.com/webmention',), args)
|
||||
self.assertEqual({
|
||||
'source': 'http://localhost/render?id=http%3A%2F%2Fmas.to%2Flike%5E%5Eok',
|
||||
'source': 'http://localhost/convert/ui/webmention/http:/mas.to/like^^ok',
|
||||
'target': 'https://user.com/post',
|
||||
}, kwargs['data'])
|
||||
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
"""Stub UI Protocol class, for objects created in the UI.
|
||||
|
||||
Needed for serving /convert/ui/webmention/... requests.
|
||||
"""
|
||||
from protocol import Protocol
|
||||
|
||||
|
||||
class UIProtocol(Protocol):
|
||||
LABEL = 'ui'
|
Ładowanie…
Reference in New Issue