-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
subsumed by User.enabled_protocols. for #973
- Loading branch information
Showing
15 changed files
with
37 additions
and
172 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -191,12 +191,6 @@ class User(StringIdModel, metaclass=ProtocolUserMeta): | |
# TODO: switch to using Object.copies on the user profile object? | ||
copies = ndb.StructuredProperty(Target, repeated=True) | ||
|
||
# whether this user signed up or otherwise explicitly, deliberately | ||
# interacted with Bridgy Fed. For example, if fediverse user @[email protected] looks | ||
# up @[email protected] via WebFinger, we'll create Users for both, | ||
# @[email protected] will be direct, foo.com will not. | ||
direct = ndb.BooleanProperty(default=False) | ||
|
||
# these are for ActivityPub HTTP Signatures | ||
public_exponent = ndb.StringProperty() | ||
private_exponent = ndb.StringProperty() | ||
|
@@ -219,6 +213,7 @@ class User(StringIdModel, metaclass=ProtocolUserMeta): | |
# `existing` attr is set by get_or_create | ||
|
||
# OLD. some stored entities still have these; do not reuse. | ||
# direct = ndb.BooleanProperty(default=False) | ||
# actor_as2 = JsonProperty() | ||
# protocol-specific state | ||
# atproto_notifs_indexed_at = ndb.TextProperty() | ||
|
@@ -310,11 +305,10 @@ def _run(): | |
|
||
# TODO: propagate more fields? | ||
changed = False | ||
for field in ['direct', 'obj', 'obj_key']: | ||
for field in ['obj', 'obj_key']: | ||
old_val = getattr(user, field, None) | ||
new_val = kwargs.get(field) | ||
if ((old_val is None and new_val is not None) | ||
or (field == 'direct' and not old_val and new_val)): | ||
if old_val is None and new_val is not None: | ||
setattr(user, field, new_val) | ||
changed = True | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -428,7 +428,7 @@ <h3 id="from-fediverse">From the fediverse</h3> | |
|
||
<li id="fediverse-follow-web" class="question">How do I find a bridged web site?</li> | ||
<li class="answer"> | ||
<p>You can follow any web site, eg <a class="handle" href="https://example.com/">example.com</a>, by searching for <span class="handle">@example[email protected]</span> in your fediverse instance.</p> | ||
<p>To follow a web site, first <a href="/web-site">enter it here</a> to make sure it's set up, then wait a minute, then search for <code>@[domain]@web.brid.gy</code> in your fediverse instance. For example, to follow <a href="https://nature.com/">nature.com</a>, search for <code>@nature[email protected]</code>.</p> | ||
<p>Bridged web sites appear in the fediverse as either <code>@[domain]@[domain]</code>, <code>@[domain]@web.brid.gy</code>, or <code>@[domain]@fed.brid.gy</code>, depending on the fediverse server and whether the web site owner has <a href="#fediverse-enhanced">connected their domain to Bridgy Fed</a>. All bridged web sites behave the same in the fediverse; the different instances in their handles are purely cosmetic.</p> | ||
</li> | ||
|
||
|
@@ -579,7 +579,7 @@ <h3 id="from-bluesky">From Bluesky</h3> | |
|
||
<li id="bluesky-follow-web" class="question">How do I find a bridged web site?</li> | ||
<li class="answer"> | ||
<p>To follow a web site, first <a href="#enter-web-site">enter it here</a> to make sure it's set up, then wait a minute, then <a href="https://bsky.app/search">search for it in Bluesky</a> as <code>[domain].web.brid.gy</code>. For example, <a href="https://nature.com/">nature.com</a> is bridged into Bluesky as <a href="https://bsky.app/profile/nature.com.web.brid.gy">nature.com.web.brid.gy</a>.</p> | ||
<p>To follow a web site, first <a href="/web-site">enter it here</a> to make sure it's set up, then wait a minute, then <a href="https://bsky.app/search">search for it in Bluesky</a> as <code>[domain].web.brid.gy</code>. For example, <a href="https://nature.com/">nature.com</a> is bridged into Bluesky as <a href="https://bsky.app/profile/nature.com.web.brid.gy">nature.com.web.brid.gy</a>.</p> | ||
</li> | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -673,7 +673,6 @@ def test_username(self, *mocks): | |
'url': ['bar'], | ||
'preferredUsername': 'baz', | ||
}) | ||
self.user.direct = True | ||
self.assertEqual('user.com', self.user.username()) | ||
|
||
# bad acct: URI, util.parse_acct_uri raises ValueError | ||
|
@@ -687,9 +686,6 @@ def test_username(self, *mocks): | |
self.user.obj.as2['url'].append('acct:[email protected]') | ||
self.assertEqual('alice', self.user.username()) | ||
|
||
self.user.direct = False | ||
self.assertEqual('user.com', self.user.username()) | ||
|
||
@patch('oauth_dropins.webutil.appengine_config.tasks_client.create_task') | ||
def test_make_task(self, mock_create_task, mock_get, mock_post): | ||
common.RUN_TASKS_INLINE = False | ||
|
@@ -1820,7 +1816,7 @@ def test_update_profile(self, mock_get, mock_post): | |
'discoverable': True, | ||
'indexable': True, | ||
} | ||
self.assert_user(Web, 'user.com', obj_as2=expected_actor_as2, direct=True, | ||
self.assert_user(Web, 'user.com', obj_as2=expected_actor_as2, | ||
has_redirects=True) | ||
|
||
# homepage object | ||
|
@@ -1896,7 +1892,7 @@ def test_update_profile_homepage_no_mf2_or_metaformats(self, mock_get, mock_post | |
self.assert_deliveries(mock_post, ('https://inbox',), update_as2) | ||
|
||
# updated Web user | ||
self.assert_user(Web, 'user.com', direct=True, has_redirects=True, obj_as2={ | ||
self.assert_user(Web, 'user.com', has_redirects=True, obj_as2={ | ||
'@context': [ | ||
'https://www.w3.org/ns/activitystreams', | ||
as2.DISCOVERABLE_INDEXABLE_CONTEXT, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -238,19 +238,6 @@ def test_user_infer_protocol_resource_overrides_request(self): | |
self.assertEqual('application/jrd+json', got.headers['Content-Type']) | ||
self.assert_equals(WEBFINGER_FAKE_FA_BRID_GY, got.json) | ||
|
||
@patch.object(Fake, 'DEFAULT_ENABLED_PROTOCOLS', ['activitypub']) | ||
def test_handle_new_user(self): | ||
self.assertIsNone(Fake.get_by_id('fake:user')) | ||
|
||
Fake.fetchable['fake:user'] = {'id': 'fake:user'} | ||
|
||
got = self.client.get( | ||
'/.well-known/webfinger?resource=acct:fake:handle:[email protected]', | ||
base_url='https://fed.brid.gy/', | ||
headers={'Accept': 'application/json'}) | ||
self.assertEqual(200, got.status_code, got.get_data(as_text=True)) | ||
self.assert_equals(WEBFINGER_FAKE_FA_BRID_GY, got.json) | ||
|
||
def test_urlencoded(self): | ||
"""https://github.com/snarfed/bridgy-fed/issues/535""" | ||
got = self.client.get( | ||
|
@@ -301,29 +288,24 @@ def test_custom_username(self): | |
}, got.json) | ||
|
||
def test_missing_user(self): | ||
got = self.client.get(f'/.well-known/webfinger?resource=acct:[email protected]') | ||
self.assertEqual(404, got.status_code) | ||
|
||
got = self.client.get(f'/.well-known/webfinger?resource=acct:nope.com') | ||
self.assertEqual(404, got.status_code) | ||
|
||
def test_indirect_user_not_on_bridgy_fed_subdomain(self): | ||
self.user.direct = False | ||
self.user.put() | ||
got = self.client.get(f'/.well-known/webfinger?resource=acct:[email protected]') | ||
self.assertEqual(404, got.status_code) | ||
for acct in ('nope.com', '[email protected]', '[email protected]', | ||
'[email protected]', 'fake:handle:[email protected]'): | ||
got = self.client.get(f'/.well-known/webfinger?resource=acct:{acct}') | ||
self.assertEqual(404, got.status_code) | ||
|
||
def test_no_redirects_user_not_on_bridgy_fed_subdomain(self): | ||
self.user.has_redirects = False | ||
self.user.put() | ||
|
||
got = self.client.get( | ||
f'/.well-known/webfinger?resource=acct:[email protected]') | ||
self.assertEqual(404, got.status_code) | ||
|
||
got = self.client.get( | ||
subdomain = self.client.get( | ||
f'/.well-known/webfinger?resource=acct:[email protected]') | ||
self.assertEqual(200, got.status_code) | ||
self.assertEqual(200, subdomain.status_code) | ||
|
||
user_domain = self.client.get( | ||
f'/.well-known/webfinger?resource=acct:[email protected]') | ||
self.assertEqual(200, user_domain.status_code) | ||
self.assertEqual(subdomain.get_data(as_text=True), | ||
user_domain.get_data(as_text=True)) | ||
|
||
def test_user_not_custom_username(self): | ||
for base_url in (None, 'https://web.brid.gy/', 'https://fed.brid.gy/'): | ||
|
@@ -333,12 +315,6 @@ def test_user_not_custom_username(self): | |
base_url=base_url) | ||
self.assertEqual(404, got.status_code) | ||
|
||
def test_missing_user_web_subdomain(self): | ||
self.user.direct = False | ||
self.user.put() | ||
got = self.client.get(f'/.well-known/webfinger?resource=acct:[email protected]') | ||
self.assertEqual(404, got.status_code) | ||
|
||
def test_protocol_not_enabled(self): | ||
self.make_user('efake:user', cls=ExplicitFake) | ||
got = self.client.get(f'/.well-known/webfinger?resource=acct:efake:[email protected]') | ||
|
@@ -379,31 +355,6 @@ class NoHandle(Fake): | |
finally: | ||
PROTOCOLS.pop('nohandle') | ||
|
||
@patch('requests.get') | ||
def test_create_user(self, mock_get): | ||
self.user.key.delete() | ||
self.user.obj_key.delete() | ||
|
||
hcard = return_value = requests_response(test_web.ACTOR_HTML, | ||
url='https://user.com/') | ||
mock_get.side_effect = [ | ||
hcard, | ||
requests_response(status=404), | ||
hcard, | ||
] | ||
expected = copy.deepcopy(WEBFINGER_NO_HCARD) | ||
expected['subject'] = 'acct:[email protected]' | ||
|
||
got = self.client.get( | ||
'/.well-known/webfinger?resource=acct:[email protected]', | ||
headers={'Accept': 'application/json'}, | ||
base_url='https://web.brid.gy/') | ||
self.assertEqual(200, got.status_code) | ||
self.assertEqual(expected, got.json) | ||
|
||
user = Web.get_by_id('user.com') | ||
assert not user.direct | ||
|
||
# skip _pre_put_hook since it doesn't allow internal domains | ||
@patch.object(Web, '_pre_put_hook', new=lambda self: None) | ||
def test_protocol_bot_user(self): | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.