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:
@@ -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);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user