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