惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Apple Machine Learning Research
Apple Machine Learning Research
Jina AI
Jina AI
博客园_首页
WordPress大学
WordPress大学
罗磊的独立博客
小众软件
小众软件
Last Week in AI
Last Week in AI
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Hugging Face - Blog
Hugging Face - Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
爱范儿
爱范儿
The Cloudflare Blog
GbyAI
GbyAI
C
Check Point Blog
腾讯CDC
MyScale Blog
MyScale Blog
有赞技术团队
有赞技术团队
博客园 - 聂微东
IT之家
IT之家
雷峰网
雷峰网
H
Help Net Security
博客园 - 叶小钗
美团技术团队
D
DataBreaches.Net

Recent Commits to openclaw:main

test: merge chat side-result checks · openclaw/openclaw@ddd2c2a test: merge cron history checks · openclaw/openclaw@f7eb746 test: merge responsive navigation shell checks · openclaw/openclaw@c2e4b47 docs(changelog): add codex oauth fixes · openclaw/openclaw@628e6cd test: merge navigation routing cases · openclaw/openclaw@5d8cecb Tests: mock channel registry bundled fallback · openclaw/openclaw@2b08233 Secrets: avoid broad web search discovery for single plugin config · openclaw/openclaw@a464f59 test: merge config view browser checks · openclaw/openclaw@20cf511 fix(status): align oauth health with runtime · openclaw/openclaw@eed7116 feat: add macOS screen snapshots for monitor preview (#67954) thanks … · openclaw/openclaw@f377db1 fix: report shared auth scopes in hello-ok (#67810) thanks @BunsDev · openclaw/openclaw@0b6c39b Auto-reply: avoid eager bundled route fallback · openclaw/openclaw@3ea1bf4 Tests: narrow session binding contract setup · openclaw/openclaw@54e4e16 fix(macOS): enable undo/redo in webchat composer text input (#34962) · openclaw/openclaw@00951dc Tests: speed up channel setup promotion · openclaw/openclaw@82b529a Docs: refresh agent instructions · openclaw/openclaw@5775fe2 fix(auth): serialize OAuth refresh across agents to fix #26322 (#67876) · openclaw/openclaw@8e79080 test: allow ollama public surface boundary test · openclaw/openclaw@7d4f1a6 Docs: add test performance guardrails · openclaw/openclaw@89706d3 Tests: restore context-engine usage proof · openclaw/openclaw@e4c4f95 Tests: slim context engine runtime coverage · openclaw/openclaw@74c198f ci: retry failed custom checkouts · openclaw/openclaw@0ee5baf test: trim duplicate provider auth onboarding cases · openclaw/openclaw@1ffc02e matrix: fix sessions_spawn --thread subagent session spawning (#67643) · openclaw/openclaw@1ce2596 test: reduce auth choice fixture churn · openclaw/openclaw@857b9cd test: mock health status config boundaries · openclaw/openclaw@9d5ab4a test: mock onboard config io boundary · openclaw/openclaw@299694d test: mock legacy state plugin boundaries · openclaw/openclaw@2713089 test: mock channel install boundaries · openclaw/openclaw@b945248 test: mock doctor preview channel boundaries · openclaw/openclaw@b1a3ad4
fix(matrix): prevent double bootstrapCrossSigning reset i...
vincentkoc · 2026-06-22 · via Recent Commits to openclaw:main
11

// Matrix tests cover crypto bootstrap plugin behavior.

22

import { beforeEach, describe, expect, it, vi, type Mock } from "vitest";

33

import { MatrixCryptoBootstrapper, type MatrixCryptoBootstrapperDeps } from "./crypto-bootstrap.js";

4+

import type { MatrixRecoveryKeyStore } from "./recovery-key-store.js";

45

import type { MatrixCryptoBootstrapApi, MatrixRawEvent } from "./types.js";

5667

type BootstrapCrossSigningMock = Mock<MatrixCryptoBootstrapApi["bootstrapCrossSigning"]>;

@@ -39,12 +40,15 @@ function createBootstrapperDeps() {

3940

return {

4041

getUserId: vi.fn(async () => "@bot:example.org"),

4142

getPassword: vi.fn<() => string | undefined>(() => "super-secret-password"),

43+

canUnlockSecretStorage: vi.fn(async () => true),

4244

getDeviceId: vi.fn(() => "DEVICE123"),

4345

verificationManager: {

4446

trackVerificationRequest: vi.fn(),

4547

},

4648

recoveryKeyStore: {

47-

bootstrapSecretStorageWithRecoveryKey: vi.fn(async () => {}),

49+

bootstrapSecretStorageWithRecoveryKey: vi.fn<

50+

MatrixRecoveryKeyStore["bootstrapSecretStorageWithRecoveryKey"]

51+

>(async () => {}),

4852

},

4953

decryptBridge: {

5054

bindCryptoRetrySignals: vi.fn(),

@@ -132,17 +136,6 @@ function createForcedResetHarness(bootstrapCrossSigning: BootstrapCrossSigningMo

132136

});

133137

}

134138135-

function expectForcedResetCrossSigningCalls(

136-

bootstrapCrossSigning: BootstrapCrossSigningMock,

137-

params: { setupNewCall: number; totalCalls: number },

138-

) {

139-

expect(bootstrapCrossSigning).toHaveBeenCalledTimes(params.totalCalls);

140-

expectBootstrapCrossSigningCall(bootstrapCrossSigning, params.setupNewCall, {

141-

setupNewCrossSigning: true,

142-

});

143-

expectBootstrapCrossSigningCall(bootstrapCrossSigning, params.totalCalls);

144-

}

145-146139

async function bootstrapWithVerificationRequestListener(overrides?: {

147140

deps?: Partial<ReturnType<typeof createBootstrapperDeps>>;

148141

crypto?: Partial<MatrixCryptoBootstrapApi>;

@@ -406,32 +399,72 @@ describe("MatrixCryptoBootstrapper", () => {

406399

);

407400408401

expect(deps.recoveryKeyStore.bootstrapSecretStorageWithRecoveryKey).not.toHaveBeenCalled();

402+

expect(bootstrapCrossSigning).toHaveBeenCalledTimes(1);

409403

});

410404411-

it("recreates secret storage and retries a forced reset when stale server SSSS blocks it", async () => {

405+

it("rejects forced reset before mutation when the active recovery key is unavailable", async () => {

406+

const deps = createBootstrapperDeps();

407+

deps.canUnlockSecretStorage = vi.fn(async () => false);

408+

const bootstrapCrossSigning = vi.fn(async () => {});

409+

const crypto = createCryptoApi({ bootstrapCrossSigning });

410+

const bootstrapper = new MatrixCryptoBootstrapper(

411+

deps as unknown as MatrixCryptoBootstrapperDeps<MatrixRawEvent>,

412+

);

413+414+

await expect(

415+

bootstrapper.bootstrap(crypto, {

416+

strict: true,

417+

forceResetCrossSigning: true,

418+

allowSecretStorageRecreateWithoutRecoveryKey: true,

419+

}),

420+

).rejects.toThrow(

421+

"Forced cross-signing reset requires the active Matrix recovery key; supply it before retrying",

422+

);

423+424+

expect(deps.recoveryKeyStore.bootstrapSecretStorageWithRecoveryKey).not.toHaveBeenCalled();

425+

expect(bootstrapCrossSigning).not.toHaveBeenCalled();

426+

});

427+428+

it("fails closed without recreating SSSS when forced reset cannot unlock it", async () => {

412429

const bootstrapCrossSigning = vi

413430

.fn<() => Promise<void>>()

414-

.mockRejectedValueOnce(new Error("getSecretStorageKey callback returned falsey"))

415-

.mockResolvedValueOnce(undefined);

431+

.mockRejectedValueOnce(new Error("getSecretStorageKey callback returned falsey"));

416432

const { deps, crypto, bootstrapper } = createForcedResetHarness(bootstrapCrossSigning);

417433418-

await bootstrapper.bootstrap(crypto, {

419-

strict: true,

434+

await expect(

435+

bootstrapper.bootstrap(crypto, {

436+

strict: true,

437+

forceResetCrossSigning: true,

438+

allowSecretStorageRecreateWithoutRecoveryKey: true,

439+

}),

440+

).rejects.toThrow(

441+

"Forced cross-signing reset cannot access secret storage; restore the Matrix recovery key before retrying",

442+

);

443+444+

expect(deps.recoveryKeyStore.bootstrapSecretStorageWithRecoveryKey).not.toHaveBeenCalled();

445+

expect(bootstrapCrossSigning).toHaveBeenCalledTimes(1);

446+

expectBootstrapCrossSigningCall(bootstrapCrossSigning, 1, { setupNewCrossSigning: true });

447+

});

448+449+

it("does not repair SSSS after a non-strict forced reset failure", async () => {

450+

const bootstrapCrossSigning = vi.fn(async () => {

451+

throw new Error("getSecretStorageKey callback returned falsey");

452+

});

453+

const { deps, crypto, bootstrapper } = createForcedResetHarness(bootstrapCrossSigning);

454+455+

const result = await bootstrapper.bootstrap(crypto, {

456+

strict: false,

420457

forceResetCrossSigning: true,

421458

allowSecretStorageRecreateWithoutRecoveryKey: true,

422459

});

423460424-

expect(deps.recoveryKeyStore.bootstrapSecretStorageWithRecoveryKey).toHaveBeenCalledWith(

425-

crypto,

426-

{

427-

allowSecretStorageRecreateWithoutRecoveryKey: true,

428-

forceNewSecretStorage: true,

429-

},

430-

);

431-

expectForcedResetCrossSigningCalls(bootstrapCrossSigning, {

432-

setupNewCall: 2,

433-

totalCalls: 3,

461+

expect(result).toEqual({

462+

crossSigningReady: false,

463+

crossSigningPublished: false,

464+

ownDeviceVerified: null,

434465

});

466+

expect(deps.recoveryKeyStore.bootstrapSecretStorageWithRecoveryKey).not.toHaveBeenCalled();

467+

expect(bootstrapCrossSigning).toHaveBeenCalledOnce();

435468

});

436469437470

it("re-exports cross-signing keys after forced reset creates secret storage", async () => {

@@ -444,16 +477,16 @@ describe("MatrixCryptoBootstrapper", () => {

444477

allowSecretStorageRecreateWithoutRecoveryKey: true,

445478

});

446479480+

expect(deps.recoveryKeyStore.bootstrapSecretStorageWithRecoveryKey).toHaveBeenCalledOnce();

447481

expect(deps.recoveryKeyStore.bootstrapSecretStorageWithRecoveryKey).toHaveBeenCalledWith(

448482

crypto,

449-

{

483+

expect.objectContaining({

450484

allowSecretStorageRecreateWithoutRecoveryKey: true,

451-

},

485+

}),

452486

);

453-

expectForcedResetCrossSigningCalls(bootstrapCrossSigning, {

454-

setupNewCall: 1,

455-

totalCalls: 2,

456-

});

487+

// No redundant second bootstrapCrossSigning call — no double reset (gh-78396).

488+

expect(bootstrapCrossSigning).toHaveBeenCalledTimes(1);

489+

expectBootstrapCrossSigningCall(bootstrapCrossSigning, 1, { setupNewCrossSigning: true });

457490

});

458491459492

it("trusts the fresh own identity after a forced cross-signing reset", async () => {