




















@@ -57,6 +57,31 @@ function createRecoveryKeyCrypto(params: {
5757} as unknown as MatrixCryptoBootstrapApi;
5858}
595960+function bootstrapSecretStorageCallArg(
61+bootstrapSecretStorage: ReturnType<typeof vi.fn>,
62+index: number,
63+) {
64+const call = bootstrapSecretStorage.mock.calls[index];
65+if (!call) {
66+throw new Error(`expected bootstrapSecretStorage call ${index}`);
67+}
68+return call[0] as { setupNewSecretStorage?: boolean } | undefined;
69+}
70+71+function expectRecoveryKeySummary(
72+store: MatrixRecoveryKeyStore,
73+expected: { keyId: string; encodedPrivateKey?: string },
74+) {
75+const summary = store.getRecoveryKeySummary();
76+if (!summary) {
77+throw new Error("expected recovery key summary");
78+}
79+expect(summary.keyId).toBe(expected.keyId);
80+if (expected.encodedPrivateKey !== undefined) {
81+expect(summary.encodedPrivateKey).toBe(expected.encodedPrivateKey);
82+}
83+}
84+6085async function runSecretStorageBootstrapScenario(params: {
6186generated: ReturnType<typeof createGeneratedRecoveryKey>;
6287status: MatrixSecretStorageStatus;
@@ -153,12 +178,10 @@ describe("MatrixRecoveryKeyStore", () => {
153178});
154179155180expect(createRecoveryKeyFromPassphrase).toHaveBeenCalledTimes(1);
156-expect(bootstrapSecretStorage).toHaveBeenCalledWith(
157-expect.objectContaining({
158-setupNewSecretStorage: true,
159-}),
181+expect(bootstrapSecretStorageCallArg(bootstrapSecretStorage, 0)?.setupNewSecretStorage).toBe(
182+true,
160183);
161-expect(store.getRecoveryKeySummary()).toMatchObject({
184+expectRecoveryKeySummary(store, {
162185keyId: "GENERATED",
163186encodedPrivateKey: "encoded-generated-key", // pragma: allowlist secret
164187});
@@ -194,7 +217,7 @@ describe("MatrixRecoveryKeyStore", () => {
194217await store.bootstrapSecretStorageWithRecoveryKey(crypto);
195218196219expect(createRecoveryKeyFromPassphrase).not.toHaveBeenCalled();
197-expect(store.getRecoveryKeySummary()).toMatchObject({
220+expectRecoveryKeySummary(store, {
198221keyId: "NEW",
199222});
200223});
@@ -212,12 +235,10 @@ describe("MatrixRecoveryKeyStore", () => {
212235});
213236214237expect(createRecoveryKeyFromPassphrase).toHaveBeenCalledTimes(1);
215-expect(bootstrapSecretStorage).toHaveBeenCalledWith(
216-expect.objectContaining({
217-setupNewSecretStorage: true,
218-}),
238+expect(bootstrapSecretStorageCallArg(bootstrapSecretStorage, 0)?.setupNewSecretStorage).toBe(
239+true,
219240);
220-expect(store.getRecoveryKeySummary()).toMatchObject({
241+expectRecoveryKeySummary(store, {
221242keyId: "RECOVERED",
222243encodedPrivateKey: "encoded-recovered-key", // pragma: allowlist secret
223244});
@@ -243,12 +264,10 @@ describe("MatrixRecoveryKeyStore", () => {
243264244265expect(createRecoveryKeyFromPassphrase).toHaveBeenCalledTimes(1);
245266expect(bootstrapSecretStorage).toHaveBeenCalledTimes(2);
246-expect(bootstrapSecretStorage).toHaveBeenLastCalledWith(
247-expect.objectContaining({
248-setupNewSecretStorage: true,
249-}),
267+expect(bootstrapSecretStorageCallArg(bootstrapSecretStorage, 1)?.setupNewSecretStorage).toBe(
268+true,
250269);
251-expect(store.getRecoveryKeySummary()).toMatchObject({
270+expectRecoveryKeySummary(store, {
252271keyId: "REPAIRED",
253272encodedPrivateKey: "encoded-repaired-key", // pragma: allowlist secret
254273});
@@ -274,10 +293,8 @@ describe("MatrixRecoveryKeyStore", () => {
274293275294expect(createRecoveryKeyFromPassphrase).toHaveBeenCalledTimes(1);
276295expect(bootstrapSecretStorage).toHaveBeenCalledTimes(2);
277-expect(bootstrapSecretStorage).toHaveBeenLastCalledWith(
278-expect.objectContaining({
279-setupNewSecretStorage: true,
280-}),
296+expect(bootstrapSecretStorageCallArg(bootstrapSecretStorage, 1)?.setupNewSecretStorage).toBe(
297+true,
281298);
282299});
283300此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。