mirror of https://github.com/vector-im/riot-web
Add credentials when calling bootstrapCrossSigning in Cypress tests (#9919)
parent
314b2e7ba6
commit
422802ea6d
|
@ -20,6 +20,7 @@ import type { ISasEvent } from "matrix-js-sdk/src/crypto/verification/SAS";
|
||||||
import type { CypressBot } from "../../support/bot";
|
import type { CypressBot } from "../../support/bot";
|
||||||
import { HomeserverInstance } from "../../plugins/utils/homeserver";
|
import { HomeserverInstance } from "../../plugins/utils/homeserver";
|
||||||
import Chainable = Cypress.Chainable;
|
import Chainable = Cypress.Chainable;
|
||||||
|
import { UserCredentials } from "../../support/login";
|
||||||
|
|
||||||
type EmojiMapping = [emoji: string, name: string];
|
type EmojiMapping = [emoji: string, name: string];
|
||||||
interface CryptoTestContext extends Mocha.Context {
|
interface CryptoTestContext extends Mocha.Context {
|
||||||
|
@ -154,11 +155,15 @@ const verify = function (this: CryptoTestContext) {
|
||||||
};
|
};
|
||||||
|
|
||||||
describe("Cryptography", function () {
|
describe("Cryptography", function () {
|
||||||
|
let aliceCredentials: UserCredentials;
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
cy.startHomeserver("default")
|
cy.startHomeserver("default")
|
||||||
.as("homeserver")
|
.as("homeserver")
|
||||||
.then((homeserver: HomeserverInstance) => {
|
.then((homeserver: HomeserverInstance) => {
|
||||||
cy.initTestUser(homeserver, "Alice", undefined, "alice_");
|
cy.initTestUser(homeserver, "Alice", undefined, "alice_").then((credentials) => {
|
||||||
|
aliceCredentials = credentials;
|
||||||
|
});
|
||||||
cy.getBot(homeserver, { displayName: "Bob", autoAcceptInvites: false, userIdPrefix: "bob_" }).as("bob");
|
cy.getBot(homeserver, { displayName: "Bob", autoAcceptInvites: false, userIdPrefix: "bob_" }).as("bob");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -183,7 +188,7 @@ describe("Cryptography", function () {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("creating a DM should work, being e2e-encrypted / user verification", function (this: CryptoTestContext) {
|
it("creating a DM should work, being e2e-encrypted / user verification", function (this: CryptoTestContext) {
|
||||||
cy.bootstrapCrossSigning();
|
cy.bootstrapCrossSigning(aliceCredentials);
|
||||||
startDMWithBob.call(this);
|
startDMWithBob.call(this);
|
||||||
// send first message
|
// send first message
|
||||||
cy.get(".mx_BasicMessageComposer_input").click().should("have.focus").type("Hey!{enter}");
|
cy.get(".mx_BasicMessageComposer_input").click().should("have.focus").type("Hey!{enter}");
|
||||||
|
@ -194,7 +199,7 @@ describe("Cryptography", function () {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should allow verification when there is no existing DM", function (this: CryptoTestContext) {
|
it("should allow verification when there is no existing DM", function (this: CryptoTestContext) {
|
||||||
cy.bootstrapCrossSigning();
|
cy.bootstrapCrossSigning(aliceCredentials);
|
||||||
autoJoin(this.bob);
|
autoJoin(this.bob);
|
||||||
|
|
||||||
// we need to have a room with the other user present, so we can open the verification panel
|
// 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 () {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should show the correct shield on edited e2e events", function (this: CryptoTestContext) {
|
it("should show the correct shield on edited e2e events", function (this: CryptoTestContext) {
|
||||||
cy.bootstrapCrossSigning();
|
cy.bootstrapCrossSigning(aliceCredentials);
|
||||||
|
|
||||||
// bob has a second, not cross-signed, device
|
// bob has a second, not cross-signed, device
|
||||||
cy.loginBot(this.homeserver, this.bob.getUserId(), this.bob.__cypress_password, {}).as("bobSecondDevice");
|
cy.loginBot(this.homeserver, this.bob.getUserId(), this.bob.__cypress_password, {}).as("bobSecondDevice");
|
||||||
|
|
|
@ -105,15 +105,9 @@ describe("Decryption Failure Bar", () => {
|
||||||
"and there are other verified devices or backups",
|
"and there are other verified devices or backups",
|
||||||
() => {
|
() => {
|
||||||
let otherDevice: MatrixClient | undefined;
|
let otherDevice: MatrixClient | undefined;
|
||||||
cy.loginBot(homeserver, testUser.username, testUser.password, {})
|
cy.loginBot(homeserver, testUser.username, testUser.password, { bootstrapCrossSigning: true })
|
||||||
.then(async (cli) => {
|
.then(async (cli) => {
|
||||||
otherDevice = cli;
|
otherDevice = cli;
|
||||||
await otherDevice.bootstrapCrossSigning({
|
|
||||||
authUploadDeviceSigningKeys: async (makeRequest) => {
|
|
||||||
await makeRequest({});
|
|
||||||
},
|
|
||||||
setupNewCrossSigning: true,
|
|
||||||
});
|
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
cy.botSendMessage(bot, roomId, "test");
|
cy.botSendMessage(bot, roomId, "test");
|
||||||
|
@ -169,15 +163,11 @@ describe("Decryption Failure Bar", () => {
|
||||||
"should prompt the user to reset keys, if this device isn't verified " +
|
"should prompt the user to reset keys, if this device isn't verified " +
|
||||||
"and there are no other verified devices or backups",
|
"and there are no other verified devices or backups",
|
||||||
() => {
|
() => {
|
||||||
cy.loginBot(homeserver, testUser.username, testUser.password, {}).then(async (cli) => {
|
cy.loginBot(homeserver, testUser.username, testUser.password, { bootstrapCrossSigning: true }).then(
|
||||||
await cli.bootstrapCrossSigning({
|
async (cli) => {
|
||||||
authUploadDeviceSigningKeys: async (makeRequest) => {
|
await cli.logout(true);
|
||||||
await makeRequest({});
|
},
|
||||||
},
|
);
|
||||||
setupNewCrossSigning: true,
|
|
||||||
});
|
|
||||||
await cli.logout(true);
|
|
||||||
});
|
|
||||||
|
|
||||||
cy.botSendMessage(bot, roomId, "test");
|
cy.botSendMessage(bot, roomId, "test");
|
||||||
cy.wait(5000);
|
cy.wait(5000);
|
||||||
|
|
|
@ -150,7 +150,14 @@ function setupBotClient(
|
||||||
if (opts.bootstrapCrossSigning) {
|
if (opts.bootstrapCrossSigning) {
|
||||||
await cli.bootstrapCrossSigning({
|
await cli.bootstrapCrossSigning({
|
||||||
authUploadDeviceSigningKeys: async (func) => {
|
authUploadDeviceSigningKeys: async (func) => {
|
||||||
await func({});
|
await func({
|
||||||
|
type: "m.login.password",
|
||||||
|
identifier: {
|
||||||
|
type: "m.id.user",
|
||||||
|
user: credentials.userId,
|
||||||
|
},
|
||||||
|
password: credentials.password,
|
||||||
|
});
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,7 @@ import type { MatrixClient } from "matrix-js-sdk/src/client";
|
||||||
import type { Room } from "matrix-js-sdk/src/models/room";
|
import type { Room } from "matrix-js-sdk/src/models/room";
|
||||||
import type { IContent } from "matrix-js-sdk/src/models/event";
|
import type { IContent } from "matrix-js-sdk/src/models/event";
|
||||||
import Chainable = Cypress.Chainable;
|
import Chainable = Cypress.Chainable;
|
||||||
|
import { UserCredentials } from "./login";
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
// eslint-disable-next-line @typescript-eslint/no-namespace
|
// eslint-disable-next-line @typescript-eslint/no-namespace
|
||||||
|
@ -119,7 +120,7 @@ declare global {
|
||||||
/**
|
/**
|
||||||
* Boostraps cross-signing.
|
* Boostraps cross-signing.
|
||||||
*/
|
*/
|
||||||
bootstrapCrossSigning(): Chainable<void>;
|
bootstrapCrossSigning(credendtials: UserCredentials): Chainable<void>;
|
||||||
/**
|
/**
|
||||||
* Joins the given room by alias or ID
|
* Joins the given room by alias or ID
|
||||||
* @param roomIdOrAlias the id or alias of the room to join
|
* @param roomIdOrAlias the id or alias of the room to join
|
||||||
|
@ -210,11 +211,18 @@ Cypress.Commands.add("setAvatarUrl", (url: string): Chainable<{}> => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
Cypress.Commands.add("bootstrapCrossSigning", () => {
|
Cypress.Commands.add("bootstrapCrossSigning", (credentials: UserCredentials) => {
|
||||||
cy.window({ log: false }).then((win) => {
|
cy.window({ log: false }).then((win) => {
|
||||||
win.mxMatrixClientPeg.matrixClient.bootstrapCrossSigning({
|
win.mxMatrixClientPeg.matrixClient.bootstrapCrossSigning({
|
||||||
authUploadDeviceSigningKeys: async (func) => {
|
authUploadDeviceSigningKeys: async (func) => {
|
||||||
await func({});
|
await func({
|
||||||
|
type: "m.login.password",
|
||||||
|
identifier: {
|
||||||
|
type: "m.id.user",
|
||||||
|
user: credentials.userId,
|
||||||
|
},
|
||||||
|
password: credentials.password,
|
||||||
|
});
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -76,6 +76,7 @@ export interface Credentials {
|
||||||
userId: string;
|
userId: string;
|
||||||
deviceId: string;
|
deviceId: string;
|
||||||
homeServer: string;
|
homeServer: string;
|
||||||
|
password: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
function registerUser(
|
function registerUser(
|
||||||
|
@ -120,6 +121,7 @@ function registerUser(
|
||||||
accessToken: response.body.access_token,
|
accessToken: response.body.access_token,
|
||||||
userId: response.body.user_id,
|
userId: response.body.user_id,
|
||||||
deviceId: response.body.device_id,
|
deviceId: response.body.device_id,
|
||||||
|
password: password,
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue