From ccb7158350147e89911a1e72aea72e77c4139954 Mon Sep 17 00:00:00 2001 From: Ryan Barrett Date: Fri, 16 Aug 2024 14:01:28 -0700 Subject: [PATCH] Protocol.check_supported: allow DMs both to and from bot accounts for #1205, #1148, #966, #1024 --- protocol.py | 5 ++++- tests/test_protocol.py | 22 +++++++++++++--------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/protocol.py b/protocol.py index 5124f7aa..f0f54357 100644 --- a/protocol.py +++ b/protocol.py @@ -1649,8 +1649,11 @@ def check_supported(cls, obj): and inner_type not in cls.SUPPORTED_AS1_TYPES)): error(f"Bridgy Fed for {cls.LABEL} doesn't support {obj.type} {inner_type} yet", status=204) + # DMs are only allowed to/from protocol bot accounts if recip := as1.recipient_if_dm(obj.as1): - if not cls.SUPPORTS_DMS or recip not in PROTOCOL_DOMAINS: + if (not cls.SUPPORTS_DMS + or (recip not in PROTOCOL_DOMAINS + and as1.get_owner(obj.as1) not in PROTOCOL_DOMAINS)): error(f"Bridgy Fed doesn't support DMs", status=204) diff --git a/tests/test_protocol.py b/tests/test_protocol.py index 1f7c069d..c5060ef7 100644 --- a/tests/test_protocol.py +++ b/tests/test_protocol.py @@ -759,15 +759,19 @@ def test_check_supported(self): Fake.check_supported(Object(our_as1=obj)) # Fake doesn't support DMs, ExplicitEnableFake does - bot_dm = Object(our_as1={ - 'objectType': 'note', - 'actor': 'ap.brid.gy', - 'to': ['did:bob'], - 'content': 'hello world', - }) - ExplicitEnableFake.check_supported(bot_dm) - with self.assertRaises(NoContent): - Fake.check_supported(bot_dm) + for actor, recip in ( + ('ap.brid.gy', 'did:bob'), + ('did:bob', 'ap.brid.gy'), + ): + bot_dm = Object(our_as1={ + 'objectType': 'note', + 'actor': actor, + 'to': [recip], + 'content': 'hello world', + }) + ExplicitEnableFake.check_supported(bot_dm) + with self.assertRaises(NoContent): + Fake.check_supported(bot_dm) dm = Object(our_as1={ 'objectType': 'note',