Skip to content

Wire up the "Forgot recovery key" button for the "Key storage out of sync" toast#29138

Merged
dbkr merged 16 commits into
developfrom
dbkr/keystorage_outofsync_forgotpassword
Feb 4, 2025
Merged

Wire up the "Forgot recovery key" button for the "Key storage out of sync" toast#29138
dbkr merged 16 commits into
developfrom
dbkr/keystorage_outofsync_forgotpassword

Conversation

@dbkr
Copy link
Copy Markdown
Member

@dbkr dbkr commented Jan 29, 2025

Fixes #29118 by making the 'forgot recovery key' button take you into settings to the flow to reset your recovery key.

Checklist

  • Tests written for new code (and old code if feasible).
  • New or updated public/exported symbols have accurate TSDoc documentation.
  • Linter and other CI checks pass.
  • I have licensed the changes to Element by completing the Contributor License Agreement (CLA)

@dbkr dbkr marked this pull request as ready for review January 31, 2025 13:05
@dbkr dbkr requested review from a team as code owners January 31, 2025 13:05
Comment on lines +56 to +66
const recheckSetupRequired = useCallback(() => {
(async () => {
const crypto = matrixClient.getCrypto()!;
const isCrossSigningReady = await crypto.isCrossSigningReady();
if (isCrossSigningReady) {
setState("main");
} else {
setState("set_up_encryption");
}
})();
}, [matrixClient]);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm in favour to use a custom hook like useSetUpEncryptionRequired before. It helps the readability of the component imo

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something like this? I find the custom hook a bit awkward in this scenario since you have to pass a lot of functions around, but I don't mind too much.

Comment thread src/components/views/settings/tabs/user/EncryptionUserSettingsTab.tsx Outdated
Comment on lines +60 to +64
if (isCrossSigningReady) {
setState("main");
} else {
setState("set_up_encryption");
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (isCrossSigningReady) {
setState("main");
} else {
setState("set_up_encryption");
}
if (isCrossSigningReady) setState("main");
else setState("set_up_encryption");

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd really rather not if at all possible: I find these line-ifs split over multiple lines very confusing, and I think our code style permits line ifs only if they're one single line.

Comment thread src/components/views/settings/tabs/user/EncryptionUserSettingsTab.tsx Outdated
Comment thread playwright/e2e/crypto/toasts.spec.ts Outdated
import { registerAccountMas } from "../oidc";
import { deleteCachedSecrets } from "./utils";

test.use(masHomeserver);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test needs mas?

Comment thread playwright/e2e/crypto/toasts.spec.ts Outdated
Comment on lines +20 to +44
test.beforeEach(async ({ page, app, mailpitClient }) => {
await page.goto("/#/login");
await page.getByRole("button", { name: "Continue" }).click();
await registerAccountMas(page, mailpitClient, "alice", "alice@email.com", "Pa$sW0rD!");

await expect(page.getByRole("heading", { level: 1, name: "Welcome alice" })).toBeVisible();

// We won't be prompted for crypto setup unless we have na e2e room, so make one
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();

// Now set up recovery (otherwise we'll delete the only copy of the secret)
await page.getByLabel("User menu").click();
await page.getByLabel("All settings").click();
await page.getByRole("tab", { name: "Encryption" }).click();
await page.getByRole("button", { name: "Set up recovery" }).click();
await page.getByRole("button", { name: "Continue" }).click();
recoveryKey = await page.getByTestId("recoveryKey").textContent();
await page.getByRole("button", { name: "Continue" }).click();
await page.getByRole("textbox", { name: "Enter recovery key" }).fill(recoveryKey);
await page.getByRole("button", { name: "Finish set up" }).click();

await expect(page.getByRole("button", { name: "Change recovery key" })).toBeVisible();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we use crypto/utils#createBot to create a second session, bootstrap cross singing and create a recovery key?

crypto/utils#verifySession can be used to verify the current session too

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It took a bit but I think this is working with the bot client now.

Copy link
Copy Markdown
Member

@uhoreg uhoreg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From a crypto point of view, looks OK

Comment thread playwright/e2e/crypto/toasts.spec.ts Outdated
@dbkr dbkr added this pull request to the merge queue Feb 4, 2025
Merged via the queue into develop with commit 9657d39 Feb 4, 2025
@dbkr dbkr deleted the dbkr/keystorage_outofsync_forgotpassword branch February 4, 2025 17:52
@dbkr dbkr added the backport staging Label to automatically backport PR to staging branch label Feb 4, 2025
RiotRobot pushed a commit that referenced this pull request Feb 4, 2025
…sync" toast (#29138)

* Wire up the "Forgot recovery key" button for the "Key storage out of sync" toast

* Unused import & fix test

* Test 'forgot' variant

* Fix dependencies

* Add more toast tests

* Unused import

* Test initialState in Encryption Tab

* Let's see if github has any more luck running this test than me

* Working playwright test with screenshot

* year

* Convert playwright test to use the bot client

* Disambiguate

Co-authored-by: Florian Duros <florianduros@element.io>

* Add doc & do other part of rename

* Split out into custom hook

* Fix tests

---------

Co-authored-by: Florian Duros <florianduros@element.io>
(cherry picked from commit 9657d39)
@richvdh
Copy link
Copy Markdown
Member

richvdh commented Feb 5, 2025

"Wire up", but what actually happens? can we get some screenshots or something?

Comment thread src/components/views/dialogs/UserSettingsDialog.tsx
Comment thread src/toasts/SetupEncryptionToast.ts
Comment thread src/components/views/settings/encryption/ResetIdentityPanel.tsx
Comment thread playwright/e2e/crypto/utils.ts
import { test, expect } from "../../element-web-test";
import { createBot, deleteCachedSecrets, logIntoElement } from "./utils";

test.describe("Key storage out of sync toast", () => {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(don't we already have some tests for this toast somewhere else?)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so - maybe the backup failure screen is what you're thinking of?

Comment thread playwright/e2e/crypto/toasts.spec.ts
github-merge-queue Bot pushed a commit that referenced this pull request Feb 7, 2025
…Key storage out of sync" toast (#29190)

* Wire up the "Forgot recovery key" button for the "Key storage out of sync" toast (#29138)

* Wire up the "Forgot recovery key" button for the "Key storage out of sync" toast

* Unused import & fix test

* Test 'forgot' variant

* Fix dependencies

* Add more toast tests

* Unused import

* Test initialState in Encryption Tab

* Let's see if github has any more luck running this test than me

* Working playwright test with screenshot

* year

* Convert playwright test to use the bot client

* Disambiguate

Co-authored-by: Florian Duros <florianduros@element.io>

* Add doc & do other part of rename

* Split out into custom hook

* Fix tests

---------

Co-authored-by: Florian Duros <florianduros@element.io>
(cherry picked from commit 9657d39)

* Update fetchdep.sh to understand merge queues

---------

Co-authored-by: David Baker <dbkr@users.noreply.github.com>
Co-authored-by: Michael Telatynski <7t3chguy@gmail.com>
@dbkr dbkr mentioned this pull request Mar 14, 2025
4 tasks
@dbkr
Copy link
Copy Markdown
Member Author

dbkr commented Mar 14, 2025

Have opened #29503 to address the feedback that came in afterwards.

t3chguy pushed a commit that referenced this pull request Mar 18, 2025
* Rename props & fix typo

* Docs

* Better docs

* Add comment

* Fix typo

* Paragraphs in tsdoc

* Add comment

* Hopefully clearer comment

* Really fix typo

Co-authored-by: Will Hunt <will@half-shot.uk>

* Stray word

Co-authored-by: Andy Balaam <andy.balaam@matrix.org>

* Hopefully clearer comment

* Typo

* Formatting & clarity

Co-authored-by: Richard van der Hoff <1389908+richvdh@users.noreply.github.com>

---------

Co-authored-by: Will Hunt <will@half-shot.uk>
Co-authored-by: Andy Balaam <andy.balaam@matrix.org>
Co-authored-by: Richard van der Hoff <1389908+richvdh@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport staging Label to automatically backport PR to staging branch T-Defect

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Your key storage is out of sync - Forgot recovery key? - After click silently disappears

4 participants