From 1e73b591262bb3d838f2c7916befda1646c1425f Mon Sep 17 00:00:00 2001 From: Brendan Abolivier Date: Wed, 3 Nov 2021 17:37:28 +0100 Subject: [PATCH] Lint --- synapse/rulecheck/domain_rule_checker.py | 6 ++- tests/rulecheck/test_domainrulecheck.py | 64 ++++++++++++++++++++---- 2 files changed, 58 insertions(+), 12 deletions(-) diff --git a/synapse/rulecheck/domain_rule_checker.py b/synapse/rulecheck/domain_rule_checker.py index da0d8aee30..645fa64a9b 100644 --- a/synapse/rulecheck/domain_rule_checker.py +++ b/synapse/rulecheck/domain_rule_checker.py @@ -144,7 +144,9 @@ class DomainRuleChecker(object): ) -> bool: """Implements the user_may_send_3pid_invite spam checker callback.""" return await self._user_may_invite( - room_id=room_id, inviter_userid=inviter_userid, invitee_userid=None, + room_id=room_id, + inviter_userid=inviter_userid, + invitee_userid=None, ) async def _user_may_invite( @@ -186,7 +188,7 @@ class DomainRuleChecker(object): await self._api.public_room_list_manager.room_is_in_public_room_list( room_id ) - ) + ) if ( published_room diff --git a/tests/rulecheck/test_domainrulecheck.py b/tests/rulecheck/test_domainrulecheck.py index ba4be81350..ab4023a72f 100644 --- a/tests/rulecheck/test_domainrulecheck.py +++ b/tests/rulecheck/test_domainrulecheck.py @@ -33,6 +33,7 @@ class MockEvent: """Mock of an event, only implementing the fields the DomainRuleChecker module will use. """ + sender: str membership: Optional[str] = None @@ -42,6 +43,7 @@ class MockPublicRoomListManager: """Mock of a synapse.module_api.PublicRoomListManager, only implementing the method the DomainRuleChecker module will use. """ + _published: bool async def room_is_in_public_room_list(self, room_id: str) -> bool: @@ -53,6 +55,7 @@ class MockModuleApi: """Mock of a synapse.module_api.ModuleApi, only implementing the methods the DomainRuleChecker module will use. """ + _new_room: bool _published: bool @@ -89,7 +92,12 @@ class MockModuleApi: # reactor to run asynchronous code. class DomainRuleCheckerTestCase(unittest.HomeserverTestCase): def _test_user_may_invite( - self, config, inviter, invitee, new_room, published, + self, + config, + inviter, + invitee, + new_room, + published, ) -> bool: check = DomainRuleChecker(config, MockModuleApi(new_room, published)) return self.get_success(check.user_may_invite(inviter, invitee, "room")) @@ -106,33 +114,53 @@ class DomainRuleCheckerTestCase(unittest.HomeserverTestCase): self.assertTrue( self._test_user_may_invite( - config, "test:source_one", "test:target_one", False, False, + config, + "test:source_one", + "test:target_one", + False, + False, ), ) self.assertTrue( self._test_user_may_invite( - config, "test:source_one", "test:target_two", False, False, + config, + "test:source_one", + "test:target_two", + False, + False, ), ) self.assertTrue( self._test_user_may_invite( - config, "test:source_two", "test:target_two", False, False, + config, + "test:source_two", + "test:target_two", + False, + False, ), ) # User can invite internal user to a published room self.assertTrue( self._test_user_may_invite( - config, "test:source_one", "test1:target_one", False, True, + config, + "test:source_one", + "test1:target_one", + False, + True, ), ) # User can invite external user to a non-published room self.assertTrue( self._test_user_may_invite( - config, "test:source_one", "test:target_two", False, False, + config, + "test:source_one", + "test:target_two", + False, + False, ), ) @@ -148,12 +176,20 @@ class DomainRuleCheckerTestCase(unittest.HomeserverTestCase): self.assertFalse( self._test_user_may_invite( - config, "test:source_one", "test:target_three", False, False, + config, + "test:source_one", + "test:target_three", + False, + False, ) ) self.assertFalse( self._test_user_may_invite( - config, "test:source_two", "test:target_three", False, False, + config, + "test:source_two", + "test:target_three", + False, + False, ) ) self.assertFalse( @@ -185,7 +221,11 @@ class DomainRuleCheckerTestCase(unittest.HomeserverTestCase): self.assertTrue( self._test_user_may_invite( - config, "test:source_three", "test:target_one", False, False, + config, + "test:source_three", + "test:target_one", + False, + False, ) ) @@ -200,7 +240,11 @@ class DomainRuleCheckerTestCase(unittest.HomeserverTestCase): self.assertFalse( self._test_user_may_invite( - config, "test:source_three", "test:target_one", False, False, + config, + "test:source_three", + "test:target_one", + False, + False, ) )