diff --git a/tests/machine.test.js b/tests/machine.test.js index b1f16be36..a7203f2eb 100644 --- a/tests/machine.test.js +++ b/tests/machine.test.js @@ -1151,23 +1151,22 @@ describe(OlmMachine.name, () => { describe("Request missing secrets", () => { /** - * * Creates an hypothetical response to a key query request for an account with a pre-existing device and identity. * - * To be used in test when you want to create a setup where there is an existing device - * on the account with cross-signing setup. + * To be used in tests when you want to create a setup where there is an existing device + * on the account with cross-signing set up. * * This will create a valid response to a key query request with all needed signatures. * - * @param {UserId} user_id - The user id - * @param {DeviceId} new_device - The device id + * @param {UserId} userId - The user id + * @param {DeviceId} deviceId - The device id * * @returns A valid response to a key query request that can be feed in a second login for that account. */ - async function getKeyQueryResponseWithExistingDevice(user_id, device_id) { - let initialMachine = await OlmMachine.initialize(user_id, device_id); - const userId = initialMachine.userId.toString(); - const deviceId = initialMachine.deviceId.toString(); + async function getKeyQueryResponseWithExistingDevice(userId, deviceId) { + let initialMachine = await OlmMachine.initialize(userId, deviceId); + const userIdStr = initialMachine.userId.toString(); + const deviceIdStr = initialMachine.deviceId.toString(); let deviceKeys; let outgoingRequests = await initialMachine.outgoingRequests(); @@ -1185,9 +1184,9 @@ describe(OlmMachine.name, () => { const newSignature = JSON.parse(bootstrapRequest.uploadSignaturesRequest.body); const allSignatures = { - [userId]: { + [userIdStr]: { ...deviceKeys.device_keys.signatures[userId], - ...newSignature[userId][deviceId].signatures[userId], + ...newSignature[userIdStr][deviceIdStr].signatures[userId], }, }; @@ -1195,8 +1194,8 @@ describe(OlmMachine.name, () => { return { device_keys: { - [userId]: { - [deviceId]: deviceKeys, + [userIdStr]: { + [deviceIdStr]: deviceKeys, }, }, ...crossSigning, @@ -1204,19 +1203,19 @@ describe(OlmMachine.name, () => { } /** - * * This function is designed to work with `getKeyQueryResponseWithExistingDevice` to simulate a scenario where - * an existing device (and crossSigning identiy), is already associated with the account. + * an existing device (and cross-signing identity), is already associated with the account. * * It will create a new login and process a hypothetical response that includes the existing identity and devices. - * @param {UserId} user_id - the user id of the account - * @param {DeviceId} device_id - the id of the new device - * @param {*} hypothetical_response - the response to the key query request generated by `getKeyQueryResponseWithExistingDevice` + * + * @param {UserId} userId - the user id of the account + * @param {DeviceId} deviceId - the id of the new device + * @param {*} hypotheticalResponse - the response to the key query request generated by `getKeyQueryResponseWithExistingDevice` * * @returns an olm machine with the new device and the hypothetical response processed. */ - async function getSecondMachine(user_id, device_id, hypothetical_response) { - const secondMachine = await OlmMachine.initialize(user_id, device_id); + async function getSecondMachine(userId, deviceId, hypotheticalResponse) { + const secondMachine = await OlmMachine.initialize(userId, deviceId); const toDeviceEvents = JSON.stringify([]); const changedDevices = new DeviceLists(); @@ -1237,20 +1236,20 @@ describe(OlmMachine.name, () => { await secondMachine.markRequestAsSent( request.id, RequestType.KeysQuery, - JSON.stringify(hypothetical_response), + JSON.stringify(hypotheticalResponse), ); return secondMachine; } - test("Should request cross signing-keys if missing", async () => { + test("Should request cross-signing keys if missing", async () => { const userId = new UserId("@alice:example.org"); const firstDevice = new DeviceId("ABCDEF"); - const hypothetical_response = await getKeyQueryResponseWithExistingDevice(userId, firstDevice); + const hypotheticalResponse = await getKeyQueryResponseWithExistingDevice(userId, firstDevice); const secondDeviceId = new DeviceId("GHIJKL"); - const secondMachine = await getSecondMachine(userId, secondDeviceId, hypothetical_response); + const secondMachine = await getSecondMachine(userId, secondDeviceId, hypotheticalResponse); const hasMissingSecrets = await secondMachine.requestMissingSecretsIfNeeded(); expect(hasMissingSecrets).toStrictEqual(true); @@ -1284,11 +1283,11 @@ describe(OlmMachine.name, () => { test("Should not request if there are requests already in flight", async () => { const userId = new UserId("@alice:example.org"); const firstDevice = new DeviceId("ABCDEF"); - const hypothetical_response = await getKeyQueryResponseWithExistingDevice(userId, firstDevice); + const hypotheticalResponse = await getKeyQueryResponseWithExistingDevice(userId, firstDevice); const secondDeviceId = new DeviceId("GHIJKL"); - const secondMachine = await getSecondMachine(userId, secondDeviceId, hypothetical_response); + const secondMachine = await getSecondMachine(userId, secondDeviceId, hypotheticalResponse); const hasMissingSecrets = await secondMachine.requestMissingSecretsIfNeeded(); expect(hasMissingSecrets).toStrictEqual(true);