Skip to content

Commit

Permalink
remove OStatus parts of Webfinger
Browse files Browse the repository at this point in the history
  • Loading branch information
snarfed committed Jan 26, 2023
1 parent f0a5f17 commit d523cc0
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 108 deletions.
68 changes: 1 addition & 67 deletions tests/test_webfinger.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ def setUp(self):
'https://foo.com/about-me',
'https://foo.com/',
],
'magic_keys': [{'value': self.key.href()}],
'links': [{
'rel': 'http://webfinger.net/rel/profile-page',
'type': 'text/html',
Expand Down Expand Up @@ -67,20 +66,10 @@ def setUp(self):
'rel': 'sharedInbox',
'type': 'application/activity+json',
'href': 'http://localhost/inbox'
}, {
'rel': 'magic-public-key',
'href': self.key.href(),
}, {
'rel': 'http://ostatus.org/schema/1.0/subscribe',
'template': 'http://localhost/user/foo.com?url={uri}',
}, {
'rel': 'http://schemas.google.com/g/2010#updates-from',
'type': 'application/atom+xml',
'href': 'https://granary.io/url?input=html&output=atom&url=https%3A%2F%2Ffoo.com%2F&hub=https%3A%2F%2Ffoo.com%2F',
}, {
'rel': 'hub',
'href': 'https://bridgy-fed.superfeedr.com/'
}]
}],
}

def test_host_meta_xrd(self):
Expand Down Expand Up @@ -116,50 +105,6 @@ def test_user(self, mock_get):

self.assertEqual(self.expected_webfinger, got.json)

# check that magic key is persistent
again = self.client.get('/acct:foo.com',
headers={'Accept': 'application/json'}).json
self.assertEqual(self.key.href(), again['magic_keys'][0]['value'])

links = {l['rel']: l.get('href') for l in again['links']}
self.assertEqual(self.key.href(), links['magic-public-key'])

@mock.patch('requests.get')
def test_user_with_atom_feed(self, mock_get):
html = """\
<html>
<head>
<link rel="feed" href="/dont-use">
<link rel="alternate" type="application/rss+xml" href="/dont-use-either">
<link rel="alternate" type="application/atom+xml" href="/use-this">
</head>
""" + self.html
mock_get.return_value = requests_response(html, url = 'https://foo.com/')

got = self.client.get('/acct:foo.com', headers={'Accept': 'application/json'})
self.assertEqual(200, got.status_code)
self.assertIn({
'rel': 'http://schemas.google.com/g/2010#updates-from',
'type': 'application/atom+xml',
'href': 'https://foo.com/use-this',
}, got.json['links'])

@mock.patch('requests.get')
def test_user_with_push_header(self, mock_get):
mock_get.return_value = requests_response(
self.html, url = 'https://foo.com/', headers={
'Link': 'badly formatted, '
"<xyz>; rel='foo',"
'<http://a.custom.hub/>; rel="hub"',
})

got = self.client.get('/acct:foo.com', headers={'Accept': 'application/json'})
self.assertEqual(200, got.status_code)
self.assertIn({
'rel': 'hub',
'href': 'http://a.custom.hub/',
}, got.json['links'])

@mock.patch('requests.get')
def test_user_no_hcard(self, mock_get):
mock_get.return_value = requests_response("""
Expand All @@ -175,7 +120,6 @@ def test_user_no_hcard(self, mock_get):
self.assert_equals({
'subject': 'acct:foo.com@foo.com',
'aliases': ['https://foo.com/'],
'magic_keys': [{'value': self.key.href()}],
'links': [{
'rel': 'http://webfinger.net/rel/profile-page',
'type': 'text/html',
Expand All @@ -196,16 +140,6 @@ def test_user_no_hcard(self, mock_get):
'rel': 'sharedInbox',
'type': 'application/activity+json',
'href': 'http://localhost/inbox'
}, {
'rel': 'http://schemas.google.com/g/2010#updates-from',
'type': 'application/atom+xml',
'href': 'https://granary.io/url?input=html&output=atom&url=https%3A%2F%2Ffoo.com%2F&hub=https%3A%2F%2Ffoo.com%2F',
}, {
'rel': 'hub',
'href': 'https://bridgy-fed.superfeedr.com/'
}, {
'rel': 'magic-public-key',
'href': self.key.href(),
}, {
'rel': 'http://ostatus.org/schema/1.0/subscribe',
'template': 'http://localhost/user/foo.com?url={uri}',
Expand Down
41 changes: 0 additions & 41 deletions webfinger.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ def template_vars(self, domain=None, url=None):
data = util.trim_nulls({
'subject': 'acct:' + user.address().lstrip('@'),
'aliases': urls,
'magic_keys': [{'value': user.href()}],
'links': sum(([{
'rel': 'http://webfinger.net/rel/profile-page',
'type': 'text/html',
Expand Down Expand Up @@ -119,13 +118,6 @@ def template_vars(self, domain=None, url=None):
'href': common.host_url('inbox'),
},

# OStatus
# TODO: remove?
{
'rel': 'magic-public-key',
'href': user.href(),
},

# remote follow
# https://socialhub.activitypub.rocks/t/what-is-the-current-spec-for-remote-follow/2020/11?u=snarfed
# https://github.com/snarfed/bridgy-fed/issues/60#issuecomment-1325589750
Expand All @@ -135,39 +127,6 @@ def template_vars(self, domain=None, url=None):
}]
})

# OStatus: discover atom feed, if any
# TODO: remove?
if resp:
feed = parsed.find('link', rel='alternate', type=atom.CONTENT_TYPE)
if feed and feed['href']:
feed = urllib.parse.urljoin(resp.url, feed['href'])
else:
feed = 'https://granary.io/url?' + urllib.parse.urlencode({
'input': 'html',
'output': 'atom',
'url': resp.url,
'hub': resp.url,
})
data['links'].append({
'rel': 'http://schemas.google.com/g/2010#updates-from',
'type': atom.CONTENT_TYPE,
'href': feed,
})

# OStatus: discover PuSH, if any
# TODO: remove?
if resp:
for link in resp.headers.get('Link', '').split(','):
match = common.LINK_HEADER_RE.match(link)
if match and match.group(2) == 'hub':
hub = match.group(1)
else:
hub = 'https://bridgy-fed.superfeedr.com/'
data['links'].append({
'rel': 'hub',
'href': hub,
})

logger.info(f'Returning WebFinger data: {json_dumps(data, indent=2)}')
return data

Expand Down

0 comments on commit d523cc0

Please sign in to comment.