Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit 422802e

Browse files
authored
Add credentials when calling bootstrapCrossSigning in Cypress tests (#9919)
1 parent 314b2e7 commit 422802e

File tree

5 files changed

+36
-24
lines changed

5 files changed

+36
-24
lines changed

cypress/e2e/crypto/crypto.spec.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import type { ISasEvent } from "matrix-js-sdk/src/crypto/verification/SAS";
2020
import type { CypressBot } from "../../support/bot";
2121
import { HomeserverInstance } from "../../plugins/utils/homeserver";
2222
import Chainable = Cypress.Chainable;
23+
import { UserCredentials } from "../../support/login";
2324

2425
type EmojiMapping = [emoji: string, name: string];
2526
interface CryptoTestContext extends Mocha.Context {
@@ -154,11 +155,15 @@ const verify = function (this: CryptoTestContext) {
154155
};
155156

156157
describe("Cryptography", function () {
158+
let aliceCredentials: UserCredentials;
159+
157160
beforeEach(function () {
158161
cy.startHomeserver("default")
159162
.as("homeserver")
160163
.then((homeserver: HomeserverInstance) => {
161-
cy.initTestUser(homeserver, "Alice", undefined, "alice_");
164+
cy.initTestUser(homeserver, "Alice", undefined, "alice_").then((credentials) => {
165+
aliceCredentials = credentials;
166+
});
162167
cy.getBot(homeserver, { displayName: "Bob", autoAcceptInvites: false, userIdPrefix: "bob_" }).as("bob");
163168
});
164169
});
@@ -183,7 +188,7 @@ describe("Cryptography", function () {
183188
});
184189

185190
it("creating a DM should work, being e2e-encrypted / user verification", function (this: CryptoTestContext) {
186-
cy.bootstrapCrossSigning();
191+
cy.bootstrapCrossSigning(aliceCredentials);
187192
startDMWithBob.call(this);
188193
// send first message
189194
cy.get(".mx_BasicMessageComposer_input").click().should("have.focus").type("Hey!{enter}");
@@ -194,7 +199,7 @@ describe("Cryptography", function () {
194199
});
195200

196201
it("should allow verification when there is no existing DM", function (this: CryptoTestContext) {
197-
cy.bootstrapCrossSigning();
202+
cy.bootstrapCrossSigning(aliceCredentials);
198203
autoJoin(this.bob);
199204

200205
// we need to have a room with the other user present, so we can open the verification panel
@@ -212,7 +217,7 @@ describe("Cryptography", function () {
212217
});
213218

214219
it("should show the correct shield on edited e2e events", function (this: CryptoTestContext) {
215-
cy.bootstrapCrossSigning();
220+
cy.bootstrapCrossSigning(aliceCredentials);
216221

217222
// bob has a second, not cross-signed, device
218223
cy.loginBot(this.homeserver, this.bob.getUserId(), this.bob.__cypress_password, {}).as("bobSecondDevice");

cypress/e2e/crypto/decryption-failure.spec.ts

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -105,15 +105,9 @@ describe("Decryption Failure Bar", () => {
105105
"and there are other verified devices or backups",
106106
() => {
107107
let otherDevice: MatrixClient | undefined;
108-
cy.loginBot(homeserver, testUser.username, testUser.password, {})
108+
cy.loginBot(homeserver, testUser.username, testUser.password, { bootstrapCrossSigning: true })
109109
.then(async (cli) => {
110110
otherDevice = cli;
111-
await otherDevice.bootstrapCrossSigning({
112-
authUploadDeviceSigningKeys: async (makeRequest) => {
113-
await makeRequest({});
114-
},
115-
setupNewCrossSigning: true,
116-
});
117111
})
118112
.then(() => {
119113
cy.botSendMessage(bot, roomId, "test");
@@ -169,15 +163,11 @@ describe("Decryption Failure Bar", () => {
169163
"should prompt the user to reset keys, if this device isn't verified " +
170164
"and there are no other verified devices or backups",
171165
() => {
172-
cy.loginBot(homeserver, testUser.username, testUser.password, {}).then(async (cli) => {
173-
await cli.bootstrapCrossSigning({
174-
authUploadDeviceSigningKeys: async (makeRequest) => {
175-
await makeRequest({});
176-
},
177-
setupNewCrossSigning: true,
178-
});
179-
await cli.logout(true);
180-
});
166+
cy.loginBot(homeserver, testUser.username, testUser.password, { bootstrapCrossSigning: true }).then(
167+
async (cli) => {
168+
await cli.logout(true);
169+
},
170+
);
181171

182172
cy.botSendMessage(bot, roomId, "test");
183173
cy.wait(5000);

cypress/support/bot.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,14 @@ function setupBotClient(
150150
if (opts.bootstrapCrossSigning) {
151151
await cli.bootstrapCrossSigning({
152152
authUploadDeviceSigningKeys: async (func) => {
153-
await func({});
153+
await func({
154+
type: "m.login.password",
155+
identifier: {
156+
type: "m.id.user",
157+
user: credentials.userId,
158+
},
159+
password: credentials.password,
160+
});
154161
},
155162
});
156163
}

cypress/support/client.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import type { MatrixClient } from "matrix-js-sdk/src/client";
2222
import type { Room } from "matrix-js-sdk/src/models/room";
2323
import type { IContent } from "matrix-js-sdk/src/models/event";
2424
import Chainable = Cypress.Chainable;
25+
import { UserCredentials } from "./login";
2526

2627
declare global {
2728
// eslint-disable-next-line @typescript-eslint/no-namespace
@@ -119,7 +120,7 @@ declare global {
119120
/**
120121
* Boostraps cross-signing.
121122
*/
122-
bootstrapCrossSigning(): Chainable<void>;
123+
bootstrapCrossSigning(credendtials: UserCredentials): Chainable<void>;
123124
/**
124125
* Joins the given room by alias or ID
125126
* @param roomIdOrAlias the id or alias of the room to join
@@ -210,11 +211,18 @@ Cypress.Commands.add("setAvatarUrl", (url: string): Chainable<{}> => {
210211
});
211212
});
212213

213-
Cypress.Commands.add("bootstrapCrossSigning", () => {
214+
Cypress.Commands.add("bootstrapCrossSigning", (credentials: UserCredentials) => {
214215
cy.window({ log: false }).then((win) => {
215216
win.mxMatrixClientPeg.matrixClient.bootstrapCrossSigning({
216217
authUploadDeviceSigningKeys: async (func) => {
217-
await func({});
218+
await func({
219+
type: "m.login.password",
220+
identifier: {
221+
type: "m.id.user",
222+
user: credentials.userId,
223+
},
224+
password: credentials.password,
225+
});
218226
},
219227
});
220228
});

cypress/support/homeserver.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ export interface Credentials {
7676
userId: string;
7777
deviceId: string;
7878
homeServer: string;
79+
password: string;
7980
}
8081

8182
function registerUser(
@@ -120,6 +121,7 @@ function registerUser(
120121
accessToken: response.body.access_token,
121122
userId: response.body.user_id,
122123
deviceId: response.body.device_id,
124+
password: password,
123125
}));
124126
}
125127

0 commit comments

Comments
 (0)