Remove AccountPasswordStore and related flows (#28750)

* Remove AccountPasswordStore and related flows

As they are no longer needed since MSC3967

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>

* Iterate

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>

* Iterate

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>

* Improve coverage

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>

* Update src/CreateCrossSigning.ts

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

* Update comment

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>

---------

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
Co-authored-by: Richard van der Hoff <1389908+richvdh@users.noreply.github.com>
This commit is contained in:
Michael Telatynski
2024-12-19 11:55:05 +00:00
committed by GitHub
parent 2c4a079153
commit cd7cf86b96
13 changed files with 71 additions and 257 deletions

View File

@@ -8,12 +8,11 @@ Please see LICENSE files in the repository root for full details.
import { mocked } from "jest-mock";
import { MatrixClient } from "matrix-js-sdk/src/matrix";
import { waitFor } from "jest-matrix-react";
import { sleep } from "matrix-js-sdk/src/utils";
import { createCrossSigning } from "../../../src/CreateCrossSigning";
import { InitialCryptoSetupStore } from "../../../src/stores/InitialCryptoSetupStore";
import { SdkContextClass } from "../../../src/contexts/SDKContext";
import { createTestClient } from "../../test-utils";
import { AccountPasswordStore } from "../../../src/stores/AccountPasswordStore";
jest.mock("../../../src/CreateCrossSigning", () => ({
createCrossSigning: jest.fn(),
@@ -22,7 +21,6 @@ jest.mock("../../../src/CreateCrossSigning", () => ({
describe("InitialCryptoSetupStore", () => {
let testStore: InitialCryptoSetupStore;
let client: MatrixClient;
let stores: SdkContextClass;
let createCrossSigningResolve: () => void;
let createCrossSigningReject: (e: Error) => void;
@@ -30,11 +28,6 @@ describe("InitialCryptoSetupStore", () => {
beforeEach(() => {
testStore = new InitialCryptoSetupStore();
client = createTestClient();
stores = {
accountPasswordStore: {
getPassword: jest.fn(),
} as unknown as AccountPasswordStore,
} as unknown as SdkContextClass;
mocked(createCrossSigning).mockImplementation(() => {
return new Promise<void>((resolve, reject) => {
@@ -45,7 +38,7 @@ describe("InitialCryptoSetupStore", () => {
});
it("should call createCrossSigning when startInitialCryptoSetup is called", async () => {
testStore.startInitialCryptoSetup(client, false, stores, jest.fn());
testStore.startInitialCryptoSetup(client, jest.fn());
await waitFor(() => expect(createCrossSigning).toHaveBeenCalled());
});
@@ -54,7 +47,7 @@ describe("InitialCryptoSetupStore", () => {
const updateSpy = jest.fn();
testStore.on("update", updateSpy);
testStore.startInitialCryptoSetup(client, false, stores, jest.fn());
testStore.startInitialCryptoSetup(client, jest.fn());
createCrossSigningResolve();
await waitFor(() => expect(updateSpy).toHaveBeenCalled());
@@ -65,21 +58,28 @@ describe("InitialCryptoSetupStore", () => {
const updateSpy = jest.fn();
testStore.on("update", updateSpy);
testStore.startInitialCryptoSetup(client, false, stores, jest.fn());
testStore.startInitialCryptoSetup(client, jest.fn());
createCrossSigningReject(new Error("Test error"));
await waitFor(() => expect(updateSpy).toHaveBeenCalled());
expect(testStore.getStatus()).toBe("error");
});
it("should ignore failures if tokenLogin is true", async () => {
const updateSpy = jest.fn();
testStore.on("update", updateSpy);
it("should fail to retry once complete", async () => {
testStore.startInitialCryptoSetup(client, jest.fn());
testStore.startInitialCryptoSetup(client, true, stores, jest.fn());
await waitFor(() => expect(createCrossSigning).toHaveBeenCalled());
createCrossSigningResolve();
await sleep(0); // await the next tick
expect(testStore.retry()).toBeFalsy();
});
it("should retry if initial attempt failed", async () => {
testStore.startInitialCryptoSetup(client, jest.fn());
await waitFor(() => expect(createCrossSigning).toHaveBeenCalled());
createCrossSigningReject(new Error("Test error"));
await waitFor(() => expect(updateSpy).toHaveBeenCalled());
expect(testStore.getStatus()).toBe("complete");
await sleep(0); // await the next tick
expect(testStore.retry()).toBeTruthy();
});
});