Invalidate the cache when an olm fallback key is uploaded (#8501)

This commit is contained in:
Hubert Chathi 2020-10-08 13:24:46 -04:00 committed by GitHub
parent 7859c4d079
commit a97cec18bb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 0 deletions

1
changelog.d/8501.feature Normal file
View file

@ -0,0 +1 @@
Add support for olm fallback keys ([MSC2732](https://github.com/matrix-org/matrix-doc/pull/2732)).

View file

@ -398,6 +398,10 @@ class EndToEndKeyWorkerStore(SQLBaseStore):
desc="set_e2e_fallback_key",
)
await self.invalidate_cache_and_stream(
"get_e2e_unused_fallback_key_types", (user_id, device_id)
)
@cached(max_entries=10000)
async def get_e2e_unused_fallback_key_types(
self, user_id: str, device_id: str

View file

@ -33,6 +33,7 @@ class E2eKeysHandlerTestCase(unittest.TestCase):
super().__init__(*args, **kwargs)
self.hs = None # type: synapse.server.HomeServer
self.handler = None # type: synapse.handlers.e2e_keys.E2eKeysHandler
self.store = None # type: synapse.storage.Storage
@defer.inlineCallbacks
def setUp(self):
@ -40,6 +41,7 @@ class E2eKeysHandlerTestCase(unittest.TestCase):
self.addCleanup, handlers=None, federation_client=mock.Mock()
)
self.handler = synapse.handlers.e2e_keys.E2eKeysHandler(self.hs)
self.store = self.hs.get_datastore()
@defer.inlineCallbacks
def test_query_local_devices_no_devices(self):
@ -178,6 +180,12 @@ class E2eKeysHandlerTestCase(unittest.TestCase):
fallback_key = {"alg1:k1": "key1"}
otk = {"alg1:k2": "key2"}
# we shouldn't have any unused fallback keys yet
res = yield defer.ensureDeferred(
self.store.get_e2e_unused_fallback_key_types(local_user, device_id)
)
self.assertEqual(res, [])
yield defer.ensureDeferred(
self.handler.upload_keys_for_user(
local_user,
@ -186,6 +194,12 @@ class E2eKeysHandlerTestCase(unittest.TestCase):
)
)
# we should now have an unused alg1 key
res = yield defer.ensureDeferred(
self.store.get_e2e_unused_fallback_key_types(local_user, device_id)
)
self.assertEqual(res, ["alg1"])
# claiming an OTK when no OTKs are available should return the fallback
# key
res = yield defer.ensureDeferred(
@ -198,6 +212,12 @@ class E2eKeysHandlerTestCase(unittest.TestCase):
{"failures": {}, "one_time_keys": {local_user: {device_id: fallback_key}}},
)
# we shouldn't have any unused fallback keys again
res = yield defer.ensureDeferred(
self.store.get_e2e_unused_fallback_key_types(local_user, device_id)
)
self.assertEqual(res, [])
# claiming an OTK again should return the same fallback key
res = yield defer.ensureDeferred(
self.handler.claim_one_time_keys(