test(matrix): add regression test for repair bootstrap UIA failure without password

This commit is contained in:
SARAMALI15792
2026-04-14 04:05:41 +05:00
committed by Gustavo Madeira Santana
parent 4200c9e837
commit f3a15b0b52

View File

@@ -1323,6 +1323,39 @@ describe("MatrixClient crypto bootstrapping", () => {
});
});
it("catches and logs repair bootstrap failure when UIA is unavailable without password", async () => {
matrixJsClient.getCrypto = vi.fn(() => ({ on: vi.fn() }));
const client = new MatrixClient("https://matrix.example.org", "token", {
encryption: true,
// no password
});
const uiaError = new Error("Interactive auth required");
const bootstrapSpy = vi
.fn()
.mockResolvedValueOnce({
crossSigningReady: false,
crossSigningPublished: false,
ownDeviceVerified: false,
})
.mockRejectedValueOnce(uiaError);
await (
client as unknown as {
ensureCryptoSupportInitialized: () => Promise<void>;
}
).ensureCryptoSupportInitialized();
(
client as unknown as {
cryptoBootstrapper: { bootstrap: typeof bootstrapSpy };
}
).cryptoBootstrapper.bootstrap = bootstrapSpy;
// start() must NOT throw even when the repair bootstrap fails
await expect(client.start()).resolves.not.toThrow();
// repair was attempted
expect(bootstrapSpy).toHaveBeenCalledTimes(2);
});
it("provides secret storage callbacks and resolves stored recovery key", async () => {
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "matrix-sdk-test-"));
const recoveryKeyPath = path.join(tmpDir, "recovery-key.json");