-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a playwright test for backup reset / deleted #28858
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ import { type Page } from "@playwright/test"; | |
import { test, expect } from "../../element-web-test"; | ||
import { test as masTest, registerAccountMas } from "../oidc"; | ||
import { isDendrite } from "../../plugins/homeserver/dendrite"; | ||
import { TestClientServerAPI } from "../csAPI"; | ||
|
||
async function expectBackupVersionToBe(page: Page, version: string) { | ||
await expect(page.locator(".mx_SecureBackupPanel_statusList tr:nth-child(5) td")).toHaveText( | ||
|
@@ -20,6 +21,9 @@ async function expectBackupVersionToBe(page: Page, version: string) { | |
await expect(page.locator(".mx_SecureBackupPanel_statusList tr:nth-child(6) td")).toHaveText(version); | ||
} | ||
|
||
// These tests register an account with MAS because then we go through the "normal" registration flow | ||
// and crypto gets set up. Using the 'user' fixture create a a user an synthesizes an existing login, | ||
// which is faster but leaves us without crypto set up. | ||
masTest.describe("Encryption state after registration", () => { | ||
masTest.skip(isDendrite, "does not yet support MAS"); | ||
|
||
|
@@ -46,6 +50,59 @@ masTest.describe("Encryption state after registration", () => { | |
}); | ||
}); | ||
|
||
masTest.describe("Key backup reset from elsewhere", () => { | ||
masTest.skip(isDendrite, "does not yet support MAS"); | ||
|
||
masTest( | ||
"Key backup is disabled when reset from elsewhere", | ||
async ({ page, mailhog, request, masPrepare, homeserver }) => { | ||
const testUsername = "alice"; | ||
const testPassword = "Pa$sW0rD!"; | ||
|
||
// there's a delay before keys are uploaded so the error doesn't appear immediately: use a fake | ||
// clock so we can skip the delay | ||
await page.clock.install(); | ||
|
||
await page.goto("/#/login"); | ||
await page.getByRole("button", { name: "Continue" }).click(); | ||
await registerAccountMas(page, mailhog.api, testUsername, "[email protected]", testPassword); | ||
|
||
await page.getByRole("button", { name: "Add room" }).click(); | ||
await page.getByRole("menuitem", { name: "New room" }).click(); | ||
await page.getByRole("textbox", { name: "Name" }).fill("test room"); | ||
await page.getByRole("button", { name: "Create room" }).click(); | ||
|
||
// @ts-ignore - this runs in the browser scope where mxMatrixClientPeg is a thing. Here, it is not. | ||
const accessToken = await page.evaluate(() => mxMatrixClientPeg.get().getAccessToken()); | ||
|
||
const csAPI = new TestClientServerAPI(request, homeserver, accessToken); | ||
|
||
const backupInfo = await csAPI.getCurrentBackupInfo(); | ||
|
||
await csAPI.deleteBackupVersion(backupInfo.version); | ||
|
||
await page.getByRole("textbox", { name: "Send an encrypted message…" }).fill("/discardsession"); | ||
await page.getByRole("button", { name: "Send message" }).click(); | ||
|
||
await page | ||
.getByRole("textbox", { name: "Send an encrypted message…" }) | ||
.fill("Message with broken key backup"); | ||
await page.getByRole("button", { name: "Send message" }).click(); | ||
|
||
// Should be the message we sent plus the room creation event | ||
await expect(page.locator(".mx_EventTile")).toHaveCount(2); | ||
await expect( | ||
page.locator(".mx_RoomView_MessageList > .mx_EventTile_last .mx_EventTile_receiptSent"), | ||
).toBeVisible(); | ||
|
||
// Wait for it to try uploading the key | ||
await page.clock.fastForward(20000); | ||
|
||
await expect(page.getByRole("heading", { level: 1, name: "New Recovery Method" })).toBeVisible(); | ||
}, | ||
); | ||
}); | ||
|
||
test.describe("Backups", () => { | ||
test.use({ | ||
displayName: "Hanako", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
Copyright 2024 New Vector Ltd. | ||
|
||
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only | ||
Please see LICENSE files in the repository root for full details. | ||
*/ | ||
|
||
import { APIRequestContext } from "playwright-core"; | ||
import { KeyBackupInfo } from "matrix-js-sdk/src/crypto-api"; | ||
|
||
import { HomeserverInstance } from "../plugins/homeserver"; | ||
|
||
/** | ||
* A small subset of the Client-Server API used to manipulate the state of the | ||
* account on the homeserver independently of the client under test. | ||
*/ | ||
export class TestClientServerAPI { | ||
public constructor( | ||
private request: APIRequestContext, | ||
private homeserver: HomeserverInstance, | ||
private accessToken: string, | ||
) {} | ||
|
||
public async getCurrentBackupInfo(): Promise<KeyBackupInfo | null> { | ||
const res = await this.request.get(`${this.homeserver.config.baseUrl}/_matrix/client/v3/room_keys/version`, { | ||
headers: { Authorization: `Bearer ${this.accessToken}` }, | ||
}); | ||
|
||
return await res.json(); | ||
} | ||
|
||
/** | ||
* Calls the API directly to delete the given backup version | ||
* @param version The version to delete | ||
*/ | ||
public async deleteBackupVersion(version: string): Promise<void> { | ||
const res = await this.request.delete( | ||
`${this.homeserver.config.baseUrl}/_matrix/client/v3/room_keys/version/${version}`, | ||
{ | ||
headers: { Authorization: `Bearer ${this.accessToken}` }, | ||
}, | ||
); | ||
|
||
if (!res.ok) { | ||
throw new Error(`Failed to delete backup version: ${res.status}`); | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not use the MatrixClient to delete or to get the current backup info ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was attempting to make it as much like a different client deleting the backup as possible, although what it ended up as isn't really much different from using the app's own matrix client. It still felt a little bit cleaner to use the API separately rather than inject code into the app, but I can change it if that's preferred.