Skip to content

Commit

Permalink
Run Black on the tests again (matrix-org#5170)
Browse files Browse the repository at this point in the history
  • Loading branch information
hawkowl authored May 10, 2019
1 parent d9a02d1 commit b36c825
Show file tree
Hide file tree
Showing 54 changed files with 829 additions and 1,169 deletions.
1 change: 1 addition & 0 deletions changelog.d/5170.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Run `black` on the tests directory.
1 change: 0 additions & 1 deletion tests/api/test_filtering.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ def test_valid_filters(self):
"event_format": "client",
"event_fields": ["type", "content", "sender"],
},

# a single backslash should be permitted (though it is debatable whether
# it should be permitted before anything other than `.`, and what that
# actually means)
Expand Down
6 changes: 3 additions & 3 deletions tests/api/test_ratelimiting.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@ def test_allowed(self):
key="test_id", time_now_s=0, rate_hz=0.1, burst_count=1
)
self.assertTrue(allowed)
self.assertEquals(10., time_allowed)
self.assertEquals(10.0, time_allowed)

allowed, time_allowed = limiter.can_do_action(
key="test_id", time_now_s=5, rate_hz=0.1, burst_count=1
)
self.assertFalse(allowed)
self.assertEquals(10., time_allowed)
self.assertEquals(10.0, time_allowed)

allowed, time_allowed = limiter.can_do_action(
key="test_id", time_now_s=10, rate_hz=0.1, burst_count=1
)
self.assertTrue(allowed)
self.assertEquals(20., time_allowed)
self.assertEquals(20.0, time_allowed)

def test_pruning(self):
limiter = Ratelimiter()
Expand Down
46 changes: 22 additions & 24 deletions tests/app/test_openid_listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,18 @@
class FederationReaderOpenIDListenerTests(HomeserverTestCase):
def make_homeserver(self, reactor, clock):
hs = self.setup_test_homeserver(
http_client=None, homeserverToUse=FederationReaderServer,
http_client=None, homeserverToUse=FederationReaderServer
)
return hs

@parameterized.expand([
(["federation"], "auth_fail"),
([], "no_resource"),
(["openid", "federation"], "auth_fail"),
(["openid"], "auth_fail"),
])
@parameterized.expand(
[
(["federation"], "auth_fail"),
([], "no_resource"),
(["openid", "federation"], "auth_fail"),
(["openid"], "auth_fail"),
]
)
def test_openid_listener(self, names, expectation):
"""
Test different openid listener configurations.
Expand All @@ -53,17 +55,14 @@ def test_openid_listener(self, names, expectation):
# Grab the resource from the site that was told to listen
site = self.reactor.tcpServers[0][1]
try:
self.resource = (
site.resource.children[b"_matrix"].children[b"federation"]
)
self.resource = site.resource.children[b"_matrix"].children[b"federation"]
except KeyError:
if expectation == "no_resource":
return
raise

request, channel = self.make_request(
"GET",
"/_matrix/federation/v1/openid/userinfo",
"GET", "/_matrix/federation/v1/openid/userinfo"
)
self.render(request)

Expand All @@ -74,16 +73,18 @@ def test_openid_listener(self, names, expectation):
class SynapseHomeserverOpenIDListenerTests(HomeserverTestCase):
def make_homeserver(self, reactor, clock):
hs = self.setup_test_homeserver(
http_client=None, homeserverToUse=SynapseHomeServer,
http_client=None, homeserverToUse=SynapseHomeServer
)
return hs

@parameterized.expand([
(["federation"], "auth_fail"),
([], "no_resource"),
(["openid", "federation"], "auth_fail"),
(["openid"], "auth_fail"),
])
@parameterized.expand(
[
(["federation"], "auth_fail"),
([], "no_resource"),
(["openid", "federation"], "auth_fail"),
(["openid"], "auth_fail"),
]
)
def test_openid_listener(self, names, expectation):
"""
Test different openid listener configurations.
Expand All @@ -102,17 +103,14 @@ def test_openid_listener(self, names, expectation):
# Grab the resource from the site that was told to listen
site = self.reactor.tcpServers[0][1]
try:
self.resource = (
site.resource.children[b"_matrix"].children[b"federation"]
)
self.resource = site.resource.children[b"_matrix"].children[b"federation"]
except KeyError:
if expectation == "no_resource":
return
raise

request, channel = self.make_request(
"GET",
"/_matrix/federation/v1/openid/userinfo",
"GET", "/_matrix/federation/v1/openid/userinfo"
)
self.render(request)

Expand Down
8 changes: 1 addition & 7 deletions tests/config/test_generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,7 @@ def test_generate_config_generates_files(self):
)

self.assertSetEqual(
set(
[
"homeserver.yaml",
"lemurs.win.log.config",
"lemurs.win.signing.key",
]
),
set(["homeserver.yaml", "lemurs.win.log.config", "lemurs.win.signing.key"]),
set(os.listdir(self.dir)),
)

Expand Down
178 changes: 98 additions & 80 deletions tests/config/test_room_directory.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@

class RoomDirectoryConfigTestCase(unittest.TestCase):
def test_alias_creation_acl(self):
config = yaml.safe_load("""
config = yaml.safe_load(
"""
alias_creation_rules:
- user_id: "*bob*"
alias: "*"
Expand All @@ -38,43 +39,49 @@ def test_alias_creation_acl(self):
action: "allow"
room_list_publication_rules: []
""")
"""
)

rd_config = RoomDirectoryConfig()
rd_config.read_config(config)

self.assertFalse(rd_config.is_alias_creation_allowed(
user_id="@bob:example.com",
room_id="!test",
alias="#test:example.com",
))

self.assertTrue(rd_config.is_alias_creation_allowed(
user_id="@test:example.com",
room_id="!test",
alias="#unofficial_st:example.com",
))

self.assertTrue(rd_config.is_alias_creation_allowed(
user_id="@foobar:example.com",
room_id="!test",
alias="#test:example.com",
))

self.assertTrue(rd_config.is_alias_creation_allowed(
user_id="@gah:example.com",
room_id="!test",
alias="#goo:example.com",
))

self.assertFalse(rd_config.is_alias_creation_allowed(
user_id="@test:example.com",
room_id="!test",
alias="#test:example.com",
))
self.assertFalse(
rd_config.is_alias_creation_allowed(
user_id="@bob:example.com", room_id="!test", alias="#test:example.com"
)
)

self.assertTrue(
rd_config.is_alias_creation_allowed(
user_id="@test:example.com",
room_id="!test",
alias="#unofficial_st:example.com",
)
)

self.assertTrue(
rd_config.is_alias_creation_allowed(
user_id="@foobar:example.com",
room_id="!test",
alias="#test:example.com",
)
)

self.assertTrue(
rd_config.is_alias_creation_allowed(
user_id="@gah:example.com", room_id="!test", alias="#goo:example.com"
)
)

self.assertFalse(
rd_config.is_alias_creation_allowed(
user_id="@test:example.com", room_id="!test", alias="#test:example.com"
)
)

def test_room_publish_acl(self):
config = yaml.safe_load("""
config = yaml.safe_load(
"""
alias_creation_rules: []
room_list_publication_rules:
Expand All @@ -92,55 +99,66 @@ def test_room_publish_acl(self):
action: "allow"
- room_id: "!test-deny"
action: "deny"
""")
"""
)

rd_config = RoomDirectoryConfig()
rd_config.read_config(config)

self.assertFalse(rd_config.is_publishing_room_allowed(
user_id="@bob:example.com",
room_id="!test",
aliases=["#test:example.com"],
))

self.assertTrue(rd_config.is_publishing_room_allowed(
user_id="@test:example.com",
room_id="!test",
aliases=["#unofficial_st:example.com"],
))

self.assertTrue(rd_config.is_publishing_room_allowed(
user_id="@foobar:example.com",
room_id="!test",
aliases=[],
))

self.assertTrue(rd_config.is_publishing_room_allowed(
user_id="@gah:example.com",
room_id="!test",
aliases=["#goo:example.com"],
))

self.assertFalse(rd_config.is_publishing_room_allowed(
user_id="@test:example.com",
room_id="!test",
aliases=["#test:example.com"],
))

self.assertTrue(rd_config.is_publishing_room_allowed(
user_id="@foobar:example.com",
room_id="!test-deny",
aliases=[],
))

self.assertFalse(rd_config.is_publishing_room_allowed(
user_id="@gah:example.com",
room_id="!test-deny",
aliases=[],
))

self.assertTrue(rd_config.is_publishing_room_allowed(
user_id="@test:example.com",
room_id="!test",
aliases=["#unofficial_st:example.com", "#blah:example.com"],
))
self.assertFalse(
rd_config.is_publishing_room_allowed(
user_id="@bob:example.com",
room_id="!test",
aliases=["#test:example.com"],
)
)

self.assertTrue(
rd_config.is_publishing_room_allowed(
user_id="@test:example.com",
room_id="!test",
aliases=["#unofficial_st:example.com"],
)
)

self.assertTrue(
rd_config.is_publishing_room_allowed(
user_id="@foobar:example.com", room_id="!test", aliases=[]
)
)

self.assertTrue(
rd_config.is_publishing_room_allowed(
user_id="@gah:example.com",
room_id="!test",
aliases=["#goo:example.com"],
)
)

self.assertFalse(
rd_config.is_publishing_room_allowed(
user_id="@test:example.com",
room_id="!test",
aliases=["#test:example.com"],
)
)

self.assertTrue(
rd_config.is_publishing_room_allowed(
user_id="@foobar:example.com", room_id="!test-deny", aliases=[]
)
)

self.assertFalse(
rd_config.is_publishing_room_allowed(
user_id="@gah:example.com", room_id="!test-deny", aliases=[]
)
)

self.assertTrue(
rd_config.is_publishing_room_allowed(
user_id="@test:example.com",
room_id="!test",
aliases=["#unofficial_st:example.com", "#blah:example.com"],
)
)
1 change: 0 additions & 1 deletion tests/config/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@


class ServerConfigTestCase(unittest.TestCase):

def test_is_threepid_reserved(self):
user1 = {'medium': 'email', 'address': '[email protected]'}
user2 = {'medium': 'email', 'address': '[email protected]'}
Expand Down
11 changes: 6 additions & 5 deletions tests/config/test_tls.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ def has_tls_listener(self):


class TLSConfigTests(TestCase):

def test_warn_self_signed(self):
"""
Synapse will give a warning when it loads a self-signed certificate.
"""
config_dir = self.mktemp()
os.mkdir(config_dir)
with open(os.path.join(config_dir, "cert.pem"), 'w') as f:
f.write("""-----BEGIN CERTIFICATE-----
f.write(
"""-----BEGIN CERTIFICATE-----
MIID6DCCAtACAws9CjANBgkqhkiG9w0BAQUFADCBtzELMAkGA1UEBhMCVFIxDzAN
BgNVBAgMBsOHb3J1bTEUMBIGA1UEBwwLQmHFn21ha8OnxLExEjAQBgNVBAMMCWxv
Y2FsaG9zdDEcMBoGA1UECgwTVHdpc3RlZCBNYXRyaXggTGFiczEkMCIGA1UECwwb
Expand All @@ -56,11 +56,12 @@ def test_warn_self_signed(self):
iZupikC5MT1LQaRwidkSNxCku1TfAyueiBwhLnFwTmIGNnhuDCutEVAD9kFmcJN2
SznugAcPk4doX2+rL+ila+ThqgPzIkwTUHtnmjI0TI6xsDUlXz5S3UyudrE2Qsfz
s4niecZKPBizL6aucT59CsunNmmb5Glq8rlAcU+1ZTZZzGYqVYhF6axB9Qg=
-----END CERTIFICATE-----""")
-----END CERTIFICATE-----"""
)

config = {
"tls_certificate_path": os.path.join(config_dir, "cert.pem"),
"tls_fingerprints": []
"tls_fingerprints": [],
}

t = TestConfig()
Expand All @@ -75,5 +76,5 @@ def test_warn_self_signed(self):
"Self-signed TLS certificates will not be accepted by "
"Synapse 1.0. Please either provide a valid certificate, "
"or use Synapse's ACME support to provision one."
)
),
)
Loading

0 comments on commit b36c825

Please sign in to comment.