-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Handle cross-signing keys missing locally and/or from secret storage #31367
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
base: develop
Are you sure you want to change the base?
Changes from 1 commit
e1ca135
d0ed546
85f8b9c
48743ee
303417e
c44916c
fb2dbe7
d7a2ac9
8983cef
f1f1f85
bb3a130
ff53fc1
bccb180
6f31fed
da86841
46915f7
3f52a6f
b09f67c
edc4d81
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -12,16 +12,29 @@ import { mocked } from "jest-mock"; | |||||||||||||
|
|
||||||||||||||
| import { RecoveryPanelOutOfSync } from "../../../../../../src/components/views/settings/encryption/RecoveryPanelOutOfSync"; | ||||||||||||||
| import { accessSecretStorage } from "../../../../../../src/SecurityManager"; | ||||||||||||||
| import DeviceListener from "../../../../../../src/DeviceListener"; | ||||||||||||||
| import { stubClient } from "../../../../../test-utils"; | ||||||||||||||
| import { MatrixClientPeg } from "../../../../../../src/MatrixClientPeg"; | ||||||||||||||
| import MatrixClientContext from "../../../../../../src/contexts/MatrixClientContext"; | ||||||||||||||
|
|
||||||||||||||
| jest.mock("../../../../../../src/SecurityManager", () => ({ | ||||||||||||||
| accessSecretStorage: jest.fn(), | ||||||||||||||
| })); | ||||||||||||||
|
|
||||||||||||||
| describe("<RecoveyPanelOutOfSync />", () => { | ||||||||||||||
| function renderComponent(onFinish = jest.fn(), onForgotRecoveryKey = jest.fn()) { | ||||||||||||||
| return render(<RecoveryPanelOutOfSync onFinish={onFinish} onForgotRecoveryKey={onForgotRecoveryKey} />); | ||||||||||||||
| stubClient(); | ||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoid using MatrixClientPeg.safeGet(), prefer to create the matrix client and put it an a context
Suggested change
|
||||||||||||||
| return render( | ||||||||||||||
| <MatrixClientContext.Provider value={MatrixClientPeg.safeGet()}> | ||||||||||||||
| <RecoveryPanelOutOfSync onFinish={onFinish} onForgotRecoveryKey={onForgotRecoveryKey} /> | ||||||||||||||
| </MatrixClientContext.Provider>, | ||||||||||||||
| ); | ||||||||||||||
|
Comment on lines
+27
to
+31
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| afterEach(() => { | ||||||||||||||
| jest.restoreAllMocks(); | ||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
| }); | ||||||||||||||
|
|
||||||||||||||
| it("should render", () => { | ||||||||||||||
| const { asFragment } = renderComponent(); | ||||||||||||||
| expect(asFragment()).toMatchSnapshot(); | ||||||||||||||
|
|
@@ -38,14 +51,42 @@ describe("<RecoveyPanelOutOfSync />", () => { | |||||||||||||
| }); | ||||||||||||||
|
|
||||||||||||||
| it("should access to 4S and call onFinish when 'Enter recovery key' is clicked", async () => { | ||||||||||||||
| jest.spyOn(DeviceListener.sharedInstance(), "keyStorageOutOfSyncNeedsBackupReset").mockResolvedValue(false); | ||||||||||||||
|
|
||||||||||||||
| const user = userEvent.setup(); | ||||||||||||||
| mocked(accessSecretStorage) | ||||||||||||||
| .mockClear() | ||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With |
||||||||||||||
| .mockImplementation(async (func = async (): Promise<void> => {}) => { | ||||||||||||||
| return await func(); | ||||||||||||||
| }); | ||||||||||||||
|
Comment on lines
+59
to
+61
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we really need to call the function in
Suggested change
|
||||||||||||||
|
|
||||||||||||||
| const onFinish = jest.fn(); | ||||||||||||||
| renderComponent(onFinish); | ||||||||||||||
|
|
||||||||||||||
| await user.click(screen.getByRole("button", { name: "Enter recovery key" })); | ||||||||||||||
| expect(accessSecretStorage).toHaveBeenCalled(); | ||||||||||||||
| expect(onFinish).toHaveBeenCalled(); | ||||||||||||||
|
|
||||||||||||||
| expect(MatrixClientPeg.safeGet().getCrypto()!.resetKeyBackup).not.toHaveBeenCalled(); | ||||||||||||||
| }); | ||||||||||||||
|
|
||||||||||||||
| it("should reset key backup if needed", async () => { | ||||||||||||||
| jest.spyOn(DeviceListener.sharedInstance(), "keyStorageOutOfSyncNeedsBackupReset").mockResolvedValue(true); | ||||||||||||||
|
|
||||||||||||||
| const user = userEvent.setup(); | ||||||||||||||
| mocked(accessSecretStorage).mockClear().mockResolvedValue(); | ||||||||||||||
| mocked(accessSecretStorage) | ||||||||||||||
| .mockClear() | ||||||||||||||
| .mockImplementation(async (func = async (): Promise<void> => {}) => { | ||||||||||||||
| return await func(); | ||||||||||||||
| }); | ||||||||||||||
|
|
||||||||||||||
| const onFinish = jest.fn(); | ||||||||||||||
| renderComponent(onFinish); | ||||||||||||||
|
|
||||||||||||||
| await user.click(screen.getByRole("button", { name: "Enter recovery key" })); | ||||||||||||||
| expect(accessSecretStorage).toHaveBeenCalled(); | ||||||||||||||
| expect(onFinish).toHaveBeenCalled(); | ||||||||||||||
|
|
||||||||||||||
| expect(MatrixClientPeg.safeGet().getCrypto()!.resetKeyBackup).toHaveBeenCalled(); | ||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto matrix client |
||||||||||||||
| }); | ||||||||||||||
| }); | ||||||||||||||
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.
what is happening if this promises are rejected?