kopia lustrzana https://github.com/snarfed/bridgy-fed
AP: add test for following bot user to enable protocol
also relax Web.put check on id to allow internal domains for bot userspull/968/head
rodzic
f52f7060a6
commit
3f1d860bba
|
@ -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"
|
||||
}
|
|
@ -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))
|
||||
|
|
|
@ -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
|
||||
|
|
2
web.py
2
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
|
||||
|
|
Ładowanie…
Reference in New Issue