1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-11-25 05:23:13 +03:00

Fix more tests

This commit is contained in:
David Baker
2019-10-29 19:39:31 +00:00
parent 3e2d845342
commit 49588da73d
3 changed files with 28 additions and 24 deletions

View File

@@ -27,6 +27,7 @@ import olmlib from '../../../../lib/crypto/olmlib';
import sdk from '../../../..';
import {verificationMethods} from '../../../../lib/crypto';
import DeviceInfo from '../../../../lib/crypto/deviceinfo';
import SAS from '../../../../lib/crypto/verification/SAS';
@@ -393,11 +394,11 @@ describe("SAS verification", function() {
},
);
alice.setDeviceVerified = expect.createSpy();
alice.getDeviceEd25519Key = () => {
alice.client.setDeviceVerified = expect.createSpy();
alice.client.getDeviceEd25519Key = () => {
return "alice+base64+ed25519+key";
};
alice.getStoredDevice = () => {
alice.client.getStoredDevice = () => {
return DeviceInfo.fromStorage(
{
keys: {
@@ -407,12 +408,12 @@ describe("SAS verification", function() {
"Dynabook",
);
};
alice.downloadKeys = () => {
alice.client.downloadKeys = () => {
return Promise.resolve();
};
bob.setDeviceVerified = expect.createSpy();
bob.getStoredDevice = () => {
bob.client.setDeviceVerified = expect.createSpy();
bob.client.getStoredDevice = () => {
return DeviceInfo.fromStorage(
{
keys: {
@@ -422,10 +423,10 @@ describe("SAS verification", function() {
"Osborne2",
);
};
bob.getDeviceEd25519Key = () => {
bob.client.getDeviceEd25519Key = () => {
return "bob+base64+ed25519+key";
};
bob.downloadKeys = () => {
bob.client.downloadKeys = () => {
return Promise.resolve();
};
@@ -433,13 +434,13 @@ describe("SAS verification", function() {
bobSasEvent = null;
bobPromise = new Promise((resolve, reject) => {
bob.on("event", async (event) => {
bob.client.on("event", async (event) => {
const content = event.getContent();
if (event.getType() === "m.room.message"
&& content.msgtype === "m.key.verification.request") {
expect(content.methods).toInclude(SAS.NAME);
expect(content.to).toBe(bob.getUserId());
const verifier = bob.acceptVerificationDM(event, SAS.NAME);
expect(content.to).toBe(bob.client.getUserId());
const verifier = bob.client.acceptVerificationDM(event, SAS.NAME);
verifier.on("show_sas", (e) => {
if (!e.sas.emoji || !e.sas.decimal) {
e.cancel();
@@ -462,8 +463,8 @@ describe("SAS verification", function() {
});
});
aliceVerifier = await alice.requestVerificationDM(
bob.getUserId(), "!room_id", [verificationMethods.SAS],
aliceVerifier = await alice.client.requestVerificationDM(
bob.client.getUserId(), "!room_id", [verificationMethods.SAS],
);
aliceVerifier.on("show_sas", (e) => {
if (!e.sas.emoji || !e.sas.decimal) {
@@ -490,10 +491,10 @@ describe("SAS verification", function() {
]);
// make sure Alice and Bob verified each other
expect(alice.setDeviceVerified)
.toHaveBeenCalledWith(bob.getUserId(), bob.deviceId);
expect(bob.setDeviceVerified)
.toHaveBeenCalledWith(alice.getUserId(), alice.deviceId);
expect(alice.client.setDeviceVerified)
.toHaveBeenCalledWith(bob.client.getUserId(), bob.client.deviceId);
expect(bob.client.setDeviceVerified)
.toHaveBeenCalledWith(alice.client.getUserId(), alice.client.deviceId);
});
});
});

View File

@@ -58,9 +58,9 @@ export async function makeTestClients(userInfos, options) {
room_id: room,
event_id: eventId,
});
for (const client of clients) {
for (const tc of clients) {
setTimeout(
() => client.emit("event", event),
() => tc.client.emit("event", event),
0,
);
}

View File

@@ -1719,9 +1719,11 @@ MatrixBaseApis.prototype.uploadKeysRequest = function(content, opts, callback) {
};
MatrixBaseApis.prototype.uploadKeySignatures = function(content) {
return this._http.authedRequestWithPrefix(
return this._http.authedRequest(
undefined, "POST", '/keys/signatures/upload', undefined,
content, httpApi.PREFIX_UNSTABLE,
content, {
prefix: httpApi.PREFIX_UNSTABLE,
},
);
};
@@ -1811,9 +1813,10 @@ MatrixBaseApis.prototype.getKeyChanges = function(oldToken, newToken) {
MatrixBaseApis.prototype.uploadDeviceSigningKeys = function(auth, keys) {
const data = Object.assign({}, keys, {auth});
return this._http.authedRequestWithPrefix(
undefined, "POST", "/keys/device_signing/upload", undefined, data,
httpApi.PREFIX_UNSTABLE,
return this._http.authedRequest(
undefined, "POST", "/keys/device_signing/upload", undefined, data, {
prefix: httpApi.PREFIX_UNSTABLE,
},
);
};