You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-11-26 17:03:12 +03:00
make algorithm.hasKeysForKeyRequest async
This commit is contained in:
@@ -119,29 +119,32 @@ describe("MegolmDecryption", function() {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
expect(megolmDecryption.hasKeysForKeyRequest(keyRequest))
|
return megolmDecryption.hasKeysForKeyRequest(
|
||||||
.toBe(true);
|
keyRequest,
|
||||||
|
).then((hasKeys) => {
|
||||||
|
expect(hasKeys).toBe(true);
|
||||||
|
|
||||||
// set up some pre-conditions for the share call
|
// set up some pre-conditions for the share call
|
||||||
const deviceInfo = {};
|
const deviceInfo = {};
|
||||||
mockCrypto.getStoredDevice.andReturn(deviceInfo);
|
mockCrypto.getStoredDevice.andReturn(deviceInfo);
|
||||||
|
|
||||||
const awaitEnsureSessions = new Promise((res, rej) => {
|
const awaitEnsureSessions = new Promise((res, rej) => {
|
||||||
mockOlmLib.ensureOlmSessionsForDevices.andCall(() => {
|
mockOlmLib.ensureOlmSessionsForDevices.andCall(() => {
|
||||||
res();
|
res();
|
||||||
return Promise.resolve({'@alice:foo': {'alidevice': {
|
return Promise.resolve({'@alice:foo': {'alidevice': {
|
||||||
sessionId: 'alisession',
|
sessionId: 'alisession',
|
||||||
}}});
|
}}});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
mockBaseApis.sendToDevice = expect.createSpy();
|
mockBaseApis.sendToDevice = expect.createSpy();
|
||||||
|
|
||||||
// do the share
|
// do the share
|
||||||
megolmDecryption.shareKeysWithDevice(keyRequest);
|
megolmDecryption.shareKeysWithDevice(keyRequest);
|
||||||
|
|
||||||
// it's asynchronous, so we have to wait a bit
|
// it's asynchronous, so we have to wait a bit
|
||||||
return awaitEnsureSessions.then(() => {
|
return awaitEnsureSessions;
|
||||||
|
}).then(() => {
|
||||||
// check that it called encryptMessageForDevice with
|
// check that it called encryptMessageForDevice with
|
||||||
// appropriate args.
|
// appropriate args.
|
||||||
expect(mockOlmLib.encryptMessageForDevice.calls.length)
|
expect(mockOlmLib.encryptMessageForDevice.calls.length)
|
||||||
|
|||||||
@@ -20,6 +20,8 @@ limitations under the License.
|
|||||||
* @module
|
* @module
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import Promise from 'bluebird';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* map of registered encryption algorithm classes. A map from string to {@link
|
* map of registered encryption algorithm classes. A map from string to {@link
|
||||||
* module:crypto/algorithms/base.EncryptionAlgorithm|EncryptionAlgorithm} class
|
* module:crypto/algorithms/base.EncryptionAlgorithm|EncryptionAlgorithm} class
|
||||||
@@ -143,11 +145,11 @@ class DecryptionAlgorithm {
|
|||||||
* Determine if we have the keys necessary to respond to a room key request
|
* Determine if we have the keys necessary to respond to a room key request
|
||||||
*
|
*
|
||||||
* @param {module:crypto~IncomingRoomKeyRequest} keyRequest
|
* @param {module:crypto~IncomingRoomKeyRequest} keyRequest
|
||||||
* @return {boolean} true if we have the keys and could (theoretically) share
|
* @return {Promise<boolean>} true if we have the keys and could (theoretically) share
|
||||||
* them; else false.
|
* them; else false.
|
||||||
*/
|
*/
|
||||||
hasKeysForKeyRequest(keyRequest) {
|
hasKeysForKeyRequest(keyRequest) {
|
||||||
return false;
|
return Promise.resolve(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -719,7 +719,7 @@ MegolmDecryption.prototype.onRoomKeyEvent = function(event) {
|
|||||||
/**
|
/**
|
||||||
* @inheritdoc
|
* @inheritdoc
|
||||||
*/
|
*/
|
||||||
MegolmDecryption.prototype.hasKeysForKeyRequest = function(keyRequest) {
|
MegolmDecryption.prototype.hasKeysForKeyRequest = async function(keyRequest) {
|
||||||
const body = keyRequest.requestBody;
|
const body = keyRequest.requestBody;
|
||||||
|
|
||||||
return this._olmDevice.hasInboundSessionKeys(
|
return this._olmDevice.hasInboundSessionKeys(
|
||||||
|
|||||||
@@ -1131,7 +1131,7 @@ Crypto.prototype._processReceivedRoomKeyRequest = async function(req) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!decryptor.hasKeysForKeyRequest(req)) {
|
if (!await decryptor.hasKeysForKeyRequest(req)) {
|
||||||
console.log(
|
console.log(
|
||||||
`room key request for unknown session ${roomId} / ` +
|
`room key request for unknown session ${roomId} / ` +
|
||||||
body.session_id,
|
body.session_id,
|
||||||
|
|||||||
Reference in New Issue
Block a user