test_keys.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. def __init__(self, *args, **kwargs):
  21. super(KeyStoreTestCase, self).__init__(*args, **kwargs)
  22. self.store = None # type: synapse.storage.keys.KeyStore
  23. @defer.inlineCallbacks
  24. def setUp(self):
  25. hs = yield tests.utils.setup_test_homeserver(self.addCleanup)
  26. self.store = hs.get_datastore()
  27. @defer.inlineCallbacks
  28. def test_get_server_verify_keys(self):
  29. key1 = signedjson.key.decode_verify_key_base64(
  30. "ed25519", "key1", "fP5l4JzpZPq/zdbBg5xx6lQGAAOM9/3w94cqiJ5jPrw"
  31. )
  32. key2 = signedjson.key.decode_verify_key_base64(
  33. "ed25519", "key2", "Noi6WqcDj0QmPxCNQqgezwTlBKrfqehY1u2FyWP9uYw"
  34. )
  35. yield self.store.store_server_verify_key("server1", "from_server", 0, key1)
  36. yield self.store.store_server_verify_key("server1", "from_server", 0, key2)
  37. res = yield self.store.get_server_verify_keys(
  38. "server1", ["ed25519:key1", "ed25519:key2", "ed25519:key3"]
  39. )
  40. self.assertEqual(len(res.keys()), 2)
  41. self.assertEqual(res["ed25519:key1"].version, "key1")
  42. self.assertEqual(res["ed25519:key2"].version, "key2")