mirror of
https://mau.dev/maunium/synapse.git
synced 2024-10-01 01:36:05 -04:00
Run black on tests/rulecheck/
This commit is contained in:
parent
164798ec32
commit
f04ee0b351
@ -36,14 +36,18 @@ class DomainRuleCheckerTestCase(unittest.TestCase):
|
||||
check = DomainRuleChecker(config)
|
||||
self.assertTrue(
|
||||
check.user_may_invite(
|
||||
"test:source_one", "test:target_one", None, "room", False,
|
||||
"test:source_one", "test:target_one", None, "room", False
|
||||
)
|
||||
)
|
||||
self.assertTrue(
|
||||
check.user_may_invite("test:source_one", "test:target_two", None, "room", False)
|
||||
check.user_may_invite(
|
||||
"test:source_one", "test:target_two", None, "room", False
|
||||
)
|
||||
)
|
||||
self.assertTrue(
|
||||
check.user_may_invite("test:source_two", "test:target_two", None, "room", False)
|
||||
check.user_may_invite(
|
||||
"test:source_two", "test:target_two", None, "room", False
|
||||
)
|
||||
)
|
||||
|
||||
def test_disallowed(self):
|
||||
@ -57,16 +61,24 @@ class DomainRuleCheckerTestCase(unittest.TestCase):
|
||||
}
|
||||
check = DomainRuleChecker(config)
|
||||
self.assertFalse(
|
||||
check.user_may_invite("test:source_one", "test:target_three", None, "room", False)
|
||||
check.user_may_invite(
|
||||
"test:source_one", "test:target_three", None, "room", False
|
||||
)
|
||||
)
|
||||
self.assertFalse(
|
||||
check.user_may_invite("test:source_two", "test:target_three", None, "room", False)
|
||||
check.user_may_invite(
|
||||
"test:source_two", "test:target_three", None, "room", False
|
||||
)
|
||||
)
|
||||
self.assertFalse(
|
||||
check.user_may_invite("test:source_two", "test:target_one", None, "room", False)
|
||||
check.user_may_invite(
|
||||
"test:source_two", "test:target_one", None, "room", False
|
||||
)
|
||||
)
|
||||
self.assertFalse(
|
||||
check.user_may_invite("test:source_four", "test:target_one", None, "room", False)
|
||||
check.user_may_invite(
|
||||
"test:source_four", "test:target_one", None, "room", False
|
||||
)
|
||||
)
|
||||
|
||||
def test_default_allow(self):
|
||||
@ -79,7 +91,9 @@ class DomainRuleCheckerTestCase(unittest.TestCase):
|
||||
}
|
||||
check = DomainRuleChecker(config)
|
||||
self.assertTrue(
|
||||
check.user_may_invite("test:source_three", "test:target_one", None, "room", False)
|
||||
check.user_may_invite(
|
||||
"test:source_three", "test:target_one", None, "room", False
|
||||
)
|
||||
)
|
||||
|
||||
def test_default_deny(self):
|
||||
@ -92,7 +106,9 @@ class DomainRuleCheckerTestCase(unittest.TestCase):
|
||||
}
|
||||
check = DomainRuleChecker(config)
|
||||
self.assertFalse(
|
||||
check.user_may_invite("test:source_three", "test:target_one", None, "room", False)
|
||||
check.user_may_invite(
|
||||
"test:source_three", "test:target_one", None, "room", False
|
||||
)
|
||||
)
|
||||
|
||||
def test_config_parse(self):
|
||||
@ -127,14 +143,17 @@ class DomainRuleCheckerRoomTestCase(unittest.HomeserverTestCase):
|
||||
def make_homeserver(self, reactor, clock):
|
||||
config = self.default_config()
|
||||
|
||||
config.spam_checker = (DomainRuleChecker, {
|
||||
"default": True,
|
||||
"domain_mapping": {},
|
||||
"can_only_join_rooms_with_invite": True,
|
||||
"can_only_create_one_to_one_rooms": True,
|
||||
"can_only_invite_during_room_creation": True,
|
||||
"can_invite_by_third_party_id": False,
|
||||
})
|
||||
config.spam_checker = (
|
||||
DomainRuleChecker,
|
||||
{
|
||||
"default": True,
|
||||
"domain_mapping": {},
|
||||
"can_only_join_rooms_with_invite": True,
|
||||
"can_only_create_one_to_one_rooms": True,
|
||||
"can_only_invite_during_room_creation": True,
|
||||
"can_invite_by_third_party_id": False,
|
||||
},
|
||||
)
|
||||
|
||||
hs = self.setup_test_homeserver(config=config)
|
||||
return hs
|
||||
@ -157,29 +176,36 @@ class DomainRuleCheckerRoomTestCase(unittest.HomeserverTestCase):
|
||||
assert channel.result["code"] == b"403", channel.result
|
||||
|
||||
def test_normal_user_cannot_create_room_with_multiple_invites(self):
|
||||
channel = self._create_room(self.normal_access_token, content={
|
||||
"invite": [self.other_user_id, self.admin_user_id],
|
||||
})
|
||||
channel = self._create_room(
|
||||
self.normal_access_token,
|
||||
content={"invite": [self.other_user_id, self.admin_user_id]},
|
||||
)
|
||||
assert channel.result["code"] == b"403", channel.result
|
||||
|
||||
# Test that it correctly counts both normal and third party invites
|
||||
channel = self._create_room(self.normal_access_token, content={
|
||||
"invite": [self.other_user_id],
|
||||
"invite_3pid": [{"medium": "email", "address": "foo@example.com"}],
|
||||
})
|
||||
channel = self._create_room(
|
||||
self.normal_access_token,
|
||||
content={
|
||||
"invite": [self.other_user_id],
|
||||
"invite_3pid": [{"medium": "email", "address": "foo@example.com"}],
|
||||
},
|
||||
)
|
||||
assert channel.result["code"] == b"403", channel.result
|
||||
|
||||
# Test that it correctly rejects third party invites
|
||||
channel = self._create_room(self.normal_access_token, content={
|
||||
"invite": [],
|
||||
"invite_3pid": [{"medium": "email", "address": "foo@example.com"}],
|
||||
})
|
||||
channel = self._create_room(
|
||||
self.normal_access_token,
|
||||
content={
|
||||
"invite": [],
|
||||
"invite_3pid": [{"medium": "email", "address": "foo@example.com"}],
|
||||
},
|
||||
)
|
||||
assert channel.result["code"] == b"403", channel.result
|
||||
|
||||
def test_normal_user_can_room_with_single_invites(self):
|
||||
channel = self._create_room(self.normal_access_token, content={
|
||||
"invite": [self.other_user_id],
|
||||
})
|
||||
channel = self._create_room(
|
||||
self.normal_access_token, content={"invite": [self.other_user_id]}
|
||||
)
|
||||
assert channel.result["code"] == b"200", channel.result
|
||||
|
||||
def test_cannot_join_public_room(self):
|
||||
@ -189,9 +215,7 @@ class DomainRuleCheckerRoomTestCase(unittest.HomeserverTestCase):
|
||||
room_id = channel.json_body["room_id"]
|
||||
|
||||
self.helper.join(
|
||||
room_id, self.normal_user_id,
|
||||
tok=self.normal_access_token,
|
||||
expect_code=403,
|
||||
room_id, self.normal_user_id, tok=self.normal_access_token, expect_code=403
|
||||
)
|
||||
|
||||
def test_can_join_invited_room(self):
|
||||
@ -208,9 +232,7 @@ class DomainRuleCheckerRoomTestCase(unittest.HomeserverTestCase):
|
||||
)
|
||||
|
||||
self.helper.join(
|
||||
room_id, self.normal_user_id,
|
||||
tok=self.normal_access_token,
|
||||
expect_code=200,
|
||||
room_id, self.normal_user_id, tok=self.normal_access_token, expect_code=200
|
||||
)
|
||||
|
||||
def test_cannot_invite(self):
|
||||
@ -227,9 +249,7 @@ class DomainRuleCheckerRoomTestCase(unittest.HomeserverTestCase):
|
||||
)
|
||||
|
||||
self.helper.join(
|
||||
room_id, self.normal_user_id,
|
||||
tok=self.normal_access_token,
|
||||
expect_code=200,
|
||||
room_id, self.normal_user_id, tok=self.normal_access_token, expect_code=200
|
||||
)
|
||||
|
||||
self.helper.invite(
|
||||
@ -241,12 +261,12 @@ class DomainRuleCheckerRoomTestCase(unittest.HomeserverTestCase):
|
||||
)
|
||||
|
||||
def _create_room(self, token, content={}):
|
||||
path = "/_matrix/client/r0/createRoom?access_token=%s" % (
|
||||
token,
|
||||
)
|
||||
path = "/_matrix/client/r0/createRoom?access_token=%s" % (token,)
|
||||
|
||||
request, channel = make_request(
|
||||
self.hs.get_reactor(), "POST", path,
|
||||
self.hs.get_reactor(),
|
||||
"POST",
|
||||
path,
|
||||
content=json.dumps(content).encode("utf8"),
|
||||
)
|
||||
render(request, self.resource, self.hs.get_reactor())
|
||||
|
Loading…
Reference in New Issue
Block a user