diff --git a/eefake.brid.gy.as2.json b/eefake.brid.gy.as2.json new file mode 100644 index 0000000..013160f --- /dev/null +++ b/eefake.brid.gy.as2.json @@ -0,0 +1,8 @@ +{ + "type": "Application", + "id": "https://eefake.brid.gy/eefake.brid.gy", + "url": "https://eefake.brid.gy/", + "preferredUsername": "eefake.brid.gy", + "summary": "Only for unit tests", + "name": "ExplicitEnableFake" +} diff --git a/tests/test_activitypub.py b/tests/test_activitypub.py index 99eefdd..1358c5f 100644 --- a/tests/test_activitypub.py +++ b/tests/test_activitypub.py @@ -11,9 +11,10 @@ from flask import g from google.cloud import ndb from granary import as2, microformats2 from httpsig import HeaderSigner +from oauth_dropins.webutil.flask_util import NoContent from oauth_dropins.webutil.testutil import requests_response -from oauth_dropins.webutil.util import domain_from_link, json_dumps, json_loads from oauth_dropins.webutil import util +from oauth_dropins.webutil.util import domain_from_link, json_dumps, json_loads import requests from urllib3.exceptions import ReadTimeoutError from werkzeug.exceptions import BadGateway, BadRequest @@ -865,6 +866,25 @@ class ActivityPubTest(TestCase): self.assertIsNone(Object.get_by_id(not_public['id'])) self.assertIsNone(Object.get_by_id(not_public['object']['id'])) + def test_follow_bot_user_enables_protocol(self, *mocks): + user = self.make_user('https://mas.to/users/swentel', cls=ActivityPub, + obj_as2=ACTOR) + self.assertFalse(ActivityPub.is_enabled_to(ExplicitEnableFake, user)) + + id = 'https://inst/follow' + with self.assertRaises(NoContent): + ActivityPub.receive(Object(id=id, as2={ + 'type': 'Follow', + 'id': id, + 'actor': 'https://mas.to/users/swentel', + 'object': 'https://eefake.brid.gy/eefake.brid.gy', + })) + + self.assertEqual(['https://mas.to/users/swentel'], + ExplicitEnableFake.created_for) + user = user.key.get() + self.assertTrue(ActivityPub.is_enabled_to(ExplicitEnableFake, user)) + def test_inbox_dm_yes_to_bot_user_enables_protocol(self, *mocks): user = self.make_user(ACTOR['id'], cls=ActivityPub) self.assertFalse(ActivityPub.is_enabled_to(ExplicitEnableFake, user)) diff --git a/tests/testutil.py b/tests/testutil.py index 3405a24..5a59013 100644 --- a/tests/testutil.py +++ b/tests/testutil.py @@ -232,16 +232,6 @@ class TestCase(unittest.TestCase, testutil.Asserts): ids._NON_WEB_SUBDOMAIN_SITES = None ids.COPIES_PROTOCOLS = ('atproto', 'fake', 'other') - common.PROTOCOL_DOMAINS = ( - 'ap.brid.gy', - 'bsky.brid.gy', - 'web.brid.gy', - 'eefake.brid.gy', - 'fa.brid.gy', - 'other.brid.gy', - ) - common.DOMAINS = ((PRIMARY_DOMAIN,) + common.PROTOCOL_DOMAINS - + OTHER_DOMAINS + LOCAL_DOMAINS) # make random test data deterministic arroba.util._clockid = 17 diff --git a/web.py b/web.py index b478fea..1afc79d 100644 --- a/web.py +++ b/web.py @@ -138,7 +138,7 @@ class Web(User, Protocol): """Validate domain id, don't allow upper case or invalid characters.""" super()._pre_put_hook() id = self.key.id() - assert is_valid_domain(id, allow_internal=False), id + assert is_valid_domain(id), id assert id.lower() == id, f'upper case is not allowed in Web key id: {id}' @classmethod