test_keys.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. # -*- coding: utf-8 -*-
  2. # Copyright 2017 Vector Creations 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 signedjson.key
  16. from twisted.internet import defer
  17. import tests.unittest
  18. import tests.utils
  19. class KeyStoreTestCase(tests.unittest.TestCase):
  20. @defer.inlineCallbacks
  21. def setUp(self):
  22. hs = yield tests.utils.setup_test_homeserver(self.addCleanup)
  23. self.store = hs.get_datastore()
  24. @defer.inlineCallbacks
  25. def test_get_server_verify_keys(self):
  26. key1 = signedjson.key.decode_verify_key_base64(
  27. "ed25519", "key1", "fP5l4JzpZPq/zdbBg5xx6lQGAAOM9/3w94cqiJ5jPrw"
  28. )
  29. key2 = signedjson.key.decode_verify_key_base64(
  30. "ed25519", "key2", "Noi6WqcDj0QmPxCNQqgezwTlBKrfqehY1u2FyWP9uYw"
  31. )
  32. yield self.store.store_server_verify_key("server1", "from_server", 0, key1)
  33. yield self.store.store_server_verify_key("server1", "from_server", 0, key2)
  34. res = yield self.store.get_server_verify_keys(
  35. "server1", ["ed25519:key1", "ed25519:key2", "ed25519:key3"]
  36. )
  37. self.assertEqual(len(res.keys()), 2)
  38. self.assertEqual(res["ed25519:key1"].version, "key1")
  39. self.assertEqual(res["ed25519:key2"].version, "key2")