mirror of
https://mau.dev/maunium/synapse.git
synced 2024-10-01 01:36:05 -04:00
Add tests
This commit is contained in:
parent
a4a9ded4d0
commit
bc35503528
@ -323,6 +323,8 @@ class AccountValidityRenewalByEmailTestCase(unittest.HomeserverTestCase):
|
|||||||
"renew_at": 172800000, # Time in ms for 2 days
|
"renew_at": 172800000, # Time in ms for 2 days
|
||||||
"renew_by_email_enabled": True,
|
"renew_by_email_enabled": True,
|
||||||
"renew_email_subject": "Renew your account",
|
"renew_email_subject": "Renew your account",
|
||||||
|
"account_renewed_html_path": "account_renewed.html",
|
||||||
|
"invalid_token_html_path": "invalid_token.html",
|
||||||
}
|
}
|
||||||
|
|
||||||
# Email config.
|
# Email config.
|
||||||
@ -373,6 +375,19 @@ class AccountValidityRenewalByEmailTestCase(unittest.HomeserverTestCase):
|
|||||||
self.render(request)
|
self.render(request)
|
||||||
self.assertEquals(channel.result["code"], b"200", channel.result)
|
self.assertEquals(channel.result["code"], b"200", channel.result)
|
||||||
|
|
||||||
|
# Check that we're getting HTML back.
|
||||||
|
content_type = None
|
||||||
|
for header in channel.result.get("headers", []):
|
||||||
|
if header[0] == b"Content-Type":
|
||||||
|
content_type = header[1]
|
||||||
|
self.assertEqual(content_type, b"text/html; charset=utf-8", channel.result)
|
||||||
|
|
||||||
|
# Check that the HTML we're getting is the one we expect on a successful renewal.
|
||||||
|
expected_html = self.hs.config.account_validity.account_renewed_html_content
|
||||||
|
self.assertEqual(
|
||||||
|
channel.result["body"], expected_html.encode("utf8"), channel.result
|
||||||
|
)
|
||||||
|
|
||||||
# Move 3 days forward. If the renewal failed, every authed request with
|
# Move 3 days forward. If the renewal failed, every authed request with
|
||||||
# our access token should be denied from now, otherwise they should
|
# our access token should be denied from now, otherwise they should
|
||||||
# succeed.
|
# succeed.
|
||||||
@ -381,6 +396,28 @@ class AccountValidityRenewalByEmailTestCase(unittest.HomeserverTestCase):
|
|||||||
self.render(request)
|
self.render(request)
|
||||||
self.assertEquals(channel.result["code"], b"200", channel.result)
|
self.assertEquals(channel.result["code"], b"200", channel.result)
|
||||||
|
|
||||||
|
def test_renewal_invalid_token(self):
|
||||||
|
# Hit the renewal endpoint with an invalid token and check that it behaves as
|
||||||
|
# expected, i.e. that it responds with 404 Not Found and the correct HTML.
|
||||||
|
url = "/_matrix/client/unstable/account_validity/renew?token=123"
|
||||||
|
request, channel = self.make_request(b"GET", url)
|
||||||
|
self.render(request)
|
||||||
|
self.assertEquals(channel.result["code"], b"404", channel.result)
|
||||||
|
|
||||||
|
# Check that we're getting HTML back.
|
||||||
|
content_type = None
|
||||||
|
for header in channel.result.get("headers", []):
|
||||||
|
if header[0] == b"Content-Type":
|
||||||
|
content_type = header[1]
|
||||||
|
self.assertEqual(content_type, b"text/html; charset=utf-8", channel.result)
|
||||||
|
|
||||||
|
# Check that the HTML we're getting is the one we expect when using an
|
||||||
|
# invalid/unknown token.
|
||||||
|
expected_html = self.hs.config.account_validity.invalid_token_html_content
|
||||||
|
self.assertEqual(
|
||||||
|
channel.result["body"], expected_html.encode("utf8"), channel.result
|
||||||
|
)
|
||||||
|
|
||||||
def test_manual_email_send(self):
|
def test_manual_email_send(self):
|
||||||
self.email_attempts = []
|
self.email_attempts = []
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user