mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 08:20:43 +00:00
test: share matrix crypto reset assertions
This commit is contained in:
@@ -90,6 +90,35 @@ function expectSecretStorageRepairRetry(
|
||||
expect(bootstrapCrossSigning).toHaveBeenCalledTimes(2);
|
||||
}
|
||||
|
||||
function createForcedResetHarness(bootstrapCrossSigning: ReturnType<typeof vi.fn>) {
|
||||
return createBootstrapperHarness({
|
||||
bootstrapCrossSigning,
|
||||
isCrossSigningReady: vi.fn(async () => true),
|
||||
userHasCrossSigningKeys: vi.fn(async () => true),
|
||||
getDeviceVerificationStatus: vi.fn(async () => createVerifiedDeviceStatus()),
|
||||
});
|
||||
}
|
||||
|
||||
function expectForcedResetCrossSigningCalls(
|
||||
bootstrapCrossSigning: ReturnType<typeof vi.fn>,
|
||||
params: { setupNewCall: number; totalCalls: number },
|
||||
) {
|
||||
expect(bootstrapCrossSigning).toHaveBeenCalledTimes(params.totalCalls);
|
||||
expect(bootstrapCrossSigning).toHaveBeenNthCalledWith(
|
||||
params.setupNewCall,
|
||||
expect.objectContaining({
|
||||
setupNewCrossSigning: true,
|
||||
authUploadDeviceSigningKeys: expect.any(Function),
|
||||
}),
|
||||
);
|
||||
expect(bootstrapCrossSigning).toHaveBeenNthCalledWith(
|
||||
params.totalCalls,
|
||||
expect.objectContaining({
|
||||
authUploadDeviceSigningKeys: expect.any(Function),
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
async function bootstrapWithVerificationRequestListener(overrides?: {
|
||||
deps?: Partial<ReturnType<typeof createBootstrapperDeps>>;
|
||||
crypto?: Partial<MatrixCryptoBootstrapApi>;
|
||||
@@ -345,12 +374,7 @@ describe("MatrixCryptoBootstrapper", () => {
|
||||
.fn<() => Promise<void>>()
|
||||
.mockRejectedValueOnce(new Error("getSecretStorageKey callback returned falsey"))
|
||||
.mockResolvedValueOnce(undefined);
|
||||
const { deps, crypto, bootstrapper } = createBootstrapperHarness({
|
||||
bootstrapCrossSigning,
|
||||
isCrossSigningReady: vi.fn(async () => true),
|
||||
userHasCrossSigningKeys: vi.fn(async () => true),
|
||||
getDeviceVerificationStatus: vi.fn(async () => createVerifiedDeviceStatus()),
|
||||
});
|
||||
const { deps, crypto, bootstrapper } = createForcedResetHarness(bootstrapCrossSigning);
|
||||
|
||||
await bootstrapper.bootstrap(crypto, {
|
||||
strict: true,
|
||||
@@ -365,30 +389,15 @@ describe("MatrixCryptoBootstrapper", () => {
|
||||
forceNewSecretStorage: true,
|
||||
},
|
||||
);
|
||||
expect(bootstrapCrossSigning).toHaveBeenCalledTimes(3);
|
||||
expect(bootstrapCrossSigning).toHaveBeenNthCalledWith(
|
||||
2,
|
||||
expect.objectContaining({
|
||||
setupNewCrossSigning: true,
|
||||
authUploadDeviceSigningKeys: expect.any(Function),
|
||||
}),
|
||||
);
|
||||
expect(bootstrapCrossSigning).toHaveBeenNthCalledWith(
|
||||
3,
|
||||
expect.objectContaining({
|
||||
authUploadDeviceSigningKeys: expect.any(Function),
|
||||
}),
|
||||
);
|
||||
expectForcedResetCrossSigningCalls(bootstrapCrossSigning, {
|
||||
setupNewCall: 2,
|
||||
totalCalls: 3,
|
||||
});
|
||||
});
|
||||
|
||||
it("re-exports cross-signing keys after forced reset creates secret storage", async () => {
|
||||
const bootstrapCrossSigning = vi.fn(async () => {});
|
||||
const { deps, crypto, bootstrapper } = createBootstrapperHarness({
|
||||
bootstrapCrossSigning,
|
||||
isCrossSigningReady: vi.fn(async () => true),
|
||||
userHasCrossSigningKeys: vi.fn(async () => true),
|
||||
getDeviceVerificationStatus: vi.fn(async () => createVerifiedDeviceStatus()),
|
||||
});
|
||||
const { deps, crypto, bootstrapper } = createForcedResetHarness(bootstrapCrossSigning);
|
||||
|
||||
await bootstrapper.bootstrap(crypto, {
|
||||
strict: true,
|
||||
@@ -402,20 +411,10 @@ describe("MatrixCryptoBootstrapper", () => {
|
||||
allowSecretStorageRecreateWithoutRecoveryKey: true,
|
||||
},
|
||||
);
|
||||
expect(bootstrapCrossSigning).toHaveBeenCalledTimes(2);
|
||||
expect(bootstrapCrossSigning).toHaveBeenNthCalledWith(
|
||||
1,
|
||||
expect.objectContaining({
|
||||
setupNewCrossSigning: true,
|
||||
authUploadDeviceSigningKeys: expect.any(Function),
|
||||
}),
|
||||
);
|
||||
expect(bootstrapCrossSigning).toHaveBeenNthCalledWith(
|
||||
2,
|
||||
expect.objectContaining({
|
||||
authUploadDeviceSigningKeys: expect.any(Function),
|
||||
}),
|
||||
);
|
||||
expectForcedResetCrossSigningCalls(bootstrapCrossSigning, {
|
||||
setupNewCall: 1,
|
||||
totalCalls: 2,
|
||||
});
|
||||
});
|
||||
|
||||
it("fails in strict mode when cross-signing keys are still unpublished", async () => {
|
||||
|
||||
Reference in New Issue
Block a user