test_register.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. # -*- coding: utf-8 -*-
  2. # Copyright 2021 The Matrix.org Foundation C.I.C.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. from twisted.trial import unittest
  16. from tests.utils import make_request, make_sydent
  17. class RegisterTestCase(unittest.TestCase):
  18. """Tests Sydent's register servlet"""
  19. def setUp(self):
  20. # Create a new sydent
  21. self.sydent = make_sydent()
  22. def test_sydent_rejects_invalid_hostname(self):
  23. """Tests that the /register endpoint rejects an invalid hostname passed as matrix_server_name"""
  24. self.sydent.run()
  25. bad_hostname = "example.com#"
  26. request, channel = make_request(
  27. self.sydent.reactor,
  28. "POST",
  29. "/_matrix/identity/v2/account/register",
  30. content={
  31. "matrix_server_name": bad_hostname,
  32. "access_token": "foo"
  33. })
  34. request.render(self.sydent.servlets.registerServlet)
  35. self.assertEqual(channel.code, 400)