Refractoring Stage 7.2 Added IPC regression tests verifying native confirmation protects OpenPGP key replacement and trust elevation: cancellation leaves stored key state unchanged, while confirmation permits the change. Bumped to 0.4.38 (Android version code 438) and updated REFACTOR_PLAN.md.

This commit is contained in:
2026-10-16 23:28:34 +03:00
parent cdf1b2dd62
commit 60d692f8b4
4 changed files with 73 additions and 4 deletions
+2 -1
View File
@@ -153,7 +153,7 @@ This is a gradual destination, not a requirement to move everything at once. IPC
- Electron Builder and the desktop Actions artifact name derive from `package.json`.
- Android `versionName` derives from the same package version. Its current `versionCode` mapping is `major * 10000 + minor * 100 + patch`; keep minor and patch below 100, and revise the mapping before reaching that boundary to avoid collisions.
- `scripts/build-all.ps1` uses the package version for APK naming. Before a release, bump once with `npm run bump:build`, verify the lockfile and computed Android version code, and build every target without another bump.
- Latest version check: `package.json` and both lockfile version fields are `0.4.37`; Android derives `versionName 0.4.37` and `versionCode 437`. The user confirms the previous artifact works; this bump is for the next build.
- Latest version check: `package.json` and both lockfile version fields are `0.4.38`; Android derives `versionName 0.4.38` and `versionCode 438`. The user confirms the previous artifact works; this bump is for the next build.
## Progress log
@@ -193,5 +193,6 @@ This is a gradual destination, not a requirement to move everything at once. IPC
- Step 6 at version `0.4.35` consolidates the mail API factory under `window.epMailFeatures.modules`, removing the separate `window.epMailUiModules` global.
- Step 6 at version `0.4.36` consolidates the HTML sanitization and remote-image policy API under `window.epMailFeatures.contentSecurity`.
- Step 7 at version `0.4.37` adds focused sanitizer coverage for dangerous DOM nodes/attributes and verifies that remote images remain data-only pending explicit loading.
- Step 7 at version `0.4.38` tests main-process native confirmation for OpenPGP key replacement and trust elevation; cancellation must not mutate stored key state.
- The current IPC/DAV validation changes pass the full suite: 108 tests.
- While work continued, `package.json` and `package-lock.json` reflected a version bump to `0.4.6`; those changes were preserved.
+2 -2
View File
@@ -1,12 +1,12 @@
{
"name": "ep-mail",
"version": "0.4.37",
"version": "0.4.38",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "ep-mail",
"version": "0.4.37",
"version": "0.4.38",
"dependencies": {
"@capacitor/android": "^8.5.2",
"@capacitor/core": "^8.5.2",
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "ep-mail",
"version": "0.4.37",
"version": "0.4.38",
"private": true,
"description": "Eternity Project mail client",
"homepage": "https://git.eternityproject.fi/thuttu/ep-mail-client",
+68
View File
@@ -2,6 +2,26 @@ const test = require('node:test');
const assert = require('node:assert/strict');
const { registerPgpIpcHandlers } = require('../desktop/ipc/pgp.cjs');
function registerWith(overrides = {}) {
const handlers = new Map();
registerPgpIpcHandlers({
registerIpcHandler(channel, handler) { handlers.set(channel, handler); },
BrowserWindow: { fromWebContents: () => ({}) },
dialog: {
async showOpenDialog() { return { canceled: true, filePaths: [] }; },
async showSaveDialog() { return { canceled: true, filePath: '' }; },
async showMessageBox() { return { response: 0 }; }
},
fs: {}, openpgp: {}, pgpKeys: {}, pgpCache: {}, pgpMail: {},
PgpError: class PgpError extends Error {},
pgpKeyServers: {}, listServers() { return []; }, MAX_CUSTOM_SERVERS: 10,
normalizeCustomServer() {}, randomUUID() { return 'test-id'; },
readAccount() { return null; }, imapClient() {}, folderPath() {}, simpleParser() {}, extractMailContent() {},
...overrides
});
return handlers;
}
test('registers the complete OpenPGP IPC surface through the shared boundary', () => {
const registered = [];
registerPgpIpcHandlers({
@@ -37,3 +57,51 @@ test('registers the complete OpenPGP IPC surface through the shared boundary', (
]);
assert.ok(registered.every(item => typeof item.handler === 'function'));
});
test('native cancellation blocks replacing an existing contact key', async () => {
const dialogs = [];
let added = false;
const handlers = registerWith({
dialog: {
async showMessageBox(_window, options) { dialogs.push(options); return { response: 0 }; }
},
openpgp: {
async readKey() {
return { getFingerprint: () => 'A'.repeat(40), getUserIDs: () => ['Alice <alice@example.test>'] };
}
},
pgpKeys: {
async listContacts() { return [{ name: 'Alice', emails: ['alice@example.test'], fingerprint: 'B'.repeat(40) }]; },
async addContact() { added = true; }
}
});
await assert.rejects(
handlers.get('pgp:add-contact')({ sender: {} }, { armoredKey: 'new-public-key', source: 'message' }),
/Key replacement cancelled/
);
assert.equal(added, false);
assert.equal(dialogs.length, 1);
assert.deepEqual(dialogs[0].buttons, ['Cancel', 'Replace key']);
assert.match(dialogs[0].detail, /A{4} A{4}/);
assert.match(dialogs[0].detail, /B{4} B{4}/);
});
test('native confirmation is required before raising contact-key trust', async () => {
let response = 0;
let trustChanges = 0;
const fingerprint = 'C'.repeat(40);
const handlers = registerWith({
dialog: { async showMessageBox() { return { response }; } },
pgpKeys: {
async listContacts() { return [{ name: 'Carol', emails: ['carol@example.test'], fingerprint }]; },
async setTrust(id, level) { trustChanges += 1; return { fingerprint: id, trust: level }; }
}
});
await assert.rejects(handlers.get('pgp:set-trust')({ sender: {} }, fingerprint, 'verified'), /Trust change cancelled/);
assert.equal(trustChanges, 0);
response = 1;
assert.deepEqual(await handlers.get('pgp:set-trust')({ sender: {} }, fingerprint, 'verified'), { fingerprint, trust: 'verified' });
assert.equal(trustChanges, 1);
});