fix: an open popup moves to the recovery screen when its profile becomes unreadable (closes #373)
A popup already open when the stored profile became unreadable stayed on the last good profile until reopened. Every save already runs the check loadState() runs at open; a save refused by it now stops the ten-second refresh, runs the leave cleanup of the current screen, and raises the recovery screen. From then on showView() shows nothing else in that popup, so a transaction wait or a later save cannot take the user off it or clear an export or a typed confirmation. That is held in memory, never as the saved current view, so a popup opened after the record is erased elsewhere opens normally. Any other failed save keeps the "NOT SAVED" banner. The popup test harness now honours clearInterval(). Model: opus-5-5
This commit is contained in:
@@ -148,6 +148,173 @@ describe("the destructive reset on the recovery screen", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("a popup already open when the stored profile becomes unreadable", () => {
|
||||
// https://git.eeqj.de/sneak/AutistMask/issues/373. The popup used to stay
|
||||
// on the wallet list with the last good balances, and only a reopen
|
||||
// reached the recovery screen.
|
||||
test("moves to the recovery screen at its next refresh", async () => {
|
||||
const env = await bootPopup(unversionedValidProfile());
|
||||
expect(env.visibleViews()).toEqual(["main"]);
|
||||
|
||||
env.storage.write("autistmask", CORRUPT_BLOBS[0].blob);
|
||||
await env.tick();
|
||||
|
||||
expect(env.visibleViews()).toEqual(["state-recovery"]);
|
||||
expect(env.text("state-recovery-problem").length).toBeGreaterThan(10);
|
||||
expect(env.hidden("btn-settings")).toBe(true);
|
||||
expect(env.storage.read("autistmask")).toEqual(CORRUPT_BLOBS[0].blob);
|
||||
});
|
||||
|
||||
test("stops the ten-second refresh", async () => {
|
||||
const env = await bootPopup(unversionedValidProfile());
|
||||
env.storage.write("autistmask", CORRUPT_BLOBS[0].blob);
|
||||
await env.tick();
|
||||
const { refreshBalances } = require("../src/shared/balances");
|
||||
const calls = refreshBalances.mock.calls.length;
|
||||
|
||||
await env.tick();
|
||||
|
||||
expect(refreshBalances).toHaveBeenCalledTimes(calls);
|
||||
});
|
||||
|
||||
test("a later save does not clear what the user exported or typed", async () => {
|
||||
const env = await bootPopup(unversionedValidProfile());
|
||||
env.storage.write("autistmask", CORRUPT_BLOBS[2].blob);
|
||||
await env.tick();
|
||||
|
||||
await env.click("btn-state-recovery-export");
|
||||
env.node("state-recovery-reset-input").value = "erase my";
|
||||
// Such as the save of a refresh already in flight when the screen
|
||||
// went up.
|
||||
const { saveState } = require("../src/shared/state");
|
||||
await expect(saveState()).rejects.toThrow();
|
||||
await env.settle();
|
||||
|
||||
expect(env.visibleViews()).toEqual(["state-recovery"]);
|
||||
expect(env.hidden("state-recovery-blob")).toBe(false);
|
||||
expect(env.value("state-recovery-reset-input")).toBe("erase my");
|
||||
});
|
||||
|
||||
// The record can become readable again under this popup, erased from the
|
||||
// recovery screen of another window, so a save from this one can succeed.
|
||||
test("a popup opened after the record is erased elsewhere shows a screen", async () => {
|
||||
const env = await bootPopup(unversionedValidProfile());
|
||||
env.storage.write("autistmask", CORRUPT_BLOBS[0].blob);
|
||||
await env.tick();
|
||||
expect(env.visibleViews()).toEqual(["state-recovery"]);
|
||||
|
||||
await env.storage.remove("autistmask");
|
||||
const { saveState } = require("../src/shared/state");
|
||||
await saveState();
|
||||
|
||||
const reopened = await bootPopup(env.storage.read("autistmask"));
|
||||
expect(reopened.visibleViews()).toEqual(["welcome"]);
|
||||
});
|
||||
|
||||
test("a stored current view of the recovery screen does not blank the popup", async () => {
|
||||
const env = await bootPopup(
|
||||
unversionedValidProfile({ currentView: "state-recovery" }),
|
||||
);
|
||||
expect(env.visibleViews()).toEqual(["main"]);
|
||||
});
|
||||
|
||||
test("a transaction wait that ends under it does not replace it", async () => {
|
||||
const env = await bootPopup(
|
||||
unversionedValidProfile({
|
||||
currentView: "wait-tx",
|
||||
viewData: {
|
||||
pendingWait: {
|
||||
hash: "0x1",
|
||||
txInfo: { to: ADDRESS, amount: "1", token: "ETH" },
|
||||
broadcastTime: Date.now(),
|
||||
},
|
||||
},
|
||||
}),
|
||||
);
|
||||
expect(env.visibleViews()).toEqual(["wait-tx"]);
|
||||
env.storage.write("autistmask", CORRUPT_BLOBS[2].blob);
|
||||
await env.tick();
|
||||
await env.click("btn-state-recovery-export");
|
||||
env.node("state-recovery-reset-input").value = "erase my";
|
||||
|
||||
// The test provider answers no receipt lookup, and six that fail in
|
||||
// a row end the wait with an error.
|
||||
for (let i = 0; i < 6; i++) await env.tick();
|
||||
|
||||
expect(env.text("error-tx-message")).toMatch(/could not be reached/);
|
||||
expect(env.visibleViews()).toEqual(["state-recovery"]);
|
||||
expect(env.hidden("state-recovery-blob")).toBe(false);
|
||||
expect(env.value("state-recovery-reset-input")).toBe("erase my");
|
||||
});
|
||||
|
||||
test("a storage read that fails once leaves the wallet list up", async () => {
|
||||
const env = await bootPopup(unversionedValidProfile());
|
||||
|
||||
env.storage.local.get.mockRejectedValueOnce(
|
||||
new Error("IO error: storage busy"),
|
||||
);
|
||||
await env.tick();
|
||||
|
||||
// Reported as a failed save, not mistaken for an unreadable profile.
|
||||
expect(env.visibleViews()).toEqual(["main"]);
|
||||
expect(env.node("save-failure-banner")).not.toBeNull();
|
||||
|
||||
await env.tick();
|
||||
expect(env.visibleViews()).toEqual(["main"]);
|
||||
});
|
||||
|
||||
// The screen it replaces is left as any navigation leaves it: the rules
|
||||
// at the top of src/popup/views/showPhrase.js and exportPrivkey.js hold
|
||||
// for this way off them too.
|
||||
describe("from a screen holding a secret", () => {
|
||||
const PHRASE =
|
||||
"abandon abandon abandon abandon abandon abandon abandon" +
|
||||
" abandon abandon abandon abandon about";
|
||||
|
||||
afterEach(() => jest.dontMock("../src/shared/vault"));
|
||||
|
||||
test("a recovery phrase on screen is wiped", async () => {
|
||||
jest.doMock("../src/shared/vault", () => ({
|
||||
decryptWithPassword: async () => PHRASE,
|
||||
}));
|
||||
const env = await bootPopup(unversionedValidProfile());
|
||||
require("../src/popup/views/showPhrase").show(0);
|
||||
env.node("show-phrase-password").value = "password";
|
||||
await env.click("btn-show-phrase-reveal");
|
||||
expect(env.text("show-phrase-value")).toBe(PHRASE);
|
||||
|
||||
env.storage.write("autistmask", CORRUPT_BLOBS[0].blob);
|
||||
await env.tick();
|
||||
|
||||
expect(env.visibleViews()).toEqual(["state-recovery"]);
|
||||
expect(env.text("show-phrase-value")).toBe("");
|
||||
});
|
||||
|
||||
test("a private key still being decrypted is never written", async () => {
|
||||
let answer;
|
||||
jest.doMock("../src/shared/vault", () => ({
|
||||
decryptWithPassword: () =>
|
||||
new Promise((resolve) => {
|
||||
answer = resolve;
|
||||
}),
|
||||
}));
|
||||
const env = await bootPopup(unversionedValidProfile());
|
||||
require("../src/popup/views/exportPrivkey").show(0, 0);
|
||||
env.node("export-privkey-password").value = "password";
|
||||
const revealing = env.click("btn-export-privkey-confirm");
|
||||
|
||||
env.storage.write("autistmask", CORRUPT_BLOBS[0].blob);
|
||||
await env.tick();
|
||||
expect(env.visibleViews()).toEqual(["state-recovery"]);
|
||||
expect(env.value("export-privkey-password")).toBe("");
|
||||
|
||||
answer(PHRASE);
|
||||
await revealing;
|
||||
expect(env.text("export-privkey-value")).toBe("");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("an unversioned profile that is perfectly valid", () => {
|
||||
// The upgrade case. Every install in the field is in this state, and the
|
||||
// popup must load it, not offer to wipe it.
|
||||
|
||||
Reference in New Issue
Block a user