Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

Commit

Permalink
Lint
Browse files Browse the repository at this point in the history
  • Loading branch information
babolivier committed Nov 4, 2021
1 parent 726f13e commit 1e73b59
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 12 deletions.
6 changes: 4 additions & 2 deletions synapse/rulecheck/domain_rule_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,9 @@ async def user_may_send_3pid_invite(
) -> 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(
Expand Down Expand Up @@ -186,7 +188,7 @@ async def _user_may_invite(
await self._api.public_room_list_manager.room_is_in_public_room_list(
room_id
)
)
)

if (
published_room
Expand Down
64 changes: 54 additions & 10 deletions tests/rulecheck/test_domainrulecheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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:
Expand All @@ -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

Expand Down Expand Up @@ -89,7 +92,12 @@ async def get_room_state(self, *args, **kwargs):
# 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"))
Expand All @@ -106,33 +114,53 @@ def test_allowed(self):

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,
),
)

Expand All @@ -148,12 +176,20 @@ def test_disallowed(self):

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(
Expand Down Expand Up @@ -185,7 +221,11 @@ def test_default_allow(self):

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,
)
)

Expand All @@ -200,7 +240,11 @@ def test_default_deny(self):

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,
)
)

Expand Down

0 comments on commit 1e73b59

Please sign in to comment.