mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2024-12-27 04:19:23 -05:00
Invalidate the cache when an olm fallback key is uploaded (#8501)
This commit is contained in:
parent
7859c4d079
commit
a97cec18bb
1
changelog.d/8501.feature
Normal file
1
changelog.d/8501.feature
Normal file
@ -0,0 +1 @@
|
|||||||
|
Add support for olm fallback keys ([MSC2732](https://github.com/matrix-org/matrix-doc/pull/2732)).
|
@ -398,6 +398,10 @@ class EndToEndKeyWorkerStore(SQLBaseStore):
|
|||||||
desc="set_e2e_fallback_key",
|
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)
|
@cached(max_entries=10000)
|
||||||
async def get_e2e_unused_fallback_key_types(
|
async def get_e2e_unused_fallback_key_types(
|
||||||
self, user_id: str, device_id: str
|
self, user_id: str, device_id: str
|
||||||
|
@ -33,6 +33,7 @@ class E2eKeysHandlerTestCase(unittest.TestCase):
|
|||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
self.hs = None # type: synapse.server.HomeServer
|
self.hs = None # type: synapse.server.HomeServer
|
||||||
self.handler = None # type: synapse.handlers.e2e_keys.E2eKeysHandler
|
self.handler = None # type: synapse.handlers.e2e_keys.E2eKeysHandler
|
||||||
|
self.store = None # type: synapse.storage.Storage
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
@ -40,6 +41,7 @@ class E2eKeysHandlerTestCase(unittest.TestCase):
|
|||||||
self.addCleanup, handlers=None, federation_client=mock.Mock()
|
self.addCleanup, handlers=None, federation_client=mock.Mock()
|
||||||
)
|
)
|
||||||
self.handler = synapse.handlers.e2e_keys.E2eKeysHandler(self.hs)
|
self.handler = synapse.handlers.e2e_keys.E2eKeysHandler(self.hs)
|
||||||
|
self.store = self.hs.get_datastore()
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def test_query_local_devices_no_devices(self):
|
def test_query_local_devices_no_devices(self):
|
||||||
@ -178,6 +180,12 @@ class E2eKeysHandlerTestCase(unittest.TestCase):
|
|||||||
fallback_key = {"alg1:k1": "key1"}
|
fallback_key = {"alg1:k1": "key1"}
|
||||||
otk = {"alg1:k2": "key2"}
|
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(
|
yield defer.ensureDeferred(
|
||||||
self.handler.upload_keys_for_user(
|
self.handler.upload_keys_for_user(
|
||||||
local_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
|
# claiming an OTK when no OTKs are available should return the fallback
|
||||||
# key
|
# key
|
||||||
res = yield defer.ensureDeferred(
|
res = yield defer.ensureDeferred(
|
||||||
@ -198,6 +212,12 @@ class E2eKeysHandlerTestCase(unittest.TestCase):
|
|||||||
{"failures": {}, "one_time_keys": {local_user: {device_id: fallback_key}}},
|
{"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
|
# claiming an OTK again should return the same fallback key
|
||||||
res = yield defer.ensureDeferred(
|
res = yield defer.ensureDeferred(
|
||||||
self.handler.claim_one_time_keys(
|
self.handler.claim_one_time_keys(
|
||||||
|
Loading…
Reference in New Issue
Block a user