|
| 1 | +/* |
| 2 | +Copyright 2022 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 { test, expect } from "../../element-web-test"; |
| 18 | + |
| 19 | +test.describe("Registration", () => { |
| 20 | + test.use({ startHomeserverOpts: "consent" }); |
| 21 | + |
| 22 | + test.beforeEach(async ({ page }) => { |
| 23 | + await page.goto("/#/register"); |
| 24 | + }); |
| 25 | + |
| 26 | + test("registers an account and lands on the home screen", async ({ homeserver, page, checkA11y, crypto }) => { |
| 27 | + await page.getByRole("button", { name: "Edit", exact: true }).click(); |
| 28 | + await expect(page.getByRole("button", { name: "Continue", exact: true })).toBeVisible(); |
| 29 | + |
| 30 | + await expect(page.locator(".mx_Dialog")).toHaveScreenshot("server-picker.png"); |
| 31 | + await checkA11y(); |
| 32 | + |
| 33 | + await page.getByRole("textbox", { name: "Other homeserver" }).fill(homeserver.config.baseUrl); |
| 34 | + await page.getByRole("button", { name: "Continue", exact: true }).click(); |
| 35 | + // wait for the dialog to go away |
| 36 | + await expect(page.getByRole("dialog")).not.toBeVisible(); |
| 37 | + |
| 38 | + await expect(page.getByRole("textbox", { name: "Username", exact: true })).toBeVisible(); |
| 39 | + // Hide the server text as it contains the randomly allocated Homeserver port |
| 40 | + const screenshotOptions = { mask: [page.locator(".mx_ServerPicker_server")] }; |
| 41 | + await expect(page).toHaveScreenshot("registration.png", screenshotOptions); |
| 42 | + await checkA11y(); |
| 43 | + |
| 44 | + await page.getByRole("textbox", { name: "Username", exact: true }).fill("alice"); |
| 45 | + await page.getByPlaceholder("Password", { exact: true }).fill("totally a great password"); |
| 46 | + await page.getByPlaceholder("Confirm password", { exact: true }).fill("totally a great password"); |
| 47 | + await page.getByRole("button", { name: "Register", exact: true }).click(); |
| 48 | + |
| 49 | + const dialog = page.getByRole("dialog"); |
| 50 | + await expect(dialog).toBeVisible(); |
| 51 | + await expect(page).toHaveScreenshot("email-prompt.png", screenshotOptions); |
| 52 | + await checkA11y(); |
| 53 | + await dialog.getByRole("button", { name: "Continue", exact: true }).click(); |
| 54 | + |
| 55 | + await expect(page.locator(".mx_InteractiveAuthEntryComponents_termsPolicy")).toBeVisible(); |
| 56 | + await expect(page).toHaveScreenshot("terms-prompt.png", screenshotOptions); |
| 57 | + await checkA11y(); |
| 58 | + |
| 59 | + const termsPolicy = page.locator(".mx_InteractiveAuthEntryComponents_termsPolicy"); |
| 60 | + await termsPolicy.getByRole("checkbox").click(); // Click the checkbox before terms of service anchor link |
| 61 | + await expect(termsPolicy.getByLabel("Privacy Policy")).toBeVisible(); |
| 62 | + |
| 63 | + await page.getByRole("button", { name: "Accept", exact: true }).click(); |
| 64 | + |
| 65 | + await expect(page.locator(".mx_UseCaseSelection_skip")).toBeVisible(); |
| 66 | + await expect(page).toHaveScreenshot("use-case-selection.png", screenshotOptions); |
| 67 | + await checkA11y(); |
| 68 | + await page.getByRole("button", { name: "Skip", exact: true }).click(); |
| 69 | + |
| 70 | + await expect(page).toHaveURL(/\/#\/home$/); |
| 71 | + |
| 72 | + /* |
| 73 | + * Cross-signing checks |
| 74 | + */ |
| 75 | + // check that the device considers itself verified |
| 76 | + await page.getByRole("button", { name: "User menu", exact: true }).click(); |
| 77 | + await page.getByRole("menuitem", { name: "All settings", exact: true }).click(); |
| 78 | + await page.getByRole("tab", { name: "Sessions", exact: true }).click(); |
| 79 | + await expect(page.getByTestId("current-session-section").getByTestId("device-metadata-isVerified")).toHaveText( |
| 80 | + "Verified", |
| 81 | + ); |
| 82 | + |
| 83 | + // check that cross-signing keys have been uploaded. |
| 84 | + await crypto.assertDeviceIsCrossSigned(); |
| 85 | + }); |
| 86 | + |
| 87 | + test("should require username to fulfil requirements and be available", async ({ homeserver, page }) => { |
| 88 | + await page.getByRole("button", { name: "Edit", exact: true }).click(); |
| 89 | + await expect(page.getByRole("button", { name: "Continue", exact: true })).toBeVisible(); |
| 90 | + await page.getByRole("textbox", { name: "Other homeserver" }).fill(homeserver.config.baseUrl); |
| 91 | + await page.getByRole("button", { name: "Continue", exact: true }).click(); |
| 92 | + // wait for the dialog to go away |
| 93 | + await expect(page.getByRole("dialog")).not.toBeVisible(); |
| 94 | + |
| 95 | + await expect(page.getByRole("textbox", { name: "Username", exact: true })).toBeVisible(); |
| 96 | + |
| 97 | + await page.route("**/_matrix/client/*/register/available?username=_alice", async (route) => { |
| 98 | + await route.fulfill({ |
| 99 | + status: 400, |
| 100 | + json: { |
| 101 | + errcode: "M_INVALID_USERNAME", |
| 102 | + error: "User ID may not begin with _", |
| 103 | + }, |
| 104 | + }); |
| 105 | + }); |
| 106 | + await page.getByRole("textbox", { name: "Username", exact: true }).fill("_alice"); |
| 107 | + await expect(page.getByRole("alert").filter({ hasText: "Some characters not allowed" })).toBeVisible(); |
| 108 | + |
| 109 | + await page.route("**/_matrix/client/*/register/available?username=bob", async (route) => { |
| 110 | + await route.fulfill({ |
| 111 | + status: 400, |
| 112 | + json: { |
| 113 | + errcode: "M_USER_IN_USE", |
| 114 | + error: "The desired username is already taken", |
| 115 | + }, |
| 116 | + }); |
| 117 | + }); |
| 118 | + await page.getByRole("textbox", { name: "Username", exact: true }).fill("bob"); |
| 119 | + await expect(page.getByRole("alert").filter({ hasText: "Someone already has that username" })).toBeVisible(); |
| 120 | + |
| 121 | + await page.getByRole("textbox", { name: "Username", exact: true }).fill("foobar"); |
| 122 | + await expect(page.getByRole("alert")).not.toBeVisible(); |
| 123 | + }); |
| 124 | +}); |
0 commit comments