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!
This commit is contained in:
+64
-54
@@ -43,6 +43,10 @@ interface CreateBotOpts {
|
||||
* Whether or not to generate cross-signing keys
|
||||
*/
|
||||
bootstrapCrossSigning?: boolean;
|
||||
/**
|
||||
* Whether to use the rust crypto impl. Defaults to false (for now!)
|
||||
*/
|
||||
rustCrypto?: boolean;
|
||||
}
|
||||
|
||||
const defaultCreateBotOptions = {
|
||||
@@ -125,66 +129,72 @@ function setupBotClient(
|
||||
opts: CreateBotOpts,
|
||||
): Chainable<MatrixClient> {
|
||||
opts = Object.assign({}, defaultCreateBotOptions, opts);
|
||||
return cy.window({ log: false }).then((win) => {
|
||||
const keys = {};
|
||||
return cy.window({ log: false }).then(
|
||||
// extra timeout, as this sometimes takes a while
|
||||
{ timeout: 30_000 },
|
||||
async (win): Promise<MatrixClient> => {
|
||||
const keys = {};
|
||||
|
||||
const getCrossSigningKey = (type: string) => {
|
||||
return keys[type];
|
||||
};
|
||||
const getCrossSigningKey = (type: string) => {
|
||||
return keys[type];
|
||||
};
|
||||
|
||||
const saveCrossSigningKeys = (k: Record<string, Uint8Array>) => {
|
||||
Object.assign(keys, k);
|
||||
};
|
||||
const saveCrossSigningKeys = (k: Record<string, Uint8Array>) => {
|
||||
Object.assign(keys, k);
|
||||
};
|
||||
|
||||
const cli = new win.matrixcs.MatrixClient({
|
||||
baseUrl: homeserver.baseUrl,
|
||||
userId: credentials.userId,
|
||||
deviceId: credentials.deviceId,
|
||||
accessToken: credentials.accessToken,
|
||||
store: new win.matrixcs.MemoryStore(),
|
||||
scheduler: new win.matrixcs.MatrixScheduler(),
|
||||
cryptoStore: new win.matrixcs.MemoryCryptoStore(),
|
||||
cryptoCallbacks: { getCrossSigningKey, saveCrossSigningKeys },
|
||||
});
|
||||
|
||||
if (opts.autoAcceptInvites) {
|
||||
cli.on(win.matrixcs.RoomMemberEvent.Membership, (event, member) => {
|
||||
if (member.membership === "invite" && member.userId === cli.getUserId()) {
|
||||
cli.joinRoom(member.roomId);
|
||||
}
|
||||
const cli = new win.matrixcs.MatrixClient({
|
||||
baseUrl: homeserver.baseUrl,
|
||||
userId: credentials.userId,
|
||||
deviceId: credentials.deviceId,
|
||||
accessToken: credentials.accessToken,
|
||||
store: new win.matrixcs.MemoryStore(),
|
||||
scheduler: new win.matrixcs.MatrixScheduler(),
|
||||
cryptoStore: new win.matrixcs.MemoryCryptoStore(),
|
||||
cryptoCallbacks: { getCrossSigningKey, saveCrossSigningKeys },
|
||||
});
|
||||
}
|
||||
|
||||
if (!opts.startClient) {
|
||||
return cy.wrap(cli);
|
||||
}
|
||||
|
||||
return cy.wrap(
|
||||
cli
|
||||
.initCrypto()
|
||||
.then(() => cli.setGlobalErrorOnUnknownDevices(false))
|
||||
.then(() => cli.startClient())
|
||||
.then(async () => {
|
||||
if (opts.bootstrapCrossSigning) {
|
||||
await cli.bootstrapCrossSigning({
|
||||
authUploadDeviceSigningKeys: async (func) => {
|
||||
await func({
|
||||
type: "m.login.password",
|
||||
identifier: {
|
||||
type: "m.id.user",
|
||||
user: credentials.userId,
|
||||
},
|
||||
password: credentials.password,
|
||||
});
|
||||
},
|
||||
});
|
||||
if (opts.autoAcceptInvites) {
|
||||
cli.on(win.matrixcs.RoomMemberEvent.Membership, (event, member) => {
|
||||
if (member.membership === "invite" && member.userId === cli.getUserId()) {
|
||||
cli.joinRoom(member.roomId);
|
||||
}
|
||||
})
|
||||
.then(() => cli),
|
||||
// extra timeout, as this sometimes takes a while
|
||||
{ timeout: 30_000 },
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
if (!opts.startClient) {
|
||||
return cli;
|
||||
}
|
||||
|
||||
if (opts.rustCrypto) {
|
||||
await cli.initRustCrypto({ useIndexedDB: false });
|
||||
} else {
|
||||
await cli.initCrypto();
|
||||
}
|
||||
cli.setGlobalErrorOnUnknownDevices(false);
|
||||
await cli.startClient();
|
||||
|
||||
if (opts.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) => {
|
||||
await func({
|
||||
type: "m.login.password",
|
||||
identifier: {
|
||||
type: "m.id.user",
|
||||
user: credentials.userId,
|
||||
},
|
||||
password: credentials.password,
|
||||
});
|
||||
},
|
||||
});
|
||||
}
|
||||
return cli;
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Cypress.Commands.add("getBot", (homeserver: HomeserverInstance, opts: CreateBotOpts): Chainable<CypressBot> => {
|
||||
|
||||
Reference in New Issue
Block a user