make storage layer in charge of interpreting the device key data

This commit is contained in:
Hubert Chathi 2019-10-10 15:56:00 -04:00
parent def5413480
commit 4908fb3b30
3 changed files with 15 additions and 19 deletions

View file

@ -248,17 +248,6 @@ class E2eKeysHandler(object):
results = yield self.store.get_e2e_device_keys(local_query) results = yield self.store.get_e2e_device_keys(local_query)
# Build the result structure, un-jsonify the results, and add the
# "unsigned" section
for user_id, device_keys in results.items():
for device_id, device_info in device_keys.items():
r = dict(device_info["keys"])
r["unsigned"] = {}
display_name = device_info["device_display_name"]
if display_name is not None:
r["unsigned"]["device_display_name"] = display_name
result_dict[user_id][device_id] = r
log_kv(results) log_kv(results)
return result_dict return result_dict

View file

@ -40,7 +40,7 @@ class EndToEndKeyWorkerStore(SQLBaseStore):
This option only takes effect if include_all_devices is true. This option only takes effect if include_all_devices is true.
Returns: Returns:
Dict mapping from user-id to dict mapping from device_id to Dict mapping from user-id to dict mapping from device_id to
dict containing "key_json", "device_display_name". key data.
""" """
set_tag("query_list", query_list) set_tag("query_list", query_list)
if not query_list: if not query_list:
@ -54,9 +54,16 @@ class EndToEndKeyWorkerStore(SQLBaseStore):
include_deleted_devices, include_deleted_devices,
) )
# Build the result structure, un-jsonify the results, and add the
# "unsigned" section
for user_id, device_keys in iteritems(results): for user_id, device_keys in iteritems(results):
for device_id, device_info in iteritems(device_keys): for device_id, device_info in iteritems(device_keys):
device_info["keys"] = db_to_json(device_info.pop("key_json")) r = db_to_json(device_info.pop("key_json"))
r["unsigned"] = {}
display_name = device_info["device_display_name"]
if display_name is not None:
r["unsigned"]["device_display_name"] = display_name
results[user_id][device_id] = r
return results return results

View file

@ -38,7 +38,7 @@ class EndToEndKeyStoreTestCase(tests.unittest.TestCase):
self.assertIn("user", res) self.assertIn("user", res)
self.assertIn("device", res["user"]) self.assertIn("device", res["user"])
dev = res["user"]["device"] dev = res["user"]["device"]
self.assertDictContainsSubset({"keys": json, "device_display_name": None}, dev) self.assertDictContainsSubset(json, dev)
@defer.inlineCallbacks @defer.inlineCallbacks
def test_reupload_key(self): def test_reupload_key(self):
@ -68,7 +68,7 @@ class EndToEndKeyStoreTestCase(tests.unittest.TestCase):
self.assertIn("device", res["user"]) self.assertIn("device", res["user"])
dev = res["user"]["device"] dev = res["user"]["device"]
self.assertDictContainsSubset( self.assertDictContainsSubset(
{"keys": json, "device_display_name": "display_name"}, dev {"key": "value", "unsigned": {"device_display_name": "display_name"}}, dev
) )
@defer.inlineCallbacks @defer.inlineCallbacks
@ -80,10 +80,10 @@ class EndToEndKeyStoreTestCase(tests.unittest.TestCase):
yield self.store.store_device("user2", "device1", None) yield self.store.store_device("user2", "device1", None)
yield self.store.store_device("user2", "device2", None) yield self.store.store_device("user2", "device2", None)
yield self.store.set_e2e_device_keys("user1", "device1", now, "json11") yield self.store.set_e2e_device_keys("user1", "device1", now, {"key": "json11"})
yield self.store.set_e2e_device_keys("user1", "device2", now, "json12") yield self.store.set_e2e_device_keys("user1", "device2", now, {"key": "json12"})
yield self.store.set_e2e_device_keys("user2", "device1", now, "json21") yield self.store.set_e2e_device_keys("user2", "device1", now, {"key": "json21"})
yield self.store.set_e2e_device_keys("user2", "device2", now, "json22") yield self.store.set_e2e_device_keys("user2", "device2", now, {"key": "json22"})
res = yield self.store.get_e2e_device_keys( res = yield self.store.get_e2e_device_keys(
(("user1", "device1"), ("user2", "device2")) (("user1", "device1"), ("user2", "device2"))