Skip to content

Commit 62a2872

Browse files
authored
add test to ensure that dehydrated device gets removed on identity reset (#29354)
1 parent db45a17 commit 62a2872

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

playwright/e2e/crypto/dehydration.spec.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,40 @@ test.describe("Dehydration", () => {
116116
expect(dehydratedDeviceIds.length).toBe(1);
117117
expect(dehydratedDeviceIds[0]).not.toEqual(initialDehydratedDeviceIds[0]);
118118
});
119+
120+
test("'Reset cryptographic identity' removes dehydrated device", async ({ page, homeserver, app, credentials }) => {
121+
await logIntoElement(page, credentials);
122+
123+
// Create a dehydrated device by setting up recovery (see "'Set up
124+
// recovery' creates dehydrated device" test above)
125+
const settingsDialogLocator = await app.settings.openUserSettings("Encryption");
126+
await settingsDialogLocator.getByRole("button", { name: "Set up recovery" }).click();
127+
128+
// First it displays an informative panel about the recovery key
129+
await expect(settingsDialogLocator.getByRole("heading", { name: "Set up recovery" })).toBeVisible();
130+
await settingsDialogLocator.getByRole("button", { name: "Continue" }).click();
131+
132+
// Next, it displays the new recovery key. We click on the copy button.
133+
await expect(settingsDialogLocator.getByText("Save your recovery key somewhere safe")).toBeVisible();
134+
await settingsDialogLocator.getByRole("button", { name: "Copy" }).click();
135+
const recoveryKey = await app.getClipboard();
136+
await settingsDialogLocator.getByRole("button", { name: "Continue" }).click();
137+
138+
await expect(
139+
settingsDialogLocator.getByText("Enter your recovery key to confirm", { exact: true }),
140+
).toBeVisible();
141+
await settingsDialogLocator.getByRole("textbox").fill(recoveryKey);
142+
await settingsDialogLocator.getByRole("button", { name: "Finish set up" }).click();
143+
144+
await expectDehydratedDeviceEnabled(app);
145+
146+
// After recovery is set up, we reset our cryptographic identity, which
147+
// should drop the dehydrated device.
148+
await settingsDialogLocator.getByRole("button", { name: "Reset cryptographic identity" }).click();
149+
await settingsDialogLocator.getByRole("button", { name: "Continue" }).click();
150+
151+
await expectDehydratedDeviceDisabled(app);
152+
});
119153
});
120154

121155
async function getDehydratedDeviceIds(client: Client): Promise<string[]> {
@@ -144,3 +178,16 @@ async function expectDehydratedDeviceEnabled(app: ElementAppPage): Promise<void>
144178
})
145179
.toEqual(1);
146180
}
181+
182+
/** Wait for our user to not have a dehydrated device */
183+
async function expectDehydratedDeviceDisabled(app: ElementAppPage): Promise<void> {
184+
// It might be nice to do this via the UI, but currently this info is not exposed via the UI.
185+
//
186+
// Note we might have to wait for the device list to be refreshed, so we wrap in `expect.poll`.
187+
await expect
188+
.poll(async () => {
189+
const dehydratedDeviceIds = await getDehydratedDeviceIds(app.client);
190+
return dehydratedDeviceIds.length;
191+
})
192+
.toEqual(0);
193+
}

0 commit comments

Comments
 (0)