-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a playwright test for backup reset / deleted (#28858)
* Add a playwright test for backup reset / deleted A slightly tricky one to test but an important case that people can hit, and one that otherwise wouldn't get hit a lot during normal usage, so I think probably quite a useful test to have. Mostly though, I'm about to change this to a toast, so I'd like a test to assert that it still works. * Return directly Co-authored-by: Florian Duros <florianduros@element.io> * Fix tsdco --------- Co-authored-by: Florian Duros <florianduros@element.io>
- Loading branch information
1 parent
d8f6c12
commit 29624f7
Showing
2 changed files
with
105 additions
and
0 deletions.
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
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}`); | ||
} | ||
} | ||
} |