test_register.py 1.4 KB

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