fix: harden app lock system unlock flow

This commit is contained in:
Zheng Liu committed 2026-06-24 14:42:49 +08:00
1 parent f6a49dbf0a
commit 0ea707f70f
14 files changed
+114 -26

No files matched your search

@@ -44,6 +44,7 @@ export function createAppLockBridgeHarness(options: HarnessOptions) {
let systemUnlockResult = options.systemUnlockResult ?? { ok: true as const };
let systemUnlockCount = 0;
let resetCount = 0;
const resetAttempts: string[] = [];
let runtimeFetchCount = 0;
const emitRuntimeState = () => {
@@ -84,8 +85,11 @@ export function createAppLockBridgeHarness(options: HarnessOptions) {
});
return { ok: true } satisfies UnlockResult;
},
requestAppLockReset: async () => {
requestAppLockReset: async (currentPassword) => {
resetCount += 1;
resetAttempts.push(currentPassword);
if (!currentPassword) return { ok: false, error: "empty-current" };
if (currentPassword !== unlockPassword) return { ok: false, error: "incorrect" };
setRuntimeState({
initialized: true,
locked: false,
@@ -96,6 +100,7 @@ export function createAppLockBridgeHarness(options: HarnessOptions) {
return {
enabled: false,
timeoutMinutes: 15,
systemUnlockEnabled: false,
passwordVerifier: null,
};
},
@@ -178,6 +183,9 @@ export function createAppLockBridgeHarness(options: HarnessOptions) {
getResetCount() {
return resetCount;
},
getResetAttempts() {
return [...resetAttempts];
},
getSystemUnlockCount() {
return systemUnlockCount;
},