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 the tests pass
This commit is contained in:
@@ -18,7 +18,7 @@ import "../../../olm-loader";
|
|||||||
import {verificationMethods} from "../../../../src/crypto";
|
import {verificationMethods} from "../../../../src/crypto";
|
||||||
import {logger} from "../../../../src/logger";
|
import {logger} from "../../../../src/logger";
|
||||||
import {SAS} from "../../../../src/crypto/verification/SAS";
|
import {SAS} from "../../../../src/crypto/verification/SAS";
|
||||||
import {makeTestClients} from './util';
|
import {makeTestClients, setupWebcrypto, teardownWebcrypto} from './util';
|
||||||
|
|
||||||
const Olm = global.Olm;
|
const Olm = global.Olm;
|
||||||
|
|
||||||
@@ -31,9 +31,14 @@ describe("verification request integration tests with crypto layer", function()
|
|||||||
}
|
}
|
||||||
|
|
||||||
beforeAll(function() {
|
beforeAll(function() {
|
||||||
|
setupWebcrypto();
|
||||||
return Olm.init();
|
return Olm.init();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
afterAll(() => {
|
||||||
|
teardownWebcrypto();
|
||||||
|
});
|
||||||
|
|
||||||
it("should request and accept a verification", async function() {
|
it("should request and accept a verification", async function() {
|
||||||
const [alice, bob] = await makeTestClients(
|
const [alice, bob] = await makeTestClients(
|
||||||
[
|
[
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ See the License for the specific language governing permissions and
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
import "../../../olm-loader";
|
import "../../../olm-loader";
|
||||||
import {makeTestClients} from './util';
|
import {makeTestClients, setupWebcrypto, teardownWebcrypto} from './util';
|
||||||
import {MatrixEvent} from "../../../../src/models/event";
|
import {MatrixEvent} from "../../../../src/models/event";
|
||||||
import {SAS} from "../../../../src/crypto/verification/SAS";
|
import {SAS} from "../../../../src/crypto/verification/SAS";
|
||||||
import {DeviceInfo} from "../../../../src/crypto/deviceinfo";
|
import {DeviceInfo} from "../../../../src/crypto/deviceinfo";
|
||||||
@@ -35,9 +35,14 @@ describe("SAS verification", function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
beforeAll(function() {
|
beforeAll(function() {
|
||||||
|
setupWebcrypto();
|
||||||
return Olm.init();
|
return Olm.init();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
afterAll(() => {
|
||||||
|
teardownWebcrypto();
|
||||||
|
});
|
||||||
|
|
||||||
it("should error on an unexpected event", async function() {
|
it("should error on an unexpected event", async function() {
|
||||||
const sas = new SAS({}, "@alice:example.com", "ABCDEFG");
|
const sas = new SAS({}, "@alice:example.com", "ABCDEFG");
|
||||||
sas.handleEvent(new MatrixEvent({
|
sas.handleEvent(new MatrixEvent({
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ limitations under the License.
|
|||||||
|
|
||||||
import {TestClient} from '../../../TestClient';
|
import {TestClient} from '../../../TestClient';
|
||||||
import {MatrixEvent} from "../../../../src/models/event";
|
import {MatrixEvent} from "../../../../src/models/event";
|
||||||
|
import nodeCrypto from "crypto";
|
||||||
|
|
||||||
export async function makeTestClients(userInfos, options) {
|
export async function makeTestClients(userInfos, options) {
|
||||||
const clients = [];
|
const clients = [];
|
||||||
@@ -102,3 +103,15 @@ export async function makeTestClients(userInfos, options) {
|
|||||||
|
|
||||||
return clients;
|
return clients;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function setupWebcrypto() {
|
||||||
|
global.crypto = {
|
||||||
|
getRandomValues: (buf) => {
|
||||||
|
return nodeCrypto.randomFillSync(buf);
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function teardownWebcrypto() {
|
||||||
|
global.crypto = undefined;
|
||||||
|
}
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ import {InRoomChannel} from "../../../../src/crypto/verification/request/InRoomC
|
|||||||
import {ToDeviceChannel} from
|
import {ToDeviceChannel} from
|
||||||
"../../../../src/crypto/verification/request/ToDeviceChannel";
|
"../../../../src/crypto/verification/request/ToDeviceChannel";
|
||||||
import {MatrixEvent} from "../../../../src/models/event";
|
import {MatrixEvent} from "../../../../src/models/event";
|
||||||
|
import {setupWebcrypto, teardownWebcrypto} from "./util";
|
||||||
|
|
||||||
function makeMockClient(userId, deviceId) {
|
function makeMockClient(userId, deviceId) {
|
||||||
let counter = 1;
|
let counter = 1;
|
||||||
@@ -115,6 +116,15 @@ async function distributeEvent(ownRequest, theirRequest, event) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
describe("verification request unit tests", function() {
|
describe("verification request unit tests", function() {
|
||||||
|
|
||||||
|
beforeAll(function() {
|
||||||
|
setupWebcrypto();
|
||||||
|
});
|
||||||
|
|
||||||
|
afterAll(() => {
|
||||||
|
teardownWebcrypto();
|
||||||
|
});
|
||||||
|
|
||||||
it("transition from UNSENT to DONE through happy path", async function() {
|
it("transition from UNSENT to DONE through happy path", async function() {
|
||||||
const alice = makeMockClient("@alice:matrix.tld", "device1");
|
const alice = makeMockClient("@alice:matrix.tld", "device1");
|
||||||
const bob = makeMockClient("@bob:matrix.tld", "device1");
|
const bob = makeMockClient("@bob:matrix.tld", "device1");
|
||||||
|
|||||||
@@ -335,7 +335,7 @@ export class VerificationRequest extends EventEmitter {
|
|||||||
|
|
||||||
_generateSharedSecret() {
|
_generateSharedSecret() {
|
||||||
const secretBytes = new Uint8Array(32); // 256bits
|
const secretBytes = new Uint8Array(32); // 256bits
|
||||||
window.crypto.getRandomValues(secretBytes);
|
global.crypto.getRandomValues(secretBytes);
|
||||||
this._sharedSecret = olmlib.encodeBase64(secretBytes);
|
this._sharedSecret = olmlib.encodeBase64(secretBytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user