2019-04-08 12:10:55 -04:00
|
|
|
import datetime
|
2018-07-09 02:09:20 -04:00
|
|
|
import json
|
2019-04-10 12:58:47 -04:00
|
|
|
import os
|
|
|
|
|
|
|
|
import pkg_resources
|
2018-07-09 02:09:20 -04:00
|
|
|
|
2019-05-01 10:32:38 -04:00
|
|
|
import synapse.rest.admin
|
2019-02-18 11:49:38 -05:00
|
|
|
from synapse.api.constants import LoginType
|
2019-04-08 12:10:55 -04:00
|
|
|
from synapse.api.errors import Codes
|
2019-02-18 11:49:38 -05:00
|
|
|
from synapse.appservice import ApplicationService
|
2019-05-01 10:32:38 -04:00
|
|
|
from synapse.rest.client.v1 import login
|
2019-04-10 12:58:47 -04:00
|
|
|
from synapse.rest.client.v2_alpha import account_validity, register, sync
|
2018-07-09 02:09:20 -04:00
|
|
|
|
2015-07-28 12:34:12 -04:00
|
|
|
from tests import unittest
|
|
|
|
|
2019-04-10 12:58:47 -04:00
|
|
|
try:
|
|
|
|
from synapse.push.mailer import load_jinja2_templates
|
|
|
|
except ImportError:
|
|
|
|
load_jinja2_templates = None
|
|
|
|
|
2015-07-28 12:34:12 -04:00
|
|
|
|
2018-11-06 11:00:00 -05:00
|
|
|
class RegisterRestServletTestCase(unittest.HomeserverTestCase):
|
|
|
|
|
2019-04-08 12:10:55 -04:00
|
|
|
servlets = [register.register_servlets]
|
2018-11-06 11:00:00 -05:00
|
|
|
|
|
|
|
def make_homeserver(self, reactor, clock):
|
2018-07-17 06:43:18 -04:00
|
|
|
|
|
|
|
self.url = b"/_matrix/client/r0/register"
|
2015-07-28 12:34:12 -04:00
|
|
|
|
2018-11-06 11:00:00 -05:00
|
|
|
self.hs = self.setup_test_homeserver()
|
2016-02-03 09:42:01 -05:00
|
|
|
self.hs.config.enable_registration = True
|
2018-01-18 19:28:08 -05:00
|
|
|
self.hs.config.registrations_require_3pid = []
|
2017-10-17 05:39:50 -04:00
|
|
|
self.hs.config.auto_join_rooms = []
|
2019-02-18 11:49:38 -05:00
|
|
|
self.hs.config.enable_registration_captcha = False
|
2019-03-19 07:01:02 -04:00
|
|
|
self.hs.config.allow_guest_access = True
|
2015-07-28 12:34:12 -04:00
|
|
|
|
2018-11-06 11:00:00 -05:00
|
|
|
return self.hs
|
2015-07-28 12:34:12 -04:00
|
|
|
|
|
|
|
def test_POST_appservice_registration_valid(self):
|
2019-02-18 11:49:38 -05:00
|
|
|
user_id = "@as_user_kermit:test"
|
|
|
|
as_token = "i_am_an_app_service"
|
|
|
|
|
|
|
|
appservice = ApplicationService(
|
2019-05-10 01:12:11 -04:00
|
|
|
as_token,
|
|
|
|
self.hs.config.server_name,
|
2019-02-18 11:49:38 -05:00
|
|
|
id="1234",
|
2019-05-10 01:12:11 -04:00
|
|
|
namespaces={"users": [{"regex": r"@as_user.*", "exclusive": True}]},
|
2019-02-18 11:49:38 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
self.hs.get_datastore().services_cache.append(appservice)
|
|
|
|
request_data = json.dumps({"username": "as_user_kermit"})
|
2018-07-17 06:43:18 -04:00
|
|
|
|
2018-11-06 11:00:00 -05:00
|
|
|
request, channel = self.make_request(
|
2018-07-17 06:43:18 -04:00
|
|
|
b"POST", self.url + b"?access_token=i_am_an_app_service", request_data
|
2016-07-22 09:52:53 -04:00
|
|
|
)
|
2018-11-06 11:00:00 -05:00
|
|
|
self.render(request)
|
2016-07-19 13:46:19 -04:00
|
|
|
|
2018-07-17 06:43:18 -04:00
|
|
|
self.assertEquals(channel.result["code"], b"200", channel.result)
|
2019-05-10 01:12:11 -04:00
|
|
|
det_data = {"user_id": user_id, "home_server": self.hs.hostname}
|
2018-08-08 22:22:01 -04:00
|
|
|
self.assertDictContainsSubset(det_data, channel.json_body)
|
2015-07-28 12:34:12 -04:00
|
|
|
|
|
|
|
def test_POST_appservice_registration_invalid(self):
|
|
|
|
self.appservice = None # no application service exists
|
2018-07-17 06:43:18 -04:00
|
|
|
request_data = json.dumps({"username": "kermit"})
|
2018-11-06 11:00:00 -05:00
|
|
|
request, channel = self.make_request(
|
2018-07-17 06:43:18 -04:00
|
|
|
b"POST", self.url + b"?access_token=i_am_an_app_service", request_data
|
|
|
|
)
|
2018-11-06 11:00:00 -05:00
|
|
|
self.render(request)
|
2018-07-17 06:43:18 -04:00
|
|
|
|
|
|
|
self.assertEquals(channel.result["code"], b"401", channel.result)
|
2015-07-28 12:34:12 -04:00
|
|
|
|
|
|
|
def test_POST_bad_password(self):
|
2018-07-17 06:43:18 -04:00
|
|
|
request_data = json.dumps({"username": "kermit", "password": 666})
|
2018-11-06 11:00:00 -05:00
|
|
|
request, channel = self.make_request(b"POST", self.url, request_data)
|
|
|
|
self.render(request)
|
2018-07-17 06:43:18 -04:00
|
|
|
|
|
|
|
self.assertEquals(channel.result["code"], b"400", channel.result)
|
2018-08-10 09:54:09 -04:00
|
|
|
self.assertEquals(channel.json_body["error"], "Invalid password")
|
2015-07-28 12:34:12 -04:00
|
|
|
|
|
|
|
def test_POST_bad_username(self):
|
2018-07-17 06:43:18 -04:00
|
|
|
request_data = json.dumps({"username": 777, "password": "monkey"})
|
2018-11-06 11:00:00 -05:00
|
|
|
request, channel = self.make_request(b"POST", self.url, request_data)
|
|
|
|
self.render(request)
|
2018-07-17 06:43:18 -04:00
|
|
|
|
|
|
|
self.assertEquals(channel.result["code"], b"400", channel.result)
|
2018-08-10 09:54:09 -04:00
|
|
|
self.assertEquals(channel.json_body["error"], "Invalid username")
|
2018-07-17 06:43:18 -04:00
|
|
|
|
2015-07-28 12:34:12 -04:00
|
|
|
def test_POST_user_valid(self):
|
2019-02-18 11:49:38 -05:00
|
|
|
user_id = "@kermit:test"
|
2016-07-19 13:38:26 -04:00
|
|
|
device_id = "frogfone"
|
2019-02-18 11:49:38 -05:00
|
|
|
params = {
|
|
|
|
"username": "kermit",
|
|
|
|
"password": "monkey",
|
|
|
|
"device_id": device_id,
|
|
|
|
"auth": {"type": LoginType.DUMMY},
|
|
|
|
}
|
2019-02-18 08:43:16 -05:00
|
|
|
request_data = json.dumps(params)
|
2018-11-06 11:00:00 -05:00
|
|
|
request, channel = self.make_request(b"POST", self.url, request_data)
|
|
|
|
self.render(request)
|
2015-07-28 12:34:12 -04:00
|
|
|
|
2016-03-09 18:08:37 -05:00
|
|
|
det_data = {
|
2016-03-10 04:13:35 -05:00
|
|
|
"user_id": user_id,
|
2016-07-19 13:38:26 -04:00
|
|
|
"home_server": self.hs.hostname,
|
|
|
|
"device_id": device_id,
|
2016-03-09 18:08:37 -05:00
|
|
|
}
|
2018-07-17 06:43:18 -04:00
|
|
|
self.assertEquals(channel.result["code"], b"200", channel.result)
|
2018-08-08 22:22:01 -04:00
|
|
|
self.assertDictContainsSubset(det_data, channel.json_body)
|
2015-07-28 12:34:12 -04:00
|
|
|
|
|
|
|
def test_POST_disabled_registration(self):
|
2016-02-03 09:42:01 -05:00
|
|
|
self.hs.config.enable_registration = False
|
2018-07-17 06:43:18 -04:00
|
|
|
request_data = json.dumps({"username": "kermit", "password": "monkey"})
|
|
|
|
self.auth_result = (None, {"username": "kermit", "password": "monkey"}, None)
|
|
|
|
|
2018-11-06 11:00:00 -05:00
|
|
|
request, channel = self.make_request(b"POST", self.url, request_data)
|
|
|
|
self.render(request)
|
2018-07-17 06:43:18 -04:00
|
|
|
|
|
|
|
self.assertEquals(channel.result["code"], b"403", channel.result)
|
2018-08-10 09:54:09 -04:00
|
|
|
self.assertEquals(channel.json_body["error"], "Registration has been disabled")
|
2018-07-17 06:43:18 -04:00
|
|
|
|
|
|
|
def test_POST_guest_registration(self):
|
|
|
|
self.hs.config.macaroon_secret_key = "test"
|
|
|
|
self.hs.config.allow_guest_access = True
|
|
|
|
|
2018-11-06 11:00:00 -05:00
|
|
|
request, channel = self.make_request(b"POST", self.url + b"?kind=guest", b"{}")
|
|
|
|
self.render(request)
|
2018-07-17 06:43:18 -04:00
|
|
|
|
2019-05-10 01:12:11 -04:00
|
|
|
det_data = {"home_server": self.hs.hostname, "device_id": "guest_device"}
|
2018-07-17 06:43:18 -04:00
|
|
|
self.assertEquals(channel.result["code"], b"200", channel.result)
|
2018-08-08 22:22:01 -04:00
|
|
|
self.assertDictContainsSubset(det_data, channel.json_body)
|
2018-07-17 06:43:18 -04:00
|
|
|
|
|
|
|
def test_POST_disabled_guest_registration(self):
|
|
|
|
self.hs.config.allow_guest_access = False
|
|
|
|
|
2018-11-06 11:00:00 -05:00
|
|
|
request, channel = self.make_request(b"POST", self.url + b"?kind=guest", b"{}")
|
|
|
|
self.render(request)
|
2018-07-17 06:43:18 -04:00
|
|
|
|
|
|
|
self.assertEquals(channel.result["code"], b"403", channel.result)
|
2018-08-10 09:54:09 -04:00
|
|
|
self.assertEquals(channel.json_body["error"], "Guest access is disabled")
|
2019-03-05 09:25:33 -05:00
|
|
|
|
|
|
|
def test_POST_ratelimiting_guest(self):
|
2019-03-15 13:46:16 -04:00
|
|
|
self.hs.config.rc_registration.burst_count = 5
|
|
|
|
self.hs.config.rc_registration.per_second = 0.17
|
2019-03-05 09:25:33 -05:00
|
|
|
|
|
|
|
for i in range(0, 6):
|
|
|
|
url = self.url + b"?kind=guest"
|
|
|
|
request, channel = self.make_request(b"POST", url, b"{}")
|
|
|
|
self.render(request)
|
|
|
|
|
|
|
|
if i == 5:
|
|
|
|
self.assertEquals(channel.result["code"], b"429", channel.result)
|
|
|
|
retry_after_ms = int(channel.json_body["retry_after_ms"])
|
|
|
|
else:
|
|
|
|
self.assertEquals(channel.result["code"], b"200", channel.result)
|
|
|
|
|
2019-05-10 01:12:11 -04:00
|
|
|
self.reactor.advance(retry_after_ms / 1000.0)
|
2019-03-05 09:25:33 -05:00
|
|
|
|
|
|
|
request, channel = self.make_request(b"POST", self.url + b"?kind=guest", b"{}")
|
|
|
|
self.render(request)
|
|
|
|
|
|
|
|
self.assertEquals(channel.result["code"], b"200", channel.result)
|
|
|
|
|
|
|
|
def test_POST_ratelimiting(self):
|
2019-03-15 13:46:16 -04:00
|
|
|
self.hs.config.rc_registration.burst_count = 5
|
|
|
|
self.hs.config.rc_registration.per_second = 0.17
|
2019-03-05 09:25:33 -05:00
|
|
|
|
|
|
|
for i in range(0, 6):
|
|
|
|
params = {
|
|
|
|
"username": "kermit" + str(i),
|
|
|
|
"password": "monkey",
|
|
|
|
"device_id": "frogfone",
|
|
|
|
"auth": {"type": LoginType.DUMMY},
|
|
|
|
}
|
|
|
|
request_data = json.dumps(params)
|
|
|
|
request, channel = self.make_request(b"POST", self.url, request_data)
|
|
|
|
self.render(request)
|
|
|
|
|
|
|
|
if i == 5:
|
|
|
|
self.assertEquals(channel.result["code"], b"429", channel.result)
|
|
|
|
retry_after_ms = int(channel.json_body["retry_after_ms"])
|
|
|
|
else:
|
|
|
|
self.assertEquals(channel.result["code"], b"200", channel.result)
|
|
|
|
|
2019-05-10 01:12:11 -04:00
|
|
|
self.reactor.advance(retry_after_ms / 1000.0)
|
2019-03-05 09:25:33 -05:00
|
|
|
|
|
|
|
request, channel = self.make_request(b"POST", self.url + b"?kind=guest", b"{}")
|
|
|
|
self.render(request)
|
|
|
|
|
|
|
|
self.assertEquals(channel.result["code"], b"200", channel.result)
|
2019-04-08 12:10:55 -04:00
|
|
|
|
|
|
|
|
|
|
|
class AccountValidityTestCase(unittest.HomeserverTestCase):
|
|
|
|
|
|
|
|
servlets = [
|
|
|
|
register.register_servlets,
|
2019-05-02 06:59:16 -04:00
|
|
|
synapse.rest.admin.register_servlets_for_client_rest_resource,
|
2019-04-08 12:10:55 -04:00
|
|
|
login.register_servlets,
|
|
|
|
sync.register_servlets,
|
2019-04-16 15:13:59 -04:00
|
|
|
account_validity.register_servlets,
|
2019-04-08 12:10:55 -04:00
|
|
|
]
|
|
|
|
|
|
|
|
def make_homeserver(self, reactor, clock):
|
|
|
|
config = self.default_config()
|
2019-04-10 12:58:47 -04:00
|
|
|
# Test for account expiring after a week.
|
2019-05-13 16:01:14 -04:00
|
|
|
config["enable_registration"] = True
|
|
|
|
config["account_validity"] = {
|
|
|
|
"enabled": True,
|
|
|
|
"period": 604800000, # Time in ms for 1 week
|
|
|
|
}
|
2019-04-08 12:10:55 -04:00
|
|
|
self.hs = self.setup_test_homeserver(config=config)
|
|
|
|
|
|
|
|
return self.hs
|
|
|
|
|
|
|
|
def test_validity_period(self):
|
|
|
|
self.register_user("kermit", "monkey")
|
|
|
|
tok = self.login("kermit", "monkey")
|
|
|
|
|
|
|
|
# The specific endpoint doesn't matter, all we need is an authenticated
|
|
|
|
# endpoint.
|
2019-05-10 01:12:11 -04:00
|
|
|
request, channel = self.make_request(b"GET", "/sync", access_token=tok)
|
2019-04-08 12:10:55 -04:00
|
|
|
self.render(request)
|
|
|
|
|
|
|
|
self.assertEquals(channel.result["code"], b"200", channel.result)
|
|
|
|
|
|
|
|
self.reactor.advance(datetime.timedelta(weeks=1).total_seconds())
|
|
|
|
|
2019-05-10 01:12:11 -04:00
|
|
|
request, channel = self.make_request(b"GET", "/sync", access_token=tok)
|
2019-04-08 12:10:55 -04:00
|
|
|
self.render(request)
|
|
|
|
|
|
|
|
self.assertEquals(channel.result["code"], b"403", channel.result)
|
|
|
|
self.assertEquals(
|
2019-05-10 01:12:11 -04:00
|
|
|
channel.json_body["errcode"], Codes.EXPIRED_ACCOUNT, channel.result
|
2019-04-08 12:10:55 -04:00
|
|
|
)
|
2019-04-10 12:58:47 -04:00
|
|
|
|
2019-04-16 15:13:59 -04:00
|
|
|
def test_manual_renewal(self):
|
|
|
|
user_id = self.register_user("kermit", "monkey")
|
|
|
|
tok = self.login("kermit", "monkey")
|
|
|
|
|
|
|
|
self.reactor.advance(datetime.timedelta(weeks=1).total_seconds())
|
|
|
|
|
|
|
|
# If we register the admin user at the beginning of the test, it will
|
|
|
|
# expire at the same time as the normal user and the renewal request
|
|
|
|
# will be denied.
|
|
|
|
self.register_user("admin", "adminpassword", admin=True)
|
|
|
|
admin_tok = self.login("admin", "adminpassword")
|
|
|
|
|
|
|
|
url = "/_matrix/client/unstable/admin/account_validity/validity"
|
2019-05-10 01:12:11 -04:00
|
|
|
params = {"user_id": user_id}
|
2019-04-16 15:13:59 -04:00
|
|
|
request_data = json.dumps(params)
|
|
|
|
request, channel = self.make_request(
|
2019-05-10 01:12:11 -04:00
|
|
|
b"POST", url, request_data, access_token=admin_tok
|
2019-04-16 15:13:59 -04:00
|
|
|
)
|
|
|
|
self.render(request)
|
|
|
|
self.assertEquals(channel.result["code"], b"200", channel.result)
|
|
|
|
|
|
|
|
# The specific endpoint doesn't matter, all we need is an authenticated
|
|
|
|
# endpoint.
|
2019-05-10 01:12:11 -04:00
|
|
|
request, channel = self.make_request(b"GET", "/sync", access_token=tok)
|
2019-04-16 15:13:59 -04:00
|
|
|
self.render(request)
|
|
|
|
self.assertEquals(channel.result["code"], b"200", channel.result)
|
|
|
|
|
|
|
|
def test_manual_expire(self):
|
|
|
|
user_id = self.register_user("kermit", "monkey")
|
|
|
|
tok = self.login("kermit", "monkey")
|
|
|
|
|
|
|
|
self.register_user("admin", "adminpassword", admin=True)
|
|
|
|
admin_tok = self.login("admin", "adminpassword")
|
|
|
|
|
|
|
|
url = "/_matrix/client/unstable/admin/account_validity/validity"
|
|
|
|
params = {
|
|
|
|
"user_id": user_id,
|
|
|
|
"expiration_ts": 0,
|
|
|
|
"enable_renewal_emails": False,
|
|
|
|
}
|
|
|
|
request_data = json.dumps(params)
|
|
|
|
request, channel = self.make_request(
|
2019-05-10 01:12:11 -04:00
|
|
|
b"POST", url, request_data, access_token=admin_tok
|
2019-04-16 15:13:59 -04:00
|
|
|
)
|
|
|
|
self.render(request)
|
|
|
|
self.assertEquals(channel.result["code"], b"200", channel.result)
|
|
|
|
|
|
|
|
# The specific endpoint doesn't matter, all we need is an authenticated
|
|
|
|
# endpoint.
|
2019-05-10 01:12:11 -04:00
|
|
|
request, channel = self.make_request(b"GET", "/sync", access_token=tok)
|
2019-04-16 15:13:59 -04:00
|
|
|
self.render(request)
|
|
|
|
self.assertEquals(channel.result["code"], b"403", channel.result)
|
|
|
|
self.assertEquals(
|
2019-05-10 01:12:11 -04:00
|
|
|
channel.json_body["errcode"], Codes.EXPIRED_ACCOUNT, channel.result
|
2019-04-16 15:13:59 -04:00
|
|
|
)
|
|
|
|
|
2019-04-10 12:58:47 -04:00
|
|
|
|
|
|
|
class AccountValidityRenewalByEmailTestCase(unittest.HomeserverTestCase):
|
|
|
|
|
|
|
|
skip = "No Jinja installed" if not load_jinja2_templates else None
|
|
|
|
servlets = [
|
|
|
|
register.register_servlets,
|
2019-05-02 06:59:16 -04:00
|
|
|
synapse.rest.admin.register_servlets_for_client_rest_resource,
|
2019-04-10 12:58:47 -04:00
|
|
|
login.register_servlets,
|
|
|
|
sync.register_servlets,
|
|
|
|
account_validity.register_servlets,
|
|
|
|
]
|
|
|
|
|
|
|
|
def make_homeserver(self, reactor, clock):
|
|
|
|
config = self.default_config()
|
2019-05-13 16:01:14 -04:00
|
|
|
|
2019-04-10 12:58:47 -04:00
|
|
|
# Test for account expiring after a week and renewal emails being sent 2
|
|
|
|
# days before expiry.
|
2019-05-13 16:01:14 -04:00
|
|
|
config["enable_registration"] = True
|
|
|
|
config["account_validity"] = {
|
|
|
|
"enabled": True,
|
|
|
|
"period": 604800000, # Time in ms for 1 week
|
|
|
|
"renew_at": 172800000, # Time in ms for 2 days
|
|
|
|
"renew_by_email_enabled": True,
|
|
|
|
"renew_email_subject": "Renew your account",
|
|
|
|
}
|
2019-04-10 12:58:47 -04:00
|
|
|
|
|
|
|
# Email config.
|
|
|
|
self.email_attempts = []
|
|
|
|
|
|
|
|
def sendmail(*args, **kwargs):
|
|
|
|
self.email_attempts.append((args, kwargs))
|
|
|
|
return
|
|
|
|
|
2019-05-13 16:01:14 -04:00
|
|
|
config["email"] = {
|
|
|
|
"enable_notifs": True,
|
|
|
|
"template_dir": os.path.abspath(
|
|
|
|
pkg_resources.resource_filename('synapse', 'res/templates')
|
|
|
|
),
|
|
|
|
"expiry_template_html": "notice_expiry.html",
|
|
|
|
"expiry_template_text": "notice_expiry.txt",
|
|
|
|
"notif_template_html": "notif_mail.html",
|
|
|
|
"notif_template_text": "notif_mail.txt",
|
|
|
|
"smtp_host": "127.0.0.1",
|
|
|
|
"smtp_port": 20,
|
|
|
|
"require_transport_security": False,
|
|
|
|
"smtp_user": None,
|
|
|
|
"smtp_pass": None,
|
|
|
|
"notif_from": "test@example.com",
|
|
|
|
}
|
|
|
|
config["public_baseurl"] = "aaa"
|
2019-04-10 12:58:47 -04:00
|
|
|
|
|
|
|
self.hs = self.setup_test_homeserver(config=config, sendmail=sendmail)
|
|
|
|
|
|
|
|
self.store = self.hs.get_datastore()
|
|
|
|
|
|
|
|
return self.hs
|
|
|
|
|
|
|
|
def test_renewal_email(self):
|
2019-04-16 15:13:59 -04:00
|
|
|
self.email_attempts = []
|
|
|
|
|
2019-04-10 12:58:47 -04:00
|
|
|
user_id = self.register_user("kermit", "monkey")
|
|
|
|
tok = self.login("kermit", "monkey")
|
|
|
|
# We need to manually add an email address otherwise the handler will do
|
|
|
|
# nothing.
|
|
|
|
now = self.hs.clock.time_msec()
|
2019-05-10 01:12:11 -04:00
|
|
|
self.get_success(
|
|
|
|
self.store.user_add_threepid(
|
|
|
|
user_id=user_id,
|
|
|
|
medium="email",
|
|
|
|
address="kermit@example.com",
|
|
|
|
validated_at=now,
|
|
|
|
added_at=now,
|
|
|
|
)
|
|
|
|
)
|
2019-04-10 12:58:47 -04:00
|
|
|
|
|
|
|
# Move 6 days forward. This should trigger a renewal email to be sent.
|
|
|
|
self.reactor.advance(datetime.timedelta(days=6).total_seconds())
|
|
|
|
self.assertEqual(len(self.email_attempts), 1)
|
|
|
|
|
|
|
|
# Retrieving the URL from the email is too much pain for now, so we
|
|
|
|
# retrieve the token from the DB.
|
|
|
|
renewal_token = self.get_success(self.store.get_renewal_token_for_user(user_id))
|
|
|
|
url = "/_matrix/client/unstable/account_validity/renew?token=%s" % renewal_token
|
|
|
|
request, channel = self.make_request(b"GET", url)
|
|
|
|
self.render(request)
|
|
|
|
self.assertEquals(channel.result["code"], b"200", channel.result)
|
|
|
|
|
|
|
|
# Move 3 days forward. If the renewal failed, every authed request with
|
|
|
|
# our access token should be denied from now, otherwise they should
|
|
|
|
# succeed.
|
|
|
|
self.reactor.advance(datetime.timedelta(days=3).total_seconds())
|
2019-05-10 01:12:11 -04:00
|
|
|
request, channel = self.make_request(b"GET", "/sync", access_token=tok)
|
2019-04-10 12:58:47 -04:00
|
|
|
self.render(request)
|
|
|
|
self.assertEquals(channel.result["code"], b"200", channel.result)
|
2019-04-16 15:13:59 -04:00
|
|
|
|
|
|
|
def test_manual_email_send(self):
|
|
|
|
self.email_attempts = []
|
|
|
|
|
|
|
|
user_id = self.register_user("kermit", "monkey")
|
|
|
|
tok = self.login("kermit", "monkey")
|
|
|
|
# We need to manually add an email address otherwise the handler will do
|
|
|
|
# nothing.
|
|
|
|
now = self.hs.clock.time_msec()
|
2019-05-10 01:12:11 -04:00
|
|
|
self.get_success(
|
|
|
|
self.store.user_add_threepid(
|
|
|
|
user_id=user_id,
|
|
|
|
medium="email",
|
|
|
|
address="kermit@example.com",
|
|
|
|
validated_at=now,
|
|
|
|
added_at=now,
|
|
|
|
)
|
|
|
|
)
|
2019-04-16 15:13:59 -04:00
|
|
|
|
|
|
|
request, channel = self.make_request(
|
2019-05-10 01:12:11 -04:00
|
|
|
b"POST",
|
|
|
|
"/_matrix/client/unstable/account_validity/send_mail",
|
2019-04-16 15:13:59 -04:00
|
|
|
access_token=tok,
|
|
|
|
)
|
|
|
|
self.render(request)
|
|
|
|
self.assertEquals(channel.result["code"], b"200", channel.result)
|
|
|
|
|
|
|
|
self.assertEqual(len(self.email_attempts), 1)
|