Skip to content

Commit

Permalink
test(crypto): rename "security key" into "recovery key" in test files
Browse files Browse the repository at this point in the history
  • Loading branch information
florianduros committed Feb 7, 2025
1 parent 2ecdaf3 commit 2d8be67
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import userEvent from "@testing-library/user-event";
import { mockPlatformPeg, stubClient } from "../../../../test-utils";
import AccessSecretStorageDialog from "../../../../../src/components/views/dialogs/security/AccessSecretStorageDialog";

const securityKey = "EsTc WKmb ivvk jLS7 Y1NH 5CcQ mP1E JJwj B3Fd pFWm t4Dp dbyu";
const recoveryKey = "EsTc WKmb ivvk jLS7 Y1NH 5CcQ mP1E JJwj B3Fd pFWm t4Dp dbyu";

describe("AccessSecretStorageDialog", () => {
let mockClient: MatrixClient;
Expand All @@ -29,11 +29,11 @@ describe("AccessSecretStorageDialog", () => {
render(<AccessSecretStorageDialog {...defaultProps} {...props} />);
};

const enterSecurityKey = (placeholder = "Security Key"): void => {
const enterRecoveryKey = (placeholder = "Recovery Key"): void => {
act(() => {
fireEvent.change(screen.getByPlaceholderText(placeholder), {
target: {
value: securityKey,
value: recoveryKey,
},
});
// wait for debounce
Expand Down Expand Up @@ -67,17 +67,17 @@ describe("AccessSecretStorageDialog", () => {
renderComponent({ onFinished, checkPrivateKey });

// check that the input field is focused
expect(screen.getByPlaceholderText("Security Key")).toHaveFocus();
expect(screen.getByPlaceholderText("Recovery Key")).toHaveFocus();

await enterSecurityKey();
await enterRecoveryKey();
await submitDialog();

expect(screen.getByText("Looks good!")).toBeInTheDocument();
expect(checkPrivateKey).toHaveBeenCalledWith({ recoveryKey: securityKey });
expect(onFinished).toHaveBeenCalledWith({ recoveryKey: securityKey });
expect(checkPrivateKey).toHaveBeenCalledWith({ recoveryKey });
expect(onFinished).toHaveBeenCalledWith({ recoveryKey });
});

it("Notifies the user if they input an invalid Security Key", async () => {
it("Notifies the user if they input an invalid Recovery Key", async () => {
const onFinished = jest.fn();
const checkPrivateKey = jest.fn().mockResolvedValue(true);
renderComponent({ onFinished, checkPrivateKey });
Expand All @@ -86,11 +86,11 @@ describe("AccessSecretStorageDialog", () => {
throw new Error("invalid key");
});

await enterSecurityKey();
await enterRecoveryKey();
await submitDialog();

expect(screen.getByText("Continue")).toBeDisabled();
expect(screen.getByText("Invalid Security Key")).toBeInTheDocument();
expect(screen.getByText("Invalid Recovery Key")).toBeInTheDocument();
});

it("Notifies the user if they input an invalid passphrase", async function () {
Expand All @@ -110,8 +110,8 @@ describe("AccessSecretStorageDialog", () => {
const checkPrivateKey = jest.fn().mockResolvedValue(false);
renderComponent({ checkPrivateKey, keyInfo });

await enterSecurityKey("Security Phrase");
expect(screen.getByPlaceholderText("Security Phrase")).toHaveValue(securityKey);
await enterRecoveryKey("Security Phrase");
expect(screen.getByPlaceholderText("Security Phrase")).toHaveValue(recoveryKey);
await submitDialog();

await expect(
Expand Down Expand Up @@ -141,11 +141,11 @@ describe("AccessSecretStorageDialog", () => {
document.execCommand = jest.fn().mockReturnValue(true);
jest.spyOn(mockClient.getCrypto()!, "createRecoveryKeyFromPassphrase").mockResolvedValue({
privateKey: new Uint8Array(),
encodedPrivateKey: securityKey,
encodedPrivateKey: recoveryKey,
});
screen.getByRole("button", { name: "Continue" }).click();

await screen.findByText(/Save your Security Key/);
await screen.findByText(/Save your Recovery Key/);
screen.getByRole("button", { name: "Copy" }).click();
await screen.findByText("Copied!");
screen.getByRole("button", { name: "Continue" }).click();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ describe("CreateSecretStorageDialog", () => {
expect(result.container).toMatchSnapshot();
await userEvent.click(result.getByRole("button", { name: "Continue" }));

await screen.findByText("Save your Security Key");
await screen.findByText("Save your Recovery Key");
expect(result.container).toMatchSnapshot();
// Copy the key to enable the continue button
await userEvent.click(screen.getByRole("button", { name: "Copy" }));
Expand All @@ -66,7 +66,7 @@ describe("CreateSecretStorageDialog", () => {
"Safeguard against losing access to encrypted messages & data by backing up encryption keys on your server.",
);
await userEvent.click(screen.getByRole("button", { name: "Continue" }));
await screen.findByText("Save your Security Key");
await screen.findByText("Save your Recovery Key");
await userEvent.click(screen.getByRole("button", { name: "Copy" }));
await userEvent.click(screen.getByRole("button", { name: "Continue" }));

Expand Down Expand Up @@ -108,7 +108,7 @@ describe("CreateSecretStorageDialog", () => {
});
result.getByRole("button", { name: "Continue" }).click();

await result.findByText(/Save your Security Key/);
await result.findByText(/Save your Recovery Key/);
result.getByRole("button", { name: "Copy" }).click();

// Resetting should reset secret storage, cross signing, and key
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ describe("<RestoreKeyBackupDialog />", () => {

it("should render", async () => {
const { asFragment } = render(<RestoreKeyBackupDialog onFinished={jest.fn()} />);
await waitFor(() => expect(screen.getByText("Enter Security Key")).toBeInTheDocument());
await waitFor(() => expect(screen.getByText("Enter Recovery Key")).toBeInTheDocument());
expect(asFragment()).toMatchSnapshot();
});

Expand All @@ -41,19 +41,19 @@ describe("<RestoreKeyBackupDialog />", () => {
throw new Error("Invalid recovery key");
});
const { asFragment } = render(<RestoreKeyBackupDialog onFinished={jest.fn()} />);
await waitFor(() => expect(screen.getByText("Enter Security Key")).toBeInTheDocument());
await waitFor(() => expect(screen.getByText("Enter Recovery Key")).toBeInTheDocument());

await userEvent.type(screen.getByRole("textbox"), "invalid key");
await waitFor(() => expect(screen.getByText("👎 Not a valid Security Key")).toBeInTheDocument());
await waitFor(() => expect(screen.getByText("👎 Not a valid Recovery Key")).toBeInTheDocument());
expect(asFragment()).toMatchSnapshot();
});

it("should not raise an error when recovery is valid", async () => {
const { asFragment } = render(<RestoreKeyBackupDialog onFinished={jest.fn()} />);
await waitFor(() => expect(screen.getByText("Enter Security Key")).toBeInTheDocument());
await waitFor(() => expect(screen.getByText("Enter Recovery Key")).toBeInTheDocument());

await userEvent.type(screen.getByRole("textbox"), "valid key");
await waitFor(() => expect(screen.getByText("👍 This looks like a valid Security Key!")).toBeInTheDocument());
await waitFor(() => expect(screen.getByText("👍 This looks like a valid Recovery Key!")).toBeInTheDocument());
expect(asFragment()).toMatchSnapshot();
});

Expand All @@ -79,17 +79,17 @@ describe("<RestoreKeyBackupDialog />", () => {
expect(asFragment()).toMatchSnapshot();
});

it("should restore key backup when security key is filled by user", async () => {
it("should restore key backup when Recovery key is filled by user", async () => {
jest.spyOn(matrixClient.getCrypto()!, "restoreKeyBackup")
// Reject when trying to restore from cache
.mockRejectedValueOnce(new Error("key backup not found"))
// Resolve when trying to restore from recovery key
.mockResolvedValue(keyBackupRestoreResult);

const { asFragment } = render(<RestoreKeyBackupDialog onFinished={jest.fn()} />);
await waitFor(() => expect(screen.getByText("Enter Security Key")).toBeInTheDocument());
await waitFor(() => expect(screen.getByText("Enter Recovery Key")).toBeInTheDocument());

await userEvent.type(screen.getByRole("textbox"), "my security key");
await userEvent.type(screen.getByRole("textbox"), "my Recovery key");
await userEvent.click(screen.getByRole("button", { name: "Next" }));

await waitFor(() => expect(screen.getByText("Successfully restored 1 keys")).toBeInTheDocument());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ exports[`CreateSecretStorageDialog handles the happy path 1`] = `
<span
class="mx_CreateSecretStorageDialog_optionIcon mx_CreateSecretStorageDialog_optionIcon_secureBackup"
/>
Generate a Security Key
Generate a Recovery Key
</div>
<div>
We'll generate a Security Key for you to store somewhere safe, like a password manager or a safe.
We'll generate a Recovery Key for you to store somewhere safe, like a password manager or a safe.
</div>
</div>
<div
Expand Down Expand Up @@ -88,7 +88,7 @@ exports[`CreateSecretStorageDialog handles the happy path 1`] = `
Enter a Security Phrase
</div>
<div>
Use a secret phrase only you know, and optionally save a Security Key to use for backup.
Use a secret phrase only you know, and optionally save a Recovery Key to use for backup.
</div>
</div>
<div
Expand Down Expand Up @@ -148,13 +148,13 @@ exports[`CreateSecretStorageDialog handles the happy path 2`] = `
class="mx_Heading_h3 mx_Dialog_title mx_CreateSecretStorageDialog_titleWithIcon mx_CreateSecretStorageDialog_secureBackupTitle"
id="mx_BaseDialog_title"
>
Save your Security Key
Save your Recovery Key
</h1>
</div>
<div>
<div>
<p>
Store your Security Key somewhere safe, like a password manager or a safe, as it's used to safeguard your encrypted data.
Store your Recovery Key somewhere safe, like a password manager or a safe, as it's used to safeguard your encrypted data.
</p>
<div
class="mx_CreateSecretStorageDialog_primaryContainer mx_CreateSecretStorageDialog_recoveryKeyPrimarycontainer"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ exports[`<RestoreKeyBackupDialog /> should display an error when recovery key is
class="mx_Heading_h3 mx_Dialog_title"
id="mx_BaseDialog_title"
>
Enter Security Key
Enter Recovery Key
</h1>
</div>
<div
Expand All @@ -36,7 +36,7 @@ exports[`<RestoreKeyBackupDialog /> should display an error when recovery key is
</span>
</p>
<p>
Access your secure message history and set up secure messaging by entering your Security Key.
Access your secure message history and set up secure messaging by entering your Recovery Key.
</p>
<div
class="mx_RestoreKeyBackupDialog_primaryContainer"
Expand All @@ -48,7 +48,7 @@ exports[`<RestoreKeyBackupDialog /> should display an error when recovery key is
<div
class="mx_RestoreKeyBackupDialog_keyStatus"
>
👎 Not a valid Security Key
👎 Not a valid Recovery Key
</div>
<div
class="mx_Dialog_buttons"
Expand All @@ -74,7 +74,7 @@ exports[`<RestoreKeyBackupDialog /> should display an error when recovery key is
</div>
</div>
<span>
If you've forgotten your Security Key you can
If you've forgotten your Recovery Key you can
<div
class="mx_AccessibleButton mx_AccessibleButton_hasKind mx_AccessibleButton_kind_link_inline"
role="button"
Expand Down Expand Up @@ -120,7 +120,7 @@ exports[`<RestoreKeyBackupDialog /> should not raise an error when recovery is v
class="mx_Heading_h3 mx_Dialog_title"
id="mx_BaseDialog_title"
>
Enter Security Key
Enter Recovery Key
</h1>
</div>
<div
Expand All @@ -136,7 +136,7 @@ exports[`<RestoreKeyBackupDialog /> should not raise an error when recovery is v
</span>
</p>
<p>
Access your secure message history and set up secure messaging by entering your Security Key.
Access your secure message history and set up secure messaging by entering your Recovery Key.
</p>
<div
class="mx_RestoreKeyBackupDialog_primaryContainer"
Expand All @@ -148,7 +148,7 @@ exports[`<RestoreKeyBackupDialog /> should not raise an error when recovery is v
<div
class="mx_RestoreKeyBackupDialog_keyStatus"
>
👍 This looks like a valid Security Key!
👍 This looks like a valid Recovery Key!
</div>
<div
class="mx_Dialog_buttons"
Expand All @@ -173,7 +173,7 @@ exports[`<RestoreKeyBackupDialog /> should not raise an error when recovery is v
</div>
</div>
<span>
If you've forgotten your Security Key you can
If you've forgotten your Recovery Key you can
<div
class="mx_AccessibleButton mx_AccessibleButton_hasKind mx_AccessibleButton_kind_link_inline"
role="button"
Expand Down Expand Up @@ -219,7 +219,7 @@ exports[`<RestoreKeyBackupDialog /> should render 1`] = `
class="mx_Heading_h3 mx_Dialog_title"
id="mx_BaseDialog_title"
>
Enter Security Key
Enter Recovery Key
</h1>
</div>
<div
Expand All @@ -235,7 +235,7 @@ exports[`<RestoreKeyBackupDialog /> should render 1`] = `
</span>
</p>
<p>
Access your secure message history and set up secure messaging by entering your Security Key.
Access your secure message history and set up secure messaging by entering your Recovery Key.
</p>
<div
class="mx_RestoreKeyBackupDialog_primaryContainer"
Expand Down Expand Up @@ -271,7 +271,7 @@ exports[`<RestoreKeyBackupDialog /> should render 1`] = `
</div>
</div>
<span>
If you've forgotten your Security Key you can
If you've forgotten your Recovery Key you can
<div
class="mx_AccessibleButton mx_AccessibleButton_hasKind mx_AccessibleButton_kind_link_inline"
role="button"
Expand All @@ -297,7 +297,7 @@ exports[`<RestoreKeyBackupDialog /> should render 1`] = `
</DocumentFragment>
`;

exports[`<RestoreKeyBackupDialog /> should restore key backup when passphrase is filled 1`] = `
exports[`<RestoreKeyBackupDialog /> should restore key backup when Recovery key is filled by user 1`] = `
<DocumentFragment>
<div
data-focus-guard="true"
Expand Down Expand Up @@ -362,7 +362,7 @@ exports[`<RestoreKeyBackupDialog /> should restore key backup when passphrase is
</DocumentFragment>
`;

exports[`<RestoreKeyBackupDialog /> should restore key backup when security key is filled by user 1`] = `
exports[`<RestoreKeyBackupDialog /> should restore key backup when passphrase is filled 1`] = `
<DocumentFragment>
<div
data-focus-guard="true"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ exports[`<SecureBackupPanel /> handles error fetching backup 1`] = `
<div
class="mx_SettingsSubsection_text"
>
Back up your encryption keys with your account data in case you lose access to your sessions. Your keys will be secured with a unique Security Key.
Back up your encryption keys with your account data in case you lose access to your sessions. Your keys will be secured with a unique Recovery Key.
</div>
<div
class="mx_SettingsSubsection_text"
Expand Down Expand Up @@ -71,7 +71,7 @@ exports[`<SecureBackupPanel /> suggests connecting session to key backup when ba
<div
class="mx_SettingsSubsection_text"
>
Back up your encryption keys with your account data in case you lose access to your sessions. Your keys will be secured with a unique Security Key.
Back up your encryption keys with your account data in case you lose access to your sessions. Your keys will be secured with a unique Recovery Key.
</div>
<div
class="mx_SettingsSubsection_text"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ exports[`<SecurityUserSettingsTab /> renders security section 1`] = `
<div
class="mx_SettingsSubsection_text"
>
Back up your encryption keys with your account data in case you lose access to your sessions. Your keys will be secured with a unique Security Key.
Back up your encryption keys with your account data in case you lose access to your sessions. Your keys will be secured with a unique Recovery Key.
</div>
<div
class="mx_Spinner"
Expand Down

0 comments on commit 2d8be67

Please sign in to comment.