|
| 1 | +/* |
| 2 | +Copyright 2023 The Matrix.org Foundation C.I.C. |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +import type { VerificationRequest } from "matrix-js-sdk/src/crypto/verification/request/VerificationRequest"; |
| 18 | +import { HomeserverInstance } from "../../plugins/utils/homeserver"; |
| 19 | +import { handleVerificationRequest, waitForVerificationRequest } from "./utils"; |
| 20 | +import { CypressBot } from "../../support/bot"; |
| 21 | + |
| 22 | +describe("Complete security", () => { |
| 23 | + let homeserver: HomeserverInstance; |
| 24 | + |
| 25 | + beforeEach(() => { |
| 26 | + cy.startHomeserver("default").then((data) => { |
| 27 | + homeserver = data; |
| 28 | + }); |
| 29 | + // visit the login page of the app, to load the matrix sdk |
| 30 | + cy.visit("/#/login"); |
| 31 | + |
| 32 | + // wait for the page to load |
| 33 | + cy.window({ log: false }).should("have.property", "matrixcs"); |
| 34 | + }); |
| 35 | + |
| 36 | + afterEach(() => { |
| 37 | + cy.stopHomeserver(homeserver); |
| 38 | + }); |
| 39 | + |
| 40 | + it("should go straight to the welcome screen if we have no signed device", () => { |
| 41 | + const username = Cypress._.uniqueId("user_"); |
| 42 | + const password = "supersecret"; |
| 43 | + cy.registerUser(homeserver, username, password, "Jeff"); |
| 44 | + logIntoElement(homeserver.baseUrl, username, password); |
| 45 | + cy.findByText("Welcome Jeff"); |
| 46 | + }); |
| 47 | + |
| 48 | + it("should walk through device verification if we have a signed device", () => { |
| 49 | + // create a new user, and have it bootstrap cross-signing |
| 50 | + let botClient: CypressBot; |
| 51 | + cy.getBot(homeserver, { displayName: "Jeff" }) |
| 52 | + .then(async (bot) => { |
| 53 | + botClient = bot; |
| 54 | + await bot.bootstrapCrossSigning({}); |
| 55 | + }) |
| 56 | + .then(() => { |
| 57 | + // now log in, in Element. We go in through the login page because otherwise the device setup flow |
| 58 | + // doesn't get triggered |
| 59 | + console.log("%cAccount set up; logging in user", "font-weight: bold; font-size:x-large"); |
| 60 | + logIntoElement(homeserver.baseUrl, botClient.getSafeUserId(), botClient.__cypress_password); |
| 61 | + |
| 62 | + // we should see a prompt for a device verification |
| 63 | + cy.findByRole("heading", { name: "Verify this device" }); |
| 64 | + const botVerificationRequestPromise = waitForVerificationRequest(botClient); |
| 65 | + cy.findByRole("button", { name: "Verify with another device" }).click(); |
| 66 | + |
| 67 | + // accept the verification request on the "bot" side |
| 68 | + cy.wrap(botVerificationRequestPromise).then(async (verificationRequest: VerificationRequest) => { |
| 69 | + await verificationRequest.accept(); |
| 70 | + await handleVerificationRequest(verificationRequest); |
| 71 | + }); |
| 72 | + |
| 73 | + // confirm that the emojis match |
| 74 | + cy.findByRole("button", { name: "They match" }).click(); |
| 75 | + |
| 76 | + // we should get the confirmation box |
| 77 | + cy.findByText(/You've successfully verified/); |
| 78 | + |
| 79 | + cy.findByRole("button", { name: "Got it" }).click(); |
| 80 | + }); |
| 81 | + }); |
| 82 | +}); |
| 83 | + |
| 84 | +/** |
| 85 | + * Fill in the login form in element with the given creds |
| 86 | + */ |
| 87 | +function logIntoElement(homeserverUrl: string, username: string, password: string) { |
| 88 | + cy.visit("/#/login"); |
| 89 | + |
| 90 | + // select homeserver |
| 91 | + cy.findByRole("button", { name: "Edit" }).click(); |
| 92 | + cy.findByRole("textbox", { name: "Other homeserver" }).type(homeserverUrl); |
| 93 | + cy.findByRole("button", { name: "Continue" }).click(); |
| 94 | + |
| 95 | + // wait for the dialog to go away |
| 96 | + cy.get(".mx_ServerPickerDialog").should("not.exist"); |
| 97 | + |
| 98 | + cy.findByRole("textbox", { name: "Username" }).type(username); |
| 99 | + cy.findByPlaceholderText("Password").type(password); |
| 100 | + cy.findByRole("button", { name: "Sign in" }).click(); |
| 101 | +} |
0 commit comments