|
| 1 | +/* |
| 2 | +Copyright 2024 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 | +import { createRoom, enableKeyBackup, logIntoElement, logOutOfElement, sendMessageInCurrentRoom } from "./utils"; |
| 19 | +import { SettingLevel } from "../../../src/settings/SettingLevel"; |
| 20 | + |
| 21 | +test.describe("Adoption of rust stack", () => { |
| 22 | + test("Test migration of existing logins when rollout is 100%", async ({ |
| 23 | + page, |
| 24 | + context, |
| 25 | + app, |
| 26 | + credentials, |
| 27 | + homeserver, |
| 28 | + }, workerInfo) => { |
| 29 | + test.skip( |
| 30 | + workerInfo.project.name === "Rust Crypto", |
| 31 | + "No need to test this on Rust Crypto as we override the config manually", |
| 32 | + ); |
| 33 | + await page.goto("/#/login"); |
| 34 | + test.slow(); |
| 35 | + |
| 36 | + let featureRustCrypto = false; |
| 37 | + let stagedRolloutPercent = 0; |
| 38 | + |
| 39 | + await context.route(`http://localhost:8080/config.json*`, async (route) => { |
| 40 | + const json = { |
| 41 | + default_server_config: { |
| 42 | + "m.homeserver": { |
| 43 | + base_url: "https://server.invalid", |
| 44 | + }, |
| 45 | + }, |
| 46 | + }; |
| 47 | + json["features"] = { |
| 48 | + feature_rust_crypto: featureRustCrypto, |
| 49 | + }; |
| 50 | + json["setting_defaults"] = { |
| 51 | + "language": "en-GB", |
| 52 | + "RustCrypto.staged_rollout_percent": stagedRolloutPercent, |
| 53 | + }; |
| 54 | + await route.fulfill({ json }); |
| 55 | + }); |
| 56 | + |
| 57 | + // reload to ensure we read the config |
| 58 | + await page.reload(); |
| 59 | + |
| 60 | + await logIntoElement(page, homeserver, credentials); |
| 61 | + |
| 62 | + await app.settings.openUserSettings("Help & About"); |
| 63 | + await expect(page.getByText("Crypto version: Olm")).toBeVisible(); |
| 64 | + |
| 65 | + featureRustCrypto = true; |
| 66 | + |
| 67 | + await page.reload(); |
| 68 | + |
| 69 | + await app.settings.openUserSettings("Help & About"); |
| 70 | + await expect(page.getByText("Crypto version: Olm")).toBeVisible(); |
| 71 | + |
| 72 | + stagedRolloutPercent = 100; |
| 73 | + |
| 74 | + await page.reload(); |
| 75 | + |
| 76 | + await app.settings.openUserSettings("Help & About"); |
| 77 | + await expect(page.getByText("Crypto version: Rust SDK")).toBeVisible(); |
| 78 | + }); |
| 79 | + |
| 80 | + test("Test new logins by default on rust stack", async ({ |
| 81 | + page, |
| 82 | + context, |
| 83 | + app, |
| 84 | + credentials, |
| 85 | + homeserver, |
| 86 | + }, workerInfo) => { |
| 87 | + test.skip( |
| 88 | + workerInfo.project.name === "Rust Crypto", |
| 89 | + "No need to test this on Rust Crypto as we override the config manually", |
| 90 | + ); |
| 91 | + test.slow(); |
| 92 | + await page.goto("/#/login"); |
| 93 | + |
| 94 | + await context.route(`http://localhost:8080/config.json*`, async (route) => { |
| 95 | + const json = { |
| 96 | + default_server_config: { |
| 97 | + "m.homeserver": { |
| 98 | + base_url: "https://server.invalid", |
| 99 | + }, |
| 100 | + }, |
| 101 | + }; |
| 102 | + // we only want to test the default |
| 103 | + json["features"] = {}; |
| 104 | + json["setting_defaults"] = { |
| 105 | + language: "en-GB", |
| 106 | + }; |
| 107 | + await route.fulfill({ json }); |
| 108 | + }); |
| 109 | + |
| 110 | + // reload to get the new config |
| 111 | + await page.reload(); |
| 112 | + await logIntoElement(page, homeserver, credentials); |
| 113 | + |
| 114 | + await app.settings.openUserSettings("Help & About"); |
| 115 | + await expect(page.getByText("Crypto version: Rust SDK")).toBeVisible(); |
| 116 | + }); |
| 117 | + |
| 118 | + test("Test default is to not rollout existing logins", async ({ |
| 119 | + page, |
| 120 | + context, |
| 121 | + app, |
| 122 | + credentials, |
| 123 | + homeserver, |
| 124 | + }, workerInfo) => { |
| 125 | + test.skip( |
| 126 | + workerInfo.project.name === "Rust Crypto", |
| 127 | + "No need to test this on Rust Crypto as we override the config manually", |
| 128 | + ); |
| 129 | + test.slow(); |
| 130 | + |
| 131 | + await page.goto("/#/login"); |
| 132 | + |
| 133 | + // In the project.name = "Legacy crypto" it will be olm crypto |
| 134 | + await logIntoElement(page, homeserver, credentials); |
| 135 | + |
| 136 | + await app.settings.openUserSettings("Help & About"); |
| 137 | + await expect(page.getByText("Crypto version: Olm")).toBeVisible(); |
| 138 | + |
| 139 | + // Now simulate a refresh with `feature_rust_crypto` enabled but ensure we use the default rollout |
| 140 | + await context.route(`http://localhost:8080/config.json*`, async (route) => { |
| 141 | + const json = {}; |
| 142 | + json["features"] = { |
| 143 | + feature_rust_crypto: true, |
| 144 | + }; |
| 145 | + json["setting_defaults"] = { |
| 146 | + // We want to test the default so we don't set this |
| 147 | + // "RustCrypto.staged_rollout_percent": 0, |
| 148 | + }; |
| 149 | + await route.fulfill({ json }); |
| 150 | + }); |
| 151 | + |
| 152 | + await page.reload(); |
| 153 | + |
| 154 | + await app.settings.openUserSettings("Help & About"); |
| 155 | + await expect(page.getByText("Crypto version: Olm")).toBeVisible(); |
| 156 | + }); |
| 157 | + |
| 158 | + test("Migrate using labflag should work", async ({ page, context, app, credentials, homeserver }, workerInfo) => { |
| 159 | + test.skip( |
| 160 | + workerInfo.project.name === "Rust Crypto", |
| 161 | + "No need to test this on Rust Crypto as we override the config manually", |
| 162 | + ); |
| 163 | + test.slow(); |
| 164 | + |
| 165 | + await page.goto("/#/login"); |
| 166 | + |
| 167 | + // In the project.name = "Legacy crypto" it will be olm crypto |
| 168 | + await logIntoElement(page, homeserver, credentials); |
| 169 | + |
| 170 | + await app.settings.openUserSettings("Help & About"); |
| 171 | + await expect(page.getByText("Crypto version: Olm")).toBeVisible(); |
| 172 | + |
| 173 | + // We need to enable devtools for this test |
| 174 | + await app.settings.setValue("developerMode", null, SettingLevel.ACCOUNT, true); |
| 175 | + |
| 176 | + // Now simulate a refresh with `feature_rust_crypto` enabled but ensure no automatic migration |
| 177 | + await context.route(`http://localhost:8080/config.json*`, async (route) => { |
| 178 | + const json = {}; |
| 179 | + json["features"] = { |
| 180 | + feature_rust_crypto: true, |
| 181 | + }; |
| 182 | + json["setting_defaults"] = { |
| 183 | + "RustCrypto.staged_rollout_percent": 0, |
| 184 | + }; |
| 185 | + await route.fulfill({ json }); |
| 186 | + }); |
| 187 | + |
| 188 | + await page.reload(); |
| 189 | + |
| 190 | + // Go to the labs flag and enable the migration |
| 191 | + await app.settings.openUserSettings("Labs"); |
| 192 | + await page.getByRole("switch", { name: "Rust cryptography implementation" }).click(); |
| 193 | + |
| 194 | + // Fixes a bug where a missing session data was shown |
| 195 | + // https://github.com/element-hq/element-web/issues/26970 |
| 196 | + |
| 197 | + await app.settings.openUserSettings("Help & About"); |
| 198 | + await expect(page.getByText("Crypto version: Rust SDK")).toBeVisible(); |
| 199 | + }); |
| 200 | + |
| 201 | + test("Test migration of room shields", async ({ page, context, app, credentials, homeserver }, workerInfo) => { |
| 202 | + test.skip( |
| 203 | + workerInfo.project.name === "Rust Crypto", |
| 204 | + "No need to test this on Rust Crypto as we override the config manually", |
| 205 | + ); |
| 206 | + test.slow(); |
| 207 | + |
| 208 | + await page.goto("/#/login"); |
| 209 | + |
| 210 | + // In the project.name = "Legacy crypto" it will be olm crypto |
| 211 | + await logIntoElement(page, homeserver, credentials); |
| 212 | + |
| 213 | + // create a room and send a message |
| 214 | + await createRoom(page, "Room1", true); |
| 215 | + await sendMessageInCurrentRoom(page, "Hello"); |
| 216 | + |
| 217 | + // enable backup to save this room key |
| 218 | + const securityKey = await enableKeyBackup(app); |
| 219 | + |
| 220 | + // wait a bit for upload to complete, there is a random timout on key upload |
| 221 | + await page.waitForTimeout(6000); |
| 222 | + |
| 223 | + // logout |
| 224 | + await logOutOfElement(page); |
| 225 | + |
| 226 | + // We logout and log back in in order to get the historical key from backup and have a gray shield |
| 227 | + await page.reload(); |
| 228 | + await page.goto("/#/login"); |
| 229 | + // login again and verify |
| 230 | + await logIntoElement(page, homeserver, credentials, securityKey); |
| 231 | + |
| 232 | + await app.viewRoomByName("Room1"); |
| 233 | + |
| 234 | + { |
| 235 | + const messageDiv = page.locator(".mx_EventTile_line").filter({ hasText: "Hello" }); |
| 236 | + // there should be a shield |
| 237 | + await expect(messageDiv.locator(".mx_EventTile_e2eIcon")).toBeVisible(); |
| 238 | + } |
| 239 | + |
| 240 | + // Now type a new message |
| 241 | + await sendMessageInCurrentRoom(page, "World"); |
| 242 | + |
| 243 | + // wait a bit for the message to be sent |
| 244 | + await expect( |
| 245 | + page |
| 246 | + .locator(".mx_EventTile_line") |
| 247 | + .filter({ hasText: "World" }) |
| 248 | + .locator("..") |
| 249 | + .locator(".mx_EventTile_receiptSent"), |
| 250 | + ).toBeVisible(); |
| 251 | + { |
| 252 | + const messageDiv = page.locator(".mx_EventTile_line").filter({ hasText: "World" }); |
| 253 | + // there should not be a shield |
| 254 | + expect(await messageDiv.locator(".mx_EventTile_e2eIcon").count()).toEqual(0); |
| 255 | + } |
| 256 | + |
| 257 | + // trigger a migration |
| 258 | + await context.route(`http://localhost:8080/config.json*`, async (route) => { |
| 259 | + const json = {}; |
| 260 | + json["features"] = { |
| 261 | + feature_rust_crypto: true, |
| 262 | + }; |
| 263 | + json["setting_defaults"] = { |
| 264 | + "RustCrypto.staged_rollout_percent": 100, |
| 265 | + }; |
| 266 | + await route.fulfill({ json }); |
| 267 | + }); |
| 268 | + |
| 269 | + await page.reload(); |
| 270 | + |
| 271 | + await app.viewRoomByName("Room1"); |
| 272 | + |
| 273 | + // The shields should be migrated properly |
| 274 | + { |
| 275 | + const messageDiv = page.locator(".mx_EventTile_line").filter({ hasText: "Hello" }); |
| 276 | + await expect(messageDiv).toBeVisible(); |
| 277 | + // there should be a shield |
| 278 | + await expect(messageDiv.locator(".mx_EventTile_e2eIcon")).toBeVisible(); |
| 279 | + } |
| 280 | + { |
| 281 | + const messageDiv = page.locator(".mx_EventTile_line").filter({ hasText: "World" }); |
| 282 | + await expect(messageDiv).toBeVisible(); |
| 283 | + // there should not be a shield |
| 284 | + expect(await messageDiv.locator(".mx_EventTile_e2eIcon").count()).toEqual(0); |
| 285 | + } |
| 286 | + |
| 287 | + await app.settings.openUserSettings("Help & About"); |
| 288 | + await expect(page.getByText("Crypto version: Rust SDK")).toBeVisible(); |
| 289 | + }); |
| 290 | +}); |
0 commit comments