test_room_directory.py 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. # -*- coding: utf-8 -*-
  2. # Copyright 2018 New Vector Ltd
  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. import yaml
  16. from synapse.config.room_directory import RoomDirectoryConfig
  17. from tests import unittest
  18. class RoomDirectoryConfigTestCase(unittest.TestCase):
  19. def test_alias_creation_acl(self):
  20. config = yaml.load("""
  21. alias_creation_rules:
  22. - user_id: "*bob*"
  23. alias: "*"
  24. action: "deny"
  25. - user_id: "*"
  26. alias: "#unofficial_*"
  27. action: "allow"
  28. - user_id: "@foo*:example.com"
  29. alias: "*"
  30. action: "allow"
  31. - user_id: "@gah:example.com"
  32. alias: "#goo:example.com"
  33. action: "allow"
  34. """)
  35. rd_config = RoomDirectoryConfig()
  36. rd_config.read_config(config)
  37. self.assertFalse(rd_config.is_alias_creation_allowed(
  38. user_id="@bob:example.com",
  39. alias="#test:example.com",
  40. ))
  41. self.assertTrue(rd_config.is_alias_creation_allowed(
  42. user_id="@test:example.com",
  43. alias="#unofficial_st:example.com",
  44. ))
  45. self.assertTrue(rd_config.is_alias_creation_allowed(
  46. user_id="@foobar:example.com",
  47. alias="#test:example.com",
  48. ))
  49. self.assertTrue(rd_config.is_alias_creation_allowed(
  50. user_id="@gah:example.com",
  51. alias="#goo:example.com",
  52. ))
  53. self.assertFalse(rd_config.is_alias_creation_allowed(
  54. user_id="@test:example.com",
  55. alias="#test:example.com",
  56. ))