Cypress: Use Rust crypto for the bot user in verification tests (#11173)
* Cypress: `crypto.verification.request` -> `crypto.verificationRequestReceived` matrix-org/matrix-js-sdk#3514 deprecated crypto.verification.request. * Cypress: `beginKeyVerification` -> `startVerification` matrix-org/matrix-js-sdk#3528 deprecated beginKeyVerification * simplify `setupBotClient` no functional change here, just combining the various `cy.wrap()`ed things into a single async func * Cypress: Use Rust crypto for the bot user in verification tests We can already start using the Rust crypto implementation for the "bot" user in the verification tests!pull/28788/head^2
parent
8924bd26fa
commit
1a75d5d869
|
@ -116,9 +116,9 @@ const verify = function (this: CryptoTestContext) {
|
||||||
// this requires creating a DM, so can take a while. Give it a longer timeout.
|
// this requires creating a DM, so can take a while. Give it a longer timeout.
|
||||||
cy.findByRole("button", { name: "Verify by emoji", timeout: 30000 }).click();
|
cy.findByRole("button", { name: "Verify by emoji", timeout: 30000 }).click();
|
||||||
|
|
||||||
cy.wrap(bobsVerificationRequestPromise).then((request: VerificationRequest) => {
|
cy.wrap(bobsVerificationRequestPromise).then(async (request: VerificationRequest) => {
|
||||||
// the bot user races with the Element user to hit the "verify by emoji" button
|
// the bot user races with the Element user to hit the "verify by emoji" button
|
||||||
const verifier = request.beginKeyVerification("m.sas.v1");
|
const verifier = await request.startVerification("m.sas.v1");
|
||||||
doTwoWaySasVerification(verifier);
|
doTwoWaySasVerification(verifier);
|
||||||
});
|
});
|
||||||
cy.findByRole("button", { name: "They match" }).click();
|
cy.findByRole("button", { name: "They match" }).click();
|
||||||
|
|
|
@ -28,13 +28,11 @@ export type EmojiMapping = [emoji: string, name: string];
|
||||||
export function waitForVerificationRequest(cli: MatrixClient): Promise<VerificationRequest> {
|
export function waitForVerificationRequest(cli: MatrixClient): Promise<VerificationRequest> {
|
||||||
return new Promise<VerificationRequest>((resolve) => {
|
return new Promise<VerificationRequest>((resolve) => {
|
||||||
const onVerificationRequestEvent = async (request: VerificationRequest) => {
|
const onVerificationRequestEvent = async (request: VerificationRequest) => {
|
||||||
// @ts-ignore CryptoEvent is not exported to window.matrixcs; using the string value here
|
|
||||||
cli.off("crypto.verification.request", onVerificationRequestEvent);
|
|
||||||
await request.accept();
|
await request.accept();
|
||||||
resolve(request);
|
resolve(request);
|
||||||
};
|
};
|
||||||
// @ts-ignore
|
// @ts-ignore CryptoEvent is not exported to window.matrixcs; using the string value here
|
||||||
cli.on("crypto.verification.request", onVerificationRequestEvent);
|
cli.once("crypto.verificationRequestReceived", onVerificationRequestEvent);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,7 +57,6 @@ export function handleSasVerification(verifier: Verifier): Promise<EmojiMapping[
|
||||||
|
|
||||||
// @ts-ignore as above, avoiding reference to VerifierEvent
|
// @ts-ignore as above, avoiding reference to VerifierEvent
|
||||||
verifier.on("show_sas", onShowSas);
|
verifier.on("show_sas", onShowSas);
|
||||||
verifier.verify();
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -134,7 +131,10 @@ export function doTwoWaySasVerification(verifier: Verifier): void {
|
||||||
cy.wrap(emojiPromise).then((emojis: EmojiMapping[]) => {
|
cy.wrap(emojiPromise).then((emojis: EmojiMapping[]) => {
|
||||||
cy.get(".mx_VerificationShowSas_emojiSas_block").then((emojiBlocks) => {
|
cy.get(".mx_VerificationShowSas_emojiSas_block").then((emojiBlocks) => {
|
||||||
emojis.forEach((emoji: EmojiMapping, index: number) => {
|
emojis.forEach((emoji: EmojiMapping, index: number) => {
|
||||||
expect(emojiBlocks[index].textContent.toLowerCase()).to.eq(emoji[0] + emoji[1]);
|
// VerificationShowSas munges the case of the emoji descriptions returned by the js-sdk before
|
||||||
|
// displaying them. Once we drop support for legacy crypto, that code can go away, and so can the
|
||||||
|
// case-munging here.
|
||||||
|
expect(emojiBlocks[index].textContent.toLowerCase()).to.eq(emoji[0] + emoji[1].toLowerCase());
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -36,7 +36,7 @@ describe("Device verification", () => {
|
||||||
cy.window({ log: false }).should("have.property", "matrixcs");
|
cy.window({ log: false }).should("have.property", "matrixcs");
|
||||||
|
|
||||||
// Create a new device for alice
|
// Create a new device for alice
|
||||||
cy.getBot(homeserver, { bootstrapCrossSigning: true }).then((bot) => {
|
cy.getBot(homeserver, { rustCrypto: true, bootstrapCrossSigning: true }).then((bot) => {
|
||||||
aliceBotClient = bot;
|
aliceBotClient = bot;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -71,9 +71,9 @@ describe("Device verification", () => {
|
||||||
|
|
||||||
// Handle emoji SAS verification
|
// Handle emoji SAS verification
|
||||||
cy.get(".mx_InfoDialog").within(() => {
|
cy.get(".mx_InfoDialog").within(() => {
|
||||||
cy.get<VerificationRequest>("@verificationRequest").then((request: VerificationRequest) => {
|
cy.get<VerificationRequest>("@verificationRequest").then(async (request: VerificationRequest) => {
|
||||||
// the bot chooses to do an emoji verification
|
// the bot chooses to do an emoji verification
|
||||||
const verifier = request.beginKeyVerification("m.sas.v1");
|
const verifier = await request.startVerification("m.sas.v1");
|
||||||
|
|
||||||
// Handle emoji request and check that emojis are matching
|
// Handle emoji request and check that emojis are matching
|
||||||
doTwoWaySasVerification(verifier);
|
doTwoWaySasVerification(verifier);
|
||||||
|
|
|
@ -43,6 +43,10 @@ interface CreateBotOpts {
|
||||||
* Whether or not to generate cross-signing keys
|
* Whether or not to generate cross-signing keys
|
||||||
*/
|
*/
|
||||||
bootstrapCrossSigning?: boolean;
|
bootstrapCrossSigning?: boolean;
|
||||||
|
/**
|
||||||
|
* Whether to use the rust crypto impl. Defaults to false (for now!)
|
||||||
|
*/
|
||||||
|
rustCrypto?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
const defaultCreateBotOptions = {
|
const defaultCreateBotOptions = {
|
||||||
|
@ -125,7 +129,10 @@ function setupBotClient(
|
||||||
opts: CreateBotOpts,
|
opts: CreateBotOpts,
|
||||||
): Chainable<MatrixClient> {
|
): Chainable<MatrixClient> {
|
||||||
opts = Object.assign({}, defaultCreateBotOptions, opts);
|
opts = Object.assign({}, defaultCreateBotOptions, opts);
|
||||||
return cy.window({ log: false }).then((win) => {
|
return cy.window({ log: false }).then(
|
||||||
|
// extra timeout, as this sometimes takes a while
|
||||||
|
{ timeout: 30_000 },
|
||||||
|
async (win): Promise<MatrixClient> => {
|
||||||
const keys = {};
|
const keys = {};
|
||||||
|
|
||||||
const getCrossSigningKey = (type: string) => {
|
const getCrossSigningKey = (type: string) => {
|
||||||
|
@ -156,17 +163,23 @@ function setupBotClient(
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!opts.startClient) {
|
if (!opts.startClient) {
|
||||||
return cy.wrap(cli);
|
return cli;
|
||||||
}
|
}
|
||||||
|
|
||||||
return cy.wrap(
|
if (opts.rustCrypto) {
|
||||||
cli
|
await cli.initRustCrypto({ useIndexedDB: false });
|
||||||
.initCrypto()
|
} else {
|
||||||
.then(() => cli.setGlobalErrorOnUnknownDevices(false))
|
await cli.initCrypto();
|
||||||
.then(() => cli.startClient())
|
}
|
||||||
.then(async () => {
|
cli.setGlobalErrorOnUnknownDevices(false);
|
||||||
|
await cli.startClient();
|
||||||
|
|
||||||
if (opts.bootstrapCrossSigning) {
|
if (opts.bootstrapCrossSigning) {
|
||||||
await cli.bootstrapCrossSigning({
|
// XXX: workaround https://github.com/matrix-org/matrix-rust-sdk/issues/2193
|
||||||
|
// wait for out device list to be available, as a proxy for the device keys having been uploaded.
|
||||||
|
await cli.getCrypto()!.getUserDeviceInfo([credentials.userId]);
|
||||||
|
|
||||||
|
await cli.getCrypto()!.bootstrapCrossSigning({
|
||||||
authUploadDeviceSigningKeys: async (func) => {
|
authUploadDeviceSigningKeys: async (func) => {
|
||||||
await func({
|
await func({
|
||||||
type: "m.login.password",
|
type: "m.login.password",
|
||||||
|
@ -179,12 +192,9 @@ function setupBotClient(
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
})
|
return cli;
|
||||||
.then(() => cli),
|
},
|
||||||
// extra timeout, as this sometimes takes a while
|
|
||||||
{ timeout: 30_000 },
|
|
||||||
);
|
);
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Cypress.Commands.add("getBot", (homeserver: HomeserverInstance, opts: CreateBotOpts): Chainable<CypressBot> => {
|
Cypress.Commands.add("getBot", (homeserver: HomeserverInstance, opts: CreateBotOpts): Chainable<CypressBot> => {
|
||||||
|
|
Loading…
Reference in New Issue