1
0

test_stringutils.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. # -*- coding: utf-8 -*-
  2. # Copyright 2020 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 synapse.api.errors import SynapseError
  16. from synapse.util.stringutils import assert_valid_client_secret
  17. from .. import unittest
  18. class StringUtilsTestCase(unittest.TestCase):
  19. def test_client_secret_regex(self):
  20. """Ensure that client_secret does not contain illegal characters"""
  21. good = [
  22. "abcde12345",
  23. "ABCabc123",
  24. "_--something==_",
  25. "...--==-18913",
  26. "8Dj2odd-e9asd.cd==_--ddas-secret-",
  27. ]
  28. bad = [
  29. "--+-/secret",
  30. "\\dx--dsa288",
  31. "",
  32. "AAS//",
  33. "asdj**",
  34. ">X><Z<!!-)))",
  35. "a@b.com",
  36. ]
  37. for client_secret in good:
  38. assert_valid_client_secret(client_secret)
  39. for client_secret in bad:
  40. with self.assertRaises(SynapseError):
  41. assert_valid_client_secret(client_secret)